Skip to content

Commit

Permalink
internal/core/adt: fix disjunction bug
Browse files Browse the repository at this point in the history
Default should return unmarked disjuncts, instead
of an error.

Fixes #1304
Fixes #1257

Signed-off-by: Marcel van Lohuizen <[email protected]>

Change-Id: Idfe0302ede7a35cac7dfbbbf0c27242ebb1c3b32
Signed-off-by: Marcel van Lohuizen <[email protected]>
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/527316
Unity-Result: CUEcueckoo <[email protected]>
TryBot-Result: CUEcueckoo <[email protected]>
Reviewed-by: Paul Jolly <[email protected]>
  • Loading branch information
mpvl committed Nov 16, 2021
1 parent 9bb874c commit 62e876d
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 8 deletions.
26 changes: 26 additions & 0 deletions cmd/cue/cmd/testdata/script/export_defaulterr.txt
Original file line number Diff line number Diff line change
@@ -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
8 changes: 7 additions & 1 deletion cue/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 0 additions & 7 deletions internal/core/adt/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit 62e876d

Please sign in to comment.