cue-lang / cue

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

evalv3: let expression scoping works differently from current evaluator #3150

Closed gotwarlost closed 3 weeks ago

gotwarlost commented 1 month ago

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

$ cue version
cue version v0.9.0-alpha.4

go version go1.21.3
      -buildmode exe
       -compiler gc
     CGO_ENABLED 1
          GOARCH arm64
            GOOS darwin
cue.lang.version v0.9.0

Does this issue reproduce with the latest stable release?

N/A

What did you do?

# old evaluator
env CUE_EXPERIMENT=''
exec cue export fruits.cue
cmp stdout stdout.golden

# new evaluator
env CUE_EXPERIMENT='evalv3'
exec cue export fruits.cue
cmp stdout stdout.golden

-- fruits.cue --
#fruits: tier1: [ "apples", "bananas"]
#fruits: tier2: [ "peaches", "pears" ]

fruitsByTier: {
    for _tier in ["tier1", "tier2" ] {
        let items = #fruits[_tier]
        (_tier):  items
    }
}

-- stdout.golden --
{
    "fruitsByTier": {
        "tier1": [
            "apples",
            "bananas"
        ],
        "tier2": [
            "peaches",
            "pears"
        ]
    }
}

What did you expect to see?

Passing test.

What did you see instead?

# old evaluator (0.058s)
# new evaluator (0.020s)
> env CUE_EXPERIMENT='evalv3'
> exec cue export fruits.cue
[stderr]
fruitsByTier.items.0: conflicting values "peaches" and "apples":
    ./fruits.cue:1:19
    ./fruits.cue:2:19
fruitsByTier.items.1: conflicting values "pears" and "bananas":
    ./fruits.cue:1:29
    ./fruits.cue:2:30
[exit status 1]
FAIL: /var/folders/fw/1zj_t77d3rg41kh6x21g0w8w0000gn/T/testscript2240517181/repro.txt/script.txtar:8: unexpected command failure
gotwarlost commented 3 weeks ago

Seems to have been fixed on the master branch. Closing as a result.

 $ testscript repro.txt
# old evaluator (0.020s)
# new evaluator (0.019s)
PASS