cue
cue copied to clipboard
evaluator: cue.SelectorOp found where none expected; cue.Dereference required
What version of CUE are you using (cue version)?
$ cue version
cue version v0.0.0-20231124103318-47d6dcedde5c
go version go1.21.3
-buildmode exe
-compiler gc
DefaultGODEBUG panicnil=1
CGO_ENABLED 1
GOARCH arm64
GOOS linux
vcs git
vcs.revision 47d6dcedde5c8c8623758044eb247c172ba4e4bf
vcs.time 2023-11-24T10:33:18Z
vcs.modified false
Does this issue reproduce with the latest release?
Yes
What did you do?
go mod tidy
go run .
cmp stdout stdout.golden
-- go.mod --
module example
go 1.21.3
require cuelang.org/go v0.6.0
-- main.go --
package main
import (
"fmt"
"log"
"cuelang.org/go/cue"
"cuelang.org/go/cue/cuecontext"
)
func main() {
ctx := cuecontext.New()
cueString := `
#def:{ foobar:[ ... #FOO | #BAR] }
#FOO: "foo" | "FOO"
#BAR: "bar" | "BAR"
`
v := ctx.CompileString(cueString)
// The use of cue.AnyIndex "selects" the constraint
field := v.LookupPath(cue.MakePath(cue.Def("def"), cue.Str("foobar"), cue.AnyIndex))
var disjunctionElements []cue.Value
var work cue.Value
todo := []cue.Value{field}
for len(todo) > 0 {
work, todo = todo[0], todo[1:]
op, values := work.Expr()
switch op {
case cue.NoOp:
// We have an element in the disjunction
disjunctionElements = append(disjunctionElements, values...)
case cue.OrOp:
// We need to break down the "element" more
todo = append(todo, values...)
default:
log.Fatalf("unexpected op: %#v, %v", op, values)
}
}
fmt.Printf("%#v", disjunctionElements)
}
-- stdout.golden --
[]cue.Value{"foo", "FOO", "bar", "BAR"}
What did you expect to see?
Passing test.
What did you see instead?
$ ts repro.txtar
> go mod tidy
> go run .
[stderr]
main.go:39: unexpected op: 3, [%!v(PANIC=Format method: unsupported type *adt.NodeLink) "#FOO"]
exit status 1
[exit status 1]
FAIL: /tmp/testscript2935393692/repro.txtar/script.txtar:2: unexpected go command failure
I just came across this issue in a slightly different form, with a somewhat simpler reproducer:
exec go mod tidy
exec go run main.go
! stderr PANIC
-- go.mod --
module test
require cuelang.org/go v0.12.1
-- main.go --
package main
import (
"log"
"cuelang.org/go/cue/cuecontext"
"cuelang.org/go/cue"
)
func main() {
ctx := cuecontext.New()
v := ctx.CompileString(`
x: false
y: x
`)
d := v.LookupPath(cue.MakePath(cue.Str("y")))
op, args := d.Expr()
log.Printf("op %v; %d args", op, len(args))
for i, arg := range args {
log.Printf("%d. %v", i, arg)
}
}
This prints the following:
> exec go mod tidy
> exec go run main.go
[stderr]
op .; 2 args
0. %!v(PANIC=Format method: unsupported type *adt.NodeLink)
1. "x"
> ! stderr PANIC
FAIL: /tmp/x.txtar:3: unexpected match for `PANIC` found in stderr: PANIC
same issue here :/ any news on this?