You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Does this issue reproduce with the latest stable release?
Yes (v0.10.0)
What did you do?
exec go mod tidy
exec go test
env CUE_EXPERIMENT=evalv3
exec go test
-- go.mod --
module test
go 1.24
require (
cuelang.org/go v0.11.0-rc.1
github.com/go-quicktest/qt v1.101.0
)
replace cuelang.org/go => /home/rogpeppe/src/cuelabs/cue
-- main.go --
package main
func main() {}
-- main_test.go --
package main
import (
"os"
"slices"
"testing"
"cuelang.org/go/cue"
"cuelang.org/go/cue/cuecontext"
"github.com/go-quicktest/qt"
)
func TestLoad(t *testing.T) {
evalVersion := cuecontext.EvalV2
if os.Getenv("CUE_EXPERIMENT") == "evalv3" {
// Earlier CUE versions don't recognise CUE_EXPERIMENT
// by default, so simulate it so bisection works OK.
evalVersion = cuecontext.EvalV3
}
ctx := cuecontext.New(cuecontext.EvaluatorVersion(evalVersion))
schemasv := ctx.CompileString(`pkg: x, x: y: "hello"`)
pkgv := schemasv.LookupPath(cue.MakePath(cue.Str("pkg")))
if !pkgv.Exists() {
t.Fatalf("cannot find package in generated schemas")
}
// We can see the field "y" in the resulting value when we iterate through its fields.
var fields []string
iter, err := pkgv.Fields(cue.All())
qt.Assert(t, qt.IsNil(err))
for iter.Next() {
fields = append(fields, iter.Selector().String())
}
if !slices.Contains(fields, "y") {
t.Fatalf("pkg value does not contain field y when iterating")
}
// ... but it fails on lookup (with v3 only)!
schemav := pkgv.LookupPath(cue.MakePath(cue.Str("y")))
if !schemav.Exists() {
t.Fatalf("schema not found")
}
}
What did you expect to see?
A passing test.
What did you see instead?
> exec go mod tidy
> exec go test
[stdout]
PASS
ok test 0.004s
> env CUE_EXPERIMENT=evalv3
> exec go test
[stdout]
--- FAIL: TestLoad (0.00s)
main_test.go:42: schema not found
FAIL
exit status 1
FAIL test 0.004s
[exit status 1]
FAIL: y.txtar:6: unexpected command failure
The text was updated successfully, but these errors were encountered:
I dug into the difference between Value.Fields and Value.LookupPath here and the difference seems to be that Fields obtains a value from Value.Default before iteration, where LookupPath does not.
mvdan
changed the title
eval: lookup failure even when field apparently exists
evalv3: lookup failure even when field apparently exists
Nov 15, 2024
What version of CUE are you using (
cue version
)?Does this issue reproduce with the latest stable release?
Yes (v0.10.0)
What did you do?
What did you expect to see?
A passing test.
What did you see instead?
The text was updated successfully, but these errors were encountered: