Dynamic field expression alias
According to the language spec, one of the supported alias positions is before the expression of a dynamic field:
In front of a dynamic field expression ((X=expr): value):
- binds the identifier to the concrete label resulting from evaluating expr.
However, currently this just seems to cause a syntax error.
What version of CUE are you using (cue version)?
$ cue version
cue version 0.7.0
go version go1.21.5
-buildmode exe
-compiler gc
-trimpath true
DefaultGODEBUG panicnil=1
CGO_ENABLED 1
GOARCH amd64
GOOS linux
GOAMD64 v1
Does this issue reproduce with the latest stable release?
Yes
What did you do?
// test.cue
(x="foo"): x
$ cue eval test.cue
What did you expect to see?
foo: "foo"
What did you see instead?
expected ')', found '=':
../../tmp/foo/test.cue:1:3
Well spotted! This is definitely a bug.
I just rediscovered this spec deviation.
Here's a txtar repro that should pass:
exec cue export
cmp stdout out
-- file.cue --
package p
(X="foo"): bar: 1
baz: X
-- out --
{
"foo": {
"bar": 1
},
"baz": "foo"
}
Here's the failure with v0.12.1:
> exec cue export
[stderr]
expected ')', found '=':
./file.cue:3:3
[exit status 1]
FAIL: foo.txtar:1: unexpected command failure
failed run
Just to make clear a let-based workaround that follows the exact same scoping rules:
exec cue export
cmp stdout out
-- file.cue --
package p
let X="foo"
(X): bar: 1
baz: X
-- out --
{
"foo": {
"bar": 1
},
"baz": "foo"
}
Note that this spec deviation bug will disappear with the aliasv2 language change: https://github.com/cue-lang/cue/discussions/4014