Open rogpeppe opened 1 year ago
Did you perhaps mean for your example to be:
exec cue export test.cue
cmp stdout expect.json
-- test.cue --
#D: x: int
#E: d: #D
#F: {
#E
d: {
...
}
}
x: #F
x: d: x: 9
x: d: y: 10
-- expect.json --
{
"x": {
"d": {
"x": 9,
"y": 10
}
}
}
In your example the ...
is opening up #F
, not #F.d
For reference, linking to https://github.com/cue-lang/cue/issues/1576.
In addition to Paul's suggestion, there are two other options:
{...}
should have the effect of opening all fields recursively. _
should have a separate effect.But both of these approaches are currently broken.
Did you perhaps mean for your example to be:
exec cue export test.cue cmp stdout expect.json -- test.cue -- #D: x: int #E: d: #D #F: { #E d: { ... } } x: #F x: d: x: 9 x: d: y: 10 -- expect.json -- { "x": { "d": { "x": 9, "y": 10 } } }
In your example the
...
is opening up#F
, not#F.d
I intended what I wrote. The spec doesn't say anything about it only applying to a single level when it says "disregarding the restrictions imposed by closed structs.". #E
is a closed struct. It's embedded inside #F
. #F
without the embedded #E
allows any field at any level. Therefore #F
with #E
embedded should, by my understanding of the language of the spec, allow fields that are inside #F.d
but not in #E
.
In addition to Paul's suggestion, there are two other options:
- embedding
{...}
should have the effect of opening all fields recursively.
Presumably that would be the same as just embedding ...
because in general embedding {x}
is the same as embedding x
for any x
AIUI.
This would then be a language change rather than enhancement, because currently:
#B: a: int
#A: {
foo: #B
...
}
would not allow:
a: #A
a: foo: b: 1
but if embedding ...
opened recursively, that would change.
- embedding
_
should have a separate effect.
What kind of separate effect are you thinking of here?
But both of these approaches are currently broken.
What version of CUE are you using (
cue version
)?Does this issue reproduce with the latest release?
Yes
What did you do?
What did you expect to see?
A passing test.
What did you see instead?
The definition is opened up at the top level, but not at any level below that, which I believe should be expected, according to the spec:
In this case, the restrictions imposed by closed structs are clearly not being disregarded.