Skip to content

Parametric Polymorphism / Generics #3642

Answered by myitcv
loisch asked this question in Q&A
Discussion options

You must be logged in to vote

I think you achieve what you want by making the _#Type "parameter" required:

! exec cue export x.cue
cmp stderr stderr.golden

exec cue export y.cue
cmp stdout stdout.golden

-- x.cue --
#FinDefSet: {
	_#Type!: _
	AllBut: [..._#Type]
} | {
	_#Type!: _
	Only: [..._#Type]
}

value: #FinDefSet & {_#Type: int}
value: Only: [1, 2, 3]

notAllowed: #FinDefSet
notAllowed: Only: []

-- y.cue --
#FinDefSet: {
	_#Type!: _
	AllBut: [..._#Type]
} | {
	_#Type!: _
	Only: [..._#Type]
}

value: #FinDefSet & {_#Type: int}
value: Only: [1, 2, 3]

notAllowed: #FinDefSet & {_#Type: string}
notAllowed: Only: []

-- stderr.golden --
notAllowed._#Type: field is required but not present:
    ./x.cue:5:2
    ./x.c…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by loisch
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