Skip to content

Commit 62e876d

Browse files
committed
internal/core/adt: fix disjunction bug
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]>
1 parent 9bb874c commit 62e876d

File tree

3 files changed

+33
-8
lines changed

3 files changed

+33
-8
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#Issue 1304
2+
3+
! cue export --out json x.cue
4+
cmp stdout expect_stdout_json
5+
cmp stderr expect_stderr_json
6+
7+
! cue export --out cue x.cue
8+
cmp stdout expect_stdout_cue
9+
cmp stderr expect_stderr_cue
10+
11+
! cue export --out yaml x.cue
12+
cmp stdout expect_stdout_yaml
13+
cmp stderr expect_stderr_yaml
14+
15+
-- x.cue --
16+
toto: value: *_|_ | (*"toto" | string)
17+
18+
-- expect_stdout_cue --
19+
-- expect_stderr_cue --
20+
toto.value: incomplete value "toto" | string
21+
-- expect_stdout_json --
22+
-- expect_stderr_json --
23+
toto.value: incomplete value "toto" | string
24+
-- expect_stdout_yaml --
25+
-- expect_stderr_yaml --
26+
toto.value: incomplete value "toto" | string

cue/types_test.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1562,14 +1562,20 @@ func TestDefaults(t *testing.T) {
15621562
ok: true,
15631563
}, {
15641564
value: `{a:1}&{b:2}`,
1565-
def: `({a:1} & {b:2})`,
1565+
def: `{a:1,b:2}`,
15661566
val: ``,
15671567
ok: false,
1568+
}, {
1569+
value: `*_|_ | (*"x" | string)`,
1570+
def: `"x" | string`,
1571+
val: `"x"|string`,
1572+
ok: false,
15681573
}}
15691574
for _, tc := range testCases {
15701575
t.Run(tc.value, func(t *testing.T) {
15711576
v := getInstance(t, "a: "+tc.value).Lookup("a")
15721577

1578+
v = v.Eval()
15731579
d, ok := v.Default()
15741580
if ok != tc.ok {
15751581
t.Errorf("hasDefault: got %v; want %v", ok, tc.ok)

internal/core/adt/default.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,6 @@ func (v *Vertex) Default() *Vertex {
5454

5555
switch d.NumDefaults {
5656
case 0:
57-
if d.HasDefaults {
58-
v = &Vertex{
59-
Parent: v.Parent,
60-
status: Finalized,
61-
BaseValue: &Bottom{},
62-
}
63-
}
6457
return v
6558
case 1:
6659
w = d.Values[0]

0 commit comments

Comments
 (0)