zed icon indicating copy to clipboard operation
zed copied to clipboard

panic: reflect.Set: value of type *ast.Cast is not assignable to type zed.Any

Open philrz opened this issue 2 years ago • 2 comments

Repro is with Zed tagged v1.1.0.

I encountered this stack trace via accidental typo. The following works as expected:

$ zq -version
Version: v1.1.0

$ echo '{greeting:"hello"}' | zq -z 'yield "bigtext = ${upper(greeting)}"' -
"bigtext = HELLO"

However, if I introduce a typo to yield, it dumps a stack trace rather than showing an error message.

$ echo '{greeting:"hello"}' | zq -z 'yiel "bigtext = ${upper(greeting)}"' -
panic: reflect.Set: value of type *ast.BinaryExpr is not assignable to type zed.Any

goroutine 1 [running]:
reflect.Value.assignTo({0x1682a00?, 0xc0002e4c80?, 0x0?}, {0x1767724, 0xb}, 0x16a5440, 0xc0002feb90)
	/usr/local/opt/go/libexec/src/reflect/value.go:3062 +0x2ac
reflect.Value.Set({0x16a5440?, 0xc0002feb90?, 0x163619a?}, {0x1682a00?, 0xc0002e4c80?, 0x16a5440?})
	/usr/local/opt/go/libexec/src/reflect/value.go:2088 +0xeb
github.com/brimdata/zed/pkg/unpack.convertStruct({0x1683780?, 0xc0002feb70?, 0xc0003bf468?}, 0x1013cf9?)
	/Users/phil/work/zed/pkg/unpack/reflector.go:230 +0x277
github.com/brimdata/zed/pkg/unpack.Reflector.unpack(0xc0003bf4d0?, {0x1690240?, 0xc0002fe6c0?})
	/Users/phil/work/zed/pkg/unpack/reflector.go:151 +0x105
github.com/brimdata/zed/pkg/unpack.Reflector.unpackObject(0x1e5f108?, 0x30?)
	/Users/phil/work/zed/pkg/unpack/reflector.go:172 +0xb0
github.com/brimdata/zed/pkg/unpack.Reflector.unpack(0xc0002faac0?, {0x1690240?, 0xc0002fe630?})
	/Users/phil/work/zed/pkg/unpack/reflector.go:140 +0x6e
github.com/brimdata/zed/pkg/unpack.Reflector.unpackObject(0xc00000f260?, 0x1c?)
	/Users/phil/work/zed/pkg/unpack/reflector.go:172 +0xb0
github.com/brimdata/zed/pkg/unpack.Reflector.unpack(0x203000?, {0x1690240?, 0xc0002fe600?})
	/Users/phil/work/zed/pkg/unpack/reflector.go:140 +0x6e
github.com/brimdata/zed/pkg/unpack.Reflector.unpackArray(0x0?, {0xc0002fac60, 0x1, 0x1013cf9?})
	/Users/phil/work/zed/pkg/unpack/reflector.go:184 +0xc5
github.com/brimdata/zed/pkg/unpack.Reflector.unpack(0xc0003bf888?, {0x165e9c0?, 0xc00000f488?})
	/Users/phil/work/zed/pkg/unpack/reflector.go:164 +0x1ce
github.com/brimdata/zed/pkg/unpack.Reflector.unpackObject(0x16?, 0x1656240?)
	/Users/phil/work/zed/pkg/unpack/reflector.go:172 +0xb0
github.com/brimdata/zed/pkg/unpack.Reflector.unpack(0xc000202240?, {0x1690240?, 0xc0002fe5d0?})
	/Users/phil/work/zed/pkg/unpack/reflector.go:140 +0x6e
github.com/brimdata/zed/pkg/unpack.Reflector.Unmarshal(0x1690240?, {0xc000202240, 0x227, 0x240})
	/Users/phil/work/zed/pkg/unpack/reflector.go:83 +0x107
github.com/brimdata/zed/pkg/unpack.Reflector.UnmarshalObject(0x1?, {0x1690240?, 0xc0002f9f20?})
	/Users/phil/work/zed/pkg/unpack/reflector.go:101 +0x5a
github.com/brimdata/zed/compiler/ast.UnpackMapAsOp({0x1690240?, 0xc0002f9f20?})
	/Users/phil/work/zed/compiler/ast/unpack.go:112 +0x37
github.com/brimdata/zed/compiler.ParseOp({0x7ff7bfeff9ce?, 0x160ed88?}, {0x0?, 0x3?, 0xc0000899c0?})
	/Users/phil/work/zed/compiler/compiler.go:164 +0x50
github.com/brimdata/zed/cli/queryflags.(*Flags).ParseSourcesAndInputs(0xc00022eed8, {0xc0000320a0, 0x2, 0x2})
	/Users/phil/work/zed/cli/queryflags/flags.go:48 +0x2de
github.com/brimdata/zed/cli/zq.(*Command).Run(0xc00022eea0, {0xc0000320a0, 0x2, 0x2})
	/Users/phil/work/zed/cli/zq/command.go:132 +0x25b
github.com/brimdata/zed/pkg/charm.path.run({0xc0000100c0?, 0x1, 0x1}, {0xc0000320a0?, 0x2, 0x0?})
	/Users/phil/work/zed/pkg/charm/path.go:11 +0x8b
github.com/brimdata/zed/pkg/charm.(*Spec).ExecRoot(0xc0000021a0?, {0xc000032090, 0x3, 0x3})
	/Users/phil/work/zed/pkg/charm/charm.go:63 +0x4a
main.main()
	/Users/phil/work/zed/cmd/zq/main.go:11 +0x5e

philrz avatar May 16 '22 20:05 philrz

#4084 fixes the panic but provides an uninformative error, so I don't consider that a fix.

$ echo '{greeting:"hello"}' | zq -z 'yiel "bigtext = ${upper(greeting)}"' -
zq: JSON field "value": value of type "*ast.BinaryExpr" not assignable to interface type "zed.Any" in struct type "ast.Term"

nwt avatar Sep 13 '22 16:09 nwt

FWIW, I found a similar crash when investigating the relevance of #3452 and it appears to be semi-fixed by the #4084 branch in the same way. If it turns out to require separate treatment I can open a new issue.

The repro:

$ zq -version
Version: v1.2.0-49-g9c0f0973

$ echo '{"addr": "192.168.0.1", "port": 80}' | zq -z 'type socket = {addr:ip,port:port=<uint16>} yield shape(socket)' -
panic: reflect.Set: value of type *zed.TypeValue is not assignable to type zed.Type

goroutine 1 [running]:
reflect.Value.assignTo({0x16f0e60?, 0xc0000d3260?, 0x0?}, {0x17b071f, 0xb}, 0x16e6ca0, 0xc00039b7c0)
	/usr/local/opt/go/libexec/src/reflect/value.go:3145 +0x2a5
...

Then with the fix branch:

$ zq -version
Version: v1.2.0-50-g613256db

$ echo '{"addr": "192.168.0.1", "port": 80}' | zq -z 'type socket = {addr:ip,port:port=<uint16>} yield shape(socket)' -
zq: JSON field "type": value of type "*zed.TypeValue" not assignable to interface type "zed.Type" in struct type "zed.TypeDef"

philrz avatar Sep 14 '22 16:09 philrz