Skip to content

Commit 14e1ef2

Browse files
committed
internal/core/adt: dereference default
Defaults are constructed from final values, so we should ensure that the value is fully dereferenced before getting a default. This fixes most tests of TestFields. We added a per-test todo field to exclude the rest. Issue #3060 Signed-off-by: Marcel van Lohuizen <[email protected]> Change-Id: Iedfcbb679d74f8be39a6ce1ed6109577c969c6c2 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1193958 TryBot-Result: CUEcueckoo <[email protected]> Reviewed-by: Daniel Martí <[email protected]> Unity-Result: CUE porcuepine <[email protected]>
1 parent c6701b4 commit 14e1ef2

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

cue/types_test.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -759,6 +759,8 @@ func TestFields(t *testing.T) {
759759
res string
760760
err string
761761
opts []Option
762+
763+
todoV3 bool
762764
}{{
763765
value: `{ #def: 1, _hidden: 2, opt?: 3, reg: 4 }`,
764766
res: "{reg:4,}",
@@ -806,13 +808,17 @@ func TestFields(t *testing.T) {
806808
if step1.value > 100 {
807809
}`,
808810
err: "undefined field: value",
811+
812+
todoV3: true,
809813
}, {
810814
opts: []Option{Concrete(true)},
811815
value: `
812816
step1: {}
813817
if step1.value > 100 {
814818
}`,
815819
err: "undefined field: value",
820+
821+
todoV3: true,
816822
}, {
817823
value: `{a!: 1, b?: 2, c: 3}`,
818824
err: "a: field is required but not present",
@@ -831,7 +837,9 @@ func TestFields(t *testing.T) {
831837
}}
832838
for _, tc := range testCases {
833839
runMatrix(t, tc.value, func(t *testing.T, cfg *evalConfig) {
834-
TODO_V3(t, cfg)
840+
if tc.todoV3 {
841+
TODO_V3(t, cfg)
842+
}
835843

836844
obj := cfg.getValue(t, tc.value)
837845

internal/core/adt/default.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ func (d *Disjunction) Default() Value {
4545
//
4646
// It also closes a list, representing its default value.
4747
func (v *Vertex) Default() *Vertex {
48+
v = v.Indirect()
4849
switch d := v.BaseValue.(type) {
4950
default:
5051
return v

0 commit comments

Comments
 (0)