Skip to content

Commit

Permalink
internal/core/adt: dereference default
Browse files Browse the repository at this point in the history
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 <mpvl@gmail.com>
Change-Id: Iedfcbb679d74f8be39a6ce1ed6109577c969c6c2
  • Loading branch information
mpvl committed Apr 26, 2024
1 parent ad9e84e commit fe6a1ca
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
10 changes: 9 additions & 1 deletion cue/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,8 @@ func TestFields(t *testing.T) {
res string
err string
opts []Option

todoV3 bool
}{{
value: `{ #def: 1, _hidden: 2, opt?: 3, reg: 4 }`,
res: "{reg:4,}",
Expand Down Expand Up @@ -806,13 +808,17 @@ func TestFields(t *testing.T) {
if step1.value > 100 {
}`,
err: "undefined field: value",

todoV3: true,
}, {
opts: []Option{Concrete(true)},
value: `
step1: {}
if step1.value > 100 {
}`,
err: "undefined field: value",

todoV3: true,
}, {
value: `{a!: 1, b?: 2, c: 3}`,
err: "a: field is required but not present",
Expand All @@ -831,7 +837,9 @@ func TestFields(t *testing.T) {
}}
for _, tc := range testCases {
runMatrix(t, tc.value, func(t *testing.T, cfg *evalConfig) {
TODO_V3(t, cfg)
if tc.todoV3 {
TODO_V3(t, cfg)
}

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

Expand Down
1 change: 1 addition & 0 deletions internal/core/adt/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func (d *Disjunction) Default() Value {
//
// It also closes a list, representing its default value.
func (v *Vertex) Default() *Vertex {
v = v.Indirect()
switch d := v.BaseValue.(type) {
default:
return v
Expand Down

0 comments on commit fe6a1ca

Please sign in to comment.