Skip to content

Commit c8f3cad

Browse files
committed
internal/core/adt: do not require closeContext.group to be non-nil
In fields.go CloseInfo.spawnCloseContext creates a closeContext with a nil group field. That explodes closeContext.assignConjunct. closeContext.assignConject has been reworked so it can cope with a nil group field. I did also try changing CloseInfo.spawnCloseContext to make it always populate the group field, but that caused other tests to break via a "group misaligned" panic in overlayContext.allocCC. Added a test and verified it fails without this fix. Fixes #3301. Change-Id: Ifcfb4b8d38d6ccc84e47f2a9a5de36a1721548ba Signed-off-by: Matthew Sackman <[email protected]> Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1198356 Reviewed-by: Marcel van Lohuizen <[email protected]> TryBot-Result: CUEcueckoo <[email protected]>
1 parent 5de5b42 commit c8f3cad

File tree

2 files changed

+92
-4
lines changed

2 files changed

+92
-4
lines changed

cue/testdata/eval/issue3301.txtar

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
-- in.cue --
2+
object: #Leaf & {}
3+
4+
#Base: {
5+
extra?: {...}
6+
}
7+
8+
#Mid: {
9+
#Base
10+
}
11+
12+
#Leaf: {
13+
#Mid
14+
extra?: {...}
15+
more?: int
16+
if extra.foo != _|_ {
17+
if more != _|_ {
18+
foo: "bar"
19+
}
20+
}
21+
}
22+
-- out/eval --
23+
(struct){
24+
object: (#struct){
25+
extra?: (#struct){
26+
}
27+
more?: (int){ int }
28+
}
29+
#Base: (#struct){
30+
extra?: (#struct){
31+
}
32+
}
33+
#Mid: (#struct){
34+
extra?: (#struct){
35+
}
36+
}
37+
#Leaf: (#struct){
38+
extra?: (#struct){
39+
}
40+
more?: (int){ int }
41+
}
42+
}
43+
-- out/eval/stats --
44+
Leaks: 0
45+
Freed: 11
46+
Reused: 5
47+
Allocs: 6
48+
Retain: 7
49+
50+
Unifications: 11
51+
Conjuncts: 25
52+
Disjuncts: 18
53+
-- out/compile --
54+
--- in.cue
55+
{
56+
object: (〈0;#Leaf〉 & {})
57+
#Base: {
58+
extra?: {
59+
...
60+
}
61+
}
62+
#Mid: {
63+
〈1;#Base〉
64+
}
65+
#Leaf: {
66+
〈1;#Mid〉
67+
extra?: {
68+
...
69+
}
70+
more?: int
71+
if (〈0;extra〉.foo != _|_(explicit error (_|_ literal) in source)) {
72+
if (〈1;more〉 != _|_(explicit error (_|_ literal) in source)) {
73+
foo: "bar"
74+
}
75+
}
76+
}
77+
}

internal/core/adt/fields.go

+15-4
Original file line numberDiff line numberDiff line change
@@ -433,17 +433,28 @@ func (cc *closeContext) linkNotify(ctx *OpContext, dst *Vertex, key *closeContex
433433
func (cc *closeContext) assignConjunct(ctx *OpContext, root *closeContext, c Conjunct, mode ArcType, check, checkClosed bool) (arc *closeContext, pos int, added bool) {
434434
arc = cc.getKeyedCC(ctx, root, c.CloseInfo.CycleInfo, mode, checkClosed)
435435

436-
pos = len(*arc.group)
437-
438436
c.CloseInfo.cc = nil
439-
added = !check || !hasConjunct(*arc.group, c)
437+
438+
var group ConjunctGroup
439+
if arc.group != nil {
440+
group = *arc.group
441+
}
442+
pos = len(group)
443+
444+
added = !check || !hasConjunct(group, c)
440445
if added {
441446
c.CloseInfo.cc = arc
442447

443448
if c.CloseInfo.cc.src != arc.src {
444449
panic("Inconsistent src")
445450
}
446-
*arc.group = append(*arc.group, c)
451+
452+
group = append(group, c)
453+
if arc.group == nil {
454+
arc.group = &group
455+
} else {
456+
*arc.group = group
457+
}
447458
}
448459

449460
return arc, pos, added

0 commit comments

Comments
 (0)