Skip to content

Commit 25f2780

Browse files
moustafabclaude
andcommitted
fix(simplecue): guard declareDisjunction against over-filtering when Equals() is unreliable in CUE v0.16
In CUE v0.16, Equals() returns true for structurally-equivalent open lists regardless of their element type: [...bool].Equals([...string]) and [...bool].Equals([]) both return true. The implicit default for any open list is the empty closed list []. The existing filter that strips the "default branch" from a disjunction used `branch.Equals(defaultAsCueValue)`. For `[...bool] | [...string]`, hasDefault=true with defaultAsCueValue=[], and both branches compared equal to [] — so both were filtered, leaving an empty branch list. Fix: count how many branches match the default before filtering. Only remove a branch when exactly one branch matches — the unambiguous case where that branch IS the default. When multiple branches match (as with open lists in v0.16), skip filtering entirely to preserve all branches. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent b0f7009 commit 25f2780

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

internal/simplecue/generator.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -596,9 +596,27 @@ func (g *generator) declareDisjunction(v cue.Value, hints ast.JenniesHints, defa
596596
_, disjunctionBranchesWithPossibleDefault := v.Expr()
597597
defaultAsCueValue, hasDefault := v.Default()
598598

599+
// Count how many branches equal the default value (with same reference path).
600+
// In CUE v0.16+, Equals() may return true for structurally-equivalent open lists
601+
// (e.g., [...bool].Equals([...string]) == true, [...bool].Equals([]) == true).
602+
// To avoid over-filtering, we only remove the default branch when exactly one
603+
// branch matches — otherwise we'd silently drop all branches of the disjunction.
604+
matchingDefaultCount := 0
605+
if hasDefault {
606+
for _, branch := range disjunctionBranchesWithPossibleDefault {
607+
if branch.Equals(defaultAsCueValue) {
608+
_, bPath := branch.ReferencePath()
609+
_, dPath := defaultAsCueValue.ReferencePath()
610+
if bPath.String() == dPath.String() {
611+
matchingDefaultCount++
612+
}
613+
}
614+
}
615+
}
616+
599617
disjunctionBranches := make([]cue.Value, 0, len(disjunctionBranchesWithPossibleDefault))
600618
for _, branch := range disjunctionBranchesWithPossibleDefault {
601-
if hasDefault && branch.Equals(defaultAsCueValue) {
619+
if hasDefault && matchingDefaultCount == 1 && branch.Equals(defaultAsCueValue) {
602620
_, bPath := branch.ReferencePath()
603621
_, dPath := defaultAsCueValue.ReferencePath()
604622

0 commit comments

Comments
 (0)