cue-lang / cue

The home of the CUE language! Validate and define text-based and dynamic configuration
https://cuelang.org
Apache License 2.0
5.04k stars 287 forks source link

evaluator: unexpected "cycle" with pattern expression #2013

Open myitcv opened 1 year ago

myitcv commented 1 year ago

What version of CUE are you using (cue version)?

$ cue version
cue version v0.0.0-20221001181137-79d80efc2882

       -compiler gc
     CGO_ENABLED 1
          GOARCH arm64
            GOOS linux
             vcs git
    vcs.revision 79d80efc288208410f77d47ae9aedd37e106d84b
        vcs.time 2022-10-01T18:11:37Z
    vcs.modified false

Does this issue reproduce with the latest release?

Yes

What did you do?

exec cue eval x.cue
cmp stdout stdout.golden

-- x.cue --
x: "x"
[x]: string
-- stdout.golden --
x: "x"

What did you expect to see?

Passing test.

What did you see instead?

> exec cue eval x.cue
[stderr]
reference "x" in label expression refers to field against which it would be matched:
    ./x.cue:2:2
[exit status 1]
FAIL: /tmp/testscript970237123/repro.txtar/script.txtar:1: unexpected command failure

Whilst this situation is not exactly common, I first wondered whether we could improve the error message... but before I got onto thinking about that I got side tracked wondering whether this is actually an error at all. It's not clear to me this should be an error, and with the recent cycle and comprehension work, perhaps it no longer needs to be?

mpvl commented 1 year ago

This has working like this for a long time. No need to delay v0.5.0 for this. This is not a cycle, per se, and also not related to comprehension.

But we could consider making it work.