From 769f37aab9c298c7696bfdaf2bf7246ff176f6bc Mon Sep 17 00:00:00 2001 From: Marcel van Lohuizen Date: Thu, 15 Aug 2024 15:50:17 +0200 Subject: [PATCH] internal/core/adt: fix disjunctions in data mode MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Change-Id: I40c1fed6c6c2284c750c3f9115a8ea6456bcc37a Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1199550 Reviewed-by: Daniel Martí TryBot-Result: CUEcueckoo Unity-Result: CUE porcuepine Reviewed-by: Roger Peppe --- internal/core/adt/composite.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/internal/core/adt/composite.go b/internal/core/adt/composite.go index 1559a3516c7..fe77e0ab07d 100644 --- a/internal/core/adt/composite.go +++ b/internal/core/adt/composite.go @@ -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)