cuelang / cue

CUE has moved to https://github.com/cue-lang/cue
https://cuelang.org
Apache License 2.0
3.09k stars 171 forks source link

cmd/cue: fmt rewrites valid value alias as let #1004

Closed myitcv closed 3 years ago

myitcv commented 3 years ago

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

$ cue version
cue version +37bf801b linux/amd64

Does this issue reproduce with the latest release?

Yes

What did you do?

cp x.cue x.cue.golden
exec cue fmt x.cue
cmp x.cue x.cue.golden

-- x.cue --
package x

X={a: 1, b: 2, c: X.a}

What did you expect to see?

Passing test.

What did you see instead?

> cp x.cue x.cue.golden
> exec cue fmt x.cue
> cmp x.cue x.cue.golden
[diff -x.cue +x.cue.golden]
 package x

-let X = {a: 1, b: 2, c: X.a}
+X={a: 1, b: 2, c: X.a}

FAIL: /tmp/testscript248389989/repro.txt/script.txt:3: x.cue and x.cue.golden differ

In this instance, the value is being used as an embedding, which should be ok?

myitcv commented 3 years ago

Per @mpvl this is working as expected, because a value alias can only appear on the right hand side of the : in a field declaration. So the rewrite happening here is of an old style alias to a let expression.

cueckoo commented 3 years ago

This issue has been migrated to https://github.com/cue-lang/cue/issues/1004.

For more details about CUE's migration to a new home, please see https://github.com/cue-lang/cue/issues/1078.