Skip to content

Alert when I have two concrete types with different set of properties #2660

Answered by mvdan
taylormonacelli asked this question in Q&A
Discussion options

You must be logged in to vote

This particular example is meant to work in CUE since multiple declarations get unified into one; foo: string and foo: "bar" is the same as foo: string & "bar". CUE is not imperative and fields get unified, so there's no such thing as "sam has already been declared before so it can't be declared again".

One solution, although quite repetitive, would be to close your values so that one declaration omitting an optional field doesn't allow another to add it later via unification: https://tip.cuelang.org/play/?id=wJD76Ii2lzX#cue@export@cue

You could indeed use the Go API to ensure that the fields in the top-level object are unique. For example, with the Go API, you could parse the syntax tree…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by taylormonacelli
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants