Skip to content

Commit 26a698f

Browse files
committed
internal/core/adt: propagate default marker in single nested value
If a single value remains of a nested disjunction, the default marker of the parent should propagate down regardless of the default marker of the nested value. This is more in line with evalv2 behavior Note that in specdeviation.txtar, staged.c now has two defaults. This seems to be technically correct, although it is a bit strange. Fixes #3779 Signed-off-by: Marcel van Lohuizen <[email protected]> Change-Id: I09ab6d7d4668884e76cb2c585a8a90da99ba1f18 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1209289 TryBot-Result: CUEcueckoo <[email protected]> Reviewed-by: Matthew Sackman <[email protected]>
1 parent 324b3da commit 26a698f

File tree

4 files changed

+24
-63
lines changed

4 files changed

+24
-63
lines changed

cue/testdata/cycle/issue429.txtar

+2-3
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ Result:
9595
s1: (#struct){
9696
min: (int){ 5 }
9797
res: (int){ |(*(int){ 0 }, (int){ &(>=0, int) }) }
98-
max: (number){ |((number){ >5 }, (int){ 5 }) }
98+
max: (number){ |(*(int){ 5 }, (number){ >5 }) }
9999
}
100100
s2: (#struct){
101101
max: (int){ 5 }
@@ -194,10 +194,9 @@ diff old new
194194
s1: (#struct){
195195
- res: (int){ |(*(int){ 0 }, (int){ &(>=0, int) }) }
196196
- min: (int){ 5 }
197-
- max: (number){ |(*(int){ 5 }, (number){ >5 }) }
198197
+ min: (int){ 5 }
199198
+ res: (int){ |(*(int){ 0 }, (int){ &(>=0, int) }) }
200-
+ max: (number){ |((number){ >5 }, (int){ 5 }) }
199+
max: (number){ |(*(int){ 5 }, (number){ >5 }) }
201200
}
202201
s2: (#struct){
203202
- res: (int){ |(*(int){ 0 }, (int){ &(>=0, int) }) }

cue/testdata/disjunctions/defaults.txtar

-47
Original file line numberDiff line numberDiff line change
@@ -44,53 +44,6 @@ issue3779: {
4444
}
4545
}
4646
}
47-
-- out/evalalpha --
48-
(struct){
49-
passToSingleValue: (struct){
50-
p1: (_){ |((_){ _ }, (string){ "y" }) }
51-
p2: (_){ |((_){ _ }, (string){ "y" }) }
52-
p3: (_){ |((string){ "y" }, (_){ _ }) }
53-
p4: (_){ |((string){ "y" }, (_){ _ }) }
54-
}
55-
issue3779: (struct){
56-
out: (#struct){
57-
fieldFoo: (string){ "foo" }
58-
fieldBar: (string){ |((string){ string }, (string){ "foo" }) }
59-
}
60-
#Foo: (#struct){
61-
fieldFoo: (string){ |(*(string){ "foo-default" }, (string){ string }) }
62-
fieldBar: (string){ |(*(string){ "foo-default" }, (string){ string }) }
63-
}
64-
#Bar: (#struct){
65-
fieldFoo: (_){ _ }
66-
fieldBar: (_){ |(*(_){ _ }, (string){ string }) }
67-
}
68-
}
69-
}
70-
-- diff/-out/evalalpha<==>+out/eval --
71-
diff old new
72-
--- old
73-
+++ new
74-
@@ -1,14 +1,14 @@
75-
(struct){
76-
passToSingleValue: (struct){
77-
- p1: (_){ |(*(string){ "y" }, (_){ _ }) }
78-
- p2: (_){ |(*(string){ "y" }, (_){ _ }) }
79-
- p3: (_){ |(*(string){ "y" }, (_){ _ }) }
80-
- p4: (_){ |(*(string){ "y" }, (_){ _ }) }
81-
+ p1: (_){ |((_){ _ }, (string){ "y" }) }
82-
+ p2: (_){ |((_){ _ }, (string){ "y" }) }
83-
+ p3: (_){ |((string){ "y" }, (_){ _ }) }
84-
+ p4: (_){ |((string){ "y" }, (_){ _ }) }
85-
}
86-
issue3779: (struct){
87-
out: (#struct){
88-
fieldFoo: (string){ "foo" }
89-
- fieldBar: (string){ |(*(string){ "foo" }, (string){ string }) }
90-
+ fieldBar: (string){ |((string){ string }, (string){ "foo" }) }
91-
}
92-
#Foo: (#struct){
93-
fieldFoo: (string){ |(*(string){ "foo-default" }, (string){ string }) }
9447
-- out/eval --
9548
(struct){
9649
passToSingleValue: (struct){

cue/testdata/disjunctions/specdeviation.txtar

+17-11
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,12 @@ Disjuncts: 172
7676
Q: (int){ |(*(int){ 1 }, (int){ int }) }
7777
q: (int){ |(*(int){ 1 }, (int){ int }) }
7878
P: (int){ 2 }
79-
p: (int){ |((int){ 2 }, (int){ int }) }
79+
p: (int){ |(*(int){ 2 }, (int){ int }) }
8080
r: (int){ |((int){ 1 }, (int){ 2 }) }
8181
s: (int){ |(*(int){ 1 }, (int){ 2 }) }
8282
s1: (#struct){
8383
min: (int){ 5 }
84-
max: (number){ |((number){ >5 }, (int){ 5 }) }
84+
max: (number){ |(*(int){ 5 }, (number){ >5 }) }
8585
res: (int){ |(*(int){ 0 }, (int){ &(>=0, int) }) }
8686
}
8787
#Size: (#struct){
@@ -90,7 +90,7 @@ Disjuncts: 172
9090
min: (number){ |(*(int){ 1 }, (number){ >0 }) }
9191
}
9292
staged: (struct){
93-
c: (string){ |(*(string){ "a" }, (string){ "b" }) }
93+
c: (string){ |(*(string){ "a" }, *(string){ "b" }) }
9494
d: (string){ |(*(string){ "a" }, (string){ "b" }) }
9595
}
9696
issue763a: (struct){
@@ -114,28 +114,34 @@ Disjuncts: 172
114114
diff old new
115115
--- old
116116
+++ new
117-
@@ -2,13 +2,13 @@
118-
Q: (int){ |(*(int){ 1 }, (int){ int }) }
119-
q: (int){ |(*(int){ 1 }, (int){ int }) }
120-
P: (int){ 2 }
121-
- p: (int){ |(*(int){ 2 }, (int){ int }) }
122-
+ p: (int){ |((int){ 2 }, (int){ int }) }
117+
@@ -6,9 +6,9 @@
123118
r: (int){ |((int){ 1 }, (int){ 2 }) }
124119
s: (int){ |(*(int){ 1 }, (int){ 2 }) }
125120
s1: (#struct){
126121
- max: (number){ |(*(int){ 5 }, (number){ >5 }) }
127122
- res: (int){ |(*(int){ 0 }, (int){ &(>=0, int) }) }
128123
min: (int){ 5 }
129-
+ max: (number){ |((number){ >5 }, (int){ 5 }) }
124+
+ max: (number){ |(*(int){ 5 }, (number){ >5 }) }
130125
+ res: (int){ |(*(int){ 0 }, (int){ &(>=0, int) }) }
131126
}
132127
#Size: (#struct){
133128
max: (number){ |(*(int){ 1 }, (number){ >0 }, (number){ >1 }) }
129+
@@ -16,7 +16,7 @@
130+
min: (number){ |(*(int){ 1 }, (number){ >0 }) }
131+
}
132+
staged: (struct){
133+
- c: (string){ |(*(string){ "a" }, (string){ "b" }) }
134+
+ c: (string){ |(*(string){ "a" }, *(string){ "b" }) }
135+
d: (string){ |(*(string){ "a" }, (string){ "b" }) }
136+
}
137+
issue763a: (struct){
134138
-- diff/explanation --
135139
The changes in default behavior as are shown here are according to spec, as is
136140
described at the top of the file. These changes may pose too much of a problem
137141
for the transition to the new evaluator, though.
138-
TODO: consider reintroducing bugs.
142+
UPDATE: we have made evalv3 a bit more in line with evalv2. Note how this
143+
affects staged.c, though.
144+
TODO(defaults): consider these cases with a potential default redesign.
139145
-- diff/todo/p3 --
140146
Reordering.
141147
-- out/eval --

internal/core/adt/disjunct2.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,9 @@ func (n *nodeContext) processDisjunctions() *Bottom {
384384
case 1:
385385
d := cross[0].node
386386
n.setBaseValue(d)
387-
n.defaultMode = cross[0].defaultMode
387+
if n.defaultMode == maybeDefault {
388+
n.defaultMode = cross[0].defaultMode
389+
}
388390
if n.defaultAttemptInCycle != nil && n.defaultMode != isDefault {
389391
c := n.ctx
390392
path := c.PathToString(n.defaultAttemptInCycle.Path())
@@ -574,7 +576,8 @@ func (n *nodeContext) doDisjunct(c Conjunct, m defaultMode, mode runMode, hole i
574576
return nil, err
575577
}
576578

577-
d = d.node.DerefDisjunct().state
579+
d.node.DerefDisjunct().state.defaultMode = d.defaultMode
580+
d = d.node.DerefDisjunct().state // TODO: maybe do not unroll at all.
578581

579582
return d, nil
580583
}

0 commit comments

Comments
 (0)