diff --git a/cmd/cue/cmd/testdata/script/export_defaulterr.txt b/cmd/cue/cmd/testdata/script/export_defaulterr.txt new file mode 100644 index 00000000000..475a6469330 --- /dev/null +++ b/cmd/cue/cmd/testdata/script/export_defaulterr.txt @@ -0,0 +1,26 @@ +#Issue 1304 + +! cue export --out json x.cue +cmp stdout expect_stdout_json +cmp stderr expect_stderr_json + +! cue export --out cue x.cue +cmp stdout expect_stdout_cue +cmp stderr expect_stderr_cue + +! cue export --out yaml x.cue +cmp stdout expect_stdout_yaml +cmp stderr expect_stderr_yaml + +-- x.cue -- +toto: value: *_|_ | (*"toto" | string) + +-- expect_stdout_cue -- +-- expect_stderr_cue -- +toto.value: incomplete value "toto" | string +-- expect_stdout_json -- +-- expect_stderr_json -- +toto.value: incomplete value "toto" | string +-- expect_stdout_yaml -- +-- expect_stderr_yaml -- +toto.value: incomplete value "toto" | string diff --git a/cue/types_test.go b/cue/types_test.go index 20b2ab73d3b..d4ff4c59ed9 100644 --- a/cue/types_test.go +++ b/cue/types_test.go @@ -1562,14 +1562,20 @@ func TestDefaults(t *testing.T) { ok: true, }, { value: `{a:1}&{b:2}`, - def: `({a:1} & {b:2})`, + def: `{a:1,b:2}`, val: ``, ok: false, + }, { + value: `*_|_ | (*"x" | string)`, + def: `"x" | string`, + val: `"x"|string`, + ok: false, }} for _, tc := range testCases { t.Run(tc.value, func(t *testing.T) { v := getInstance(t, "a: "+tc.value).Lookup("a") + v = v.Eval() d, ok := v.Default() if ok != tc.ok { t.Errorf("hasDefault: got %v; want %v", ok, tc.ok) diff --git a/internal/core/adt/default.go b/internal/core/adt/default.go index e239a26043a..ad88f0daca2 100644 --- a/internal/core/adt/default.go +++ b/internal/core/adt/default.go @@ -54,13 +54,6 @@ func (v *Vertex) Default() *Vertex { switch d.NumDefaults { case 0: - if d.HasDefaults { - v = &Vertex{ - Parent: v.Parent, - status: Finalized, - BaseValue: &Bottom{}, - } - } return v case 1: w = d.Values[0]