cue
cue copied to clipboard
cmd/cue: simplify `["k"]: v` to `"k"?: v`
Originally opened by @myitcv in https://github.com/cuelang/cue/issues/1045
What version of CUE are you using (cue version)?
$ cue version cue version +20ed9abd linux/amd64
Does this issue reproduce with the latest release?
Yes
What did you do?
exec cue fmt -s x.cue
cmp x.cue x.cue.golden
-- x.cue --
package x
["^t"]: 5
-- x.cue.golden --
package x
"^t"?: 5
What did you expect to see?
Test to pass.
What did you see instead?
> exec cue fmt -s x.cue
> cmp x.cue x.cue.golden
[diff -x.cue +x.cue.golden]
package x
-["^t"]: 5
+"^t"?: 5
As discussed with @mpvl, this would be a useful simplification so that the user can see what they perhaps intended was not actually the case.
Because ["^t"] is equivalent to "^t"?, whereas the user probably intended [=~"^t"] in this case.
Thanks for @mvdan for spotting the errors in the original description here. I've now tweaked the original description to demonstrate that an optional (as opposed to regular) field is the equivalent.
Whether we should rewrite via simplify here (which not everyone does), or have a vet rule, or something else, is not clear.