-
Originally opened by @leitzler in cuelang/cue#989 Using I'm trying to provide a "new default value" for a nested definition and the error message is slightly confusing. Is there a more natural way to achieve this? E.g.: I want a new definition package foobar
#AB: {
"a"
} | {
b: #B
}
#B: {
bf: string | *"default"
}
#Foo: {
// This works:
//bar: {b: #B & {bf: "newDefault"}}
// $ cue eval foo.cue --out yaml
// bar:
// b:
// bf: newDefault
// This also works:
//bar: #AB
//
// $ cue eval foo.cue --out yaml
// bar:
// b:
// bf: default
//
// Doesn't work:
bar: #AB | {
b: #B & {bf: "newDefault"}
}
// $ cue vet -c foo.cue
// bar: incomplete value {b:{bf:*"default" | string}} | {b:{bf:"newDefault"}}
//
}
// I want to enforce a default value for "bf" via "& #Foo"
{
bar: b: #B
} & #Foo |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Original reply by @mpvl in cuelang/cue#989 (comment) In general, a good approach is to not have any defaults in the base template, and then add them later as one desires. In this case, the issue is that
|
Beta Was this translation helpful? Give feedback.
Original reply by @mpvl in cuelang/cue#989 (comment)
In general, a good approach is to not have any defaults in the base template, and then add them later as one desires.
In this case, the issue is that
bar
introduces a disjunction without a default. To ensure it "reaches" thenewDefault
value, you could write