Skip to content

Commit

Permalink
internal/core/adt: fix disjunctions in data mode
Browse files Browse the repository at this point in the history
The toDataAll path is currently not used, but will
be used in the upcoming matchN builtin.

In data mode, defaults of disjunctons should be taken
and a non-ambiguous default should consequently be
converted to data also.

This will be tested as part of the matchN builtin.

Signed-off-by: Marcel van Lohuizen <[email protected]>
Change-Id: I40c1fed6c6c2284c750c3f9115a8ea6456bcc37a
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1199550
Reviewed-by: Daniel Martí <[email protected]>
TryBot-Result: CUEcueckoo <[email protected]>
Unity-Result: CUE porcuepine <[email protected]>
Reviewed-by: Roger Peppe <[email protected]>
  • Loading branch information
mpvl committed Aug 19, 2024
1 parent ae3987d commit 769f37a
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions internal/core/adt/composite.go
Original file line number Diff line number Diff line change
Expand Up @@ -760,8 +760,18 @@ func toDataAll(ctx *OpContext, v BaseValue) BaseValue {
// to avoid issues with the closedness algorithm down the line.
case *Disjunction:
d := *x
d.Values = make([]Value, len(x.Values))
for i, v := range x.Values {
values := x.Values
// Data mode involves taking default values and if there is an
// unambiguous default value, we should convert that to data as well.
switch x.NumDefaults {
case 0:
case 1:
return toDataAll(ctx, values[0])
default:
values = values[:x.NumDefaults]
}
d.Values = make([]Value, len(values))
for i, v := range values {
switch x := v.(type) {
case *Vertex:
d.Values[i] = x.ToDataAll(ctx)
Expand Down

0 comments on commit 769f37a

Please sign in to comment.