Struct openness in definition #527
-
Given: #B: a: number
#A: {
c: [string]: #B
c: {
foo: _
bar: _
}
}
m: #A
m: c: {
foo: a: 1
bar: a: 2
foobar: a: 10
} I expect Eval (0.2.2 or 0.3.0): #B: {
a: number
}
#A: {
c: {
foo: {
a: number
}
bar: {
a: number
}
}
}
m: {
c: {
foo: {
a: 1
}
bar: {
a: 2
}
foobar: {
a: 10
}
}
} In my mind I noticed that the introduction of the template How to make the if I define:
It works properly with cue 0.3 (but not cue 0.2.2). Is this the way to go ?
In my real use case the template is quite useful. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 6 replies
-
Can you clarify what you are trying to achieve with your
which basically says that all the fields of In the near future (not yet implemented), the semantics are going to change to those detailed in the spec: https://tip.cuelang.org/docs/references/spec/#structs. (This was also detailed in the Under this new implementation:
would constrain all fields of Whereas:
would allow additional fields in The one additional case which is covered in the spec is that of default constraints. |
Beta Was this translation helpful? Give feedback.
-
Another way to see this: spec says that definitions are only closed upon reference. So multiple fields with the same value get unified before they get closed. In the past not doing so has led to confusion as
was expected to mean the same as
From a composability perspective, as well as from the substitution principle, this makes a lot of sense.
is indeed a valid way to achieve what you want. Another way would be:
In this case, Note that closedness is not enforced for embedding (analogous to Go), so
would not have the desired effect. |
Beta Was this translation helpful? Give feedback.
-
This discussion has been migrated to cue-lang/cue#527. For more details about CUE's migration to a new home, please see cue-lang/cue#1078. |
Beta Was this translation helpful? Give feedback.
Can you clarify what you are trying to achieve with your
#A
definition? Because currently (emphasis important, see below) it is equivalent to:which basically says that all the fields of
c
(includingfoo
andbar
) must be of type#B
. This constraint does not preclude additional fields beyondfoo
andbar
, just so long as those additional fields are of type#B
.In the near future (not yet implemented), the semantics are going to change to those detailed in the spec: https://tip.cuelang.org/docs/references/spec/#structs. (This was also detailed…