Skip to content

Commit

Permalink
internal/core/adt: do not require closeContext.group to be non-nil
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
cuematthew committed Jul 26, 2024
1 parent 5de5b42 commit c8f3cad
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 4 deletions.
77 changes: 77 additions & 0 deletions cue/testdata/eval/issue3301.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
-- in.cue --
object: #Leaf & {}

#Base: {
extra?: {...}
}

#Mid: {
#Base
}

#Leaf: {
#Mid
extra?: {...}
more?: int
if extra.foo != _|_ {
if more != _|_ {
foo: "bar"
}
}
}
-- out/eval --
(struct){
object: (#struct){
extra?: (#struct){
}
more?: (int){ int }
}
#Base: (#struct){
extra?: (#struct){
}
}
#Mid: (#struct){
extra?: (#struct){
}
}
#Leaf: (#struct){
extra?: (#struct){
}
more?: (int){ int }
}
}
-- out/eval/stats --
Leaks: 0
Freed: 11
Reused: 5
Allocs: 6
Retain: 7

Unifications: 11
Conjuncts: 25
Disjuncts: 18
-- out/compile --
--- in.cue
{
object: (〈0;#Leaf〉 & {})
#Base: {
extra?: {
...
}
}
#Mid: {
〈1;#Base〉
}
#Leaf: {
〈1;#Mid〉
extra?: {
...
}
more?: int
if (〈0;extra〉.foo != _|_(explicit error (_|_ literal) in source)) {
if (〈1;more〉 != _|_(explicit error (_|_ literal) in source)) {
foo: "bar"
}
}
}
}
19 changes: 15 additions & 4 deletions internal/core/adt/fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -433,17 +433,28 @@ func (cc *closeContext) linkNotify(ctx *OpContext, dst *Vertex, key *closeContex
func (cc *closeContext) assignConjunct(ctx *OpContext, root *closeContext, c Conjunct, mode ArcType, check, checkClosed bool) (arc *closeContext, pos int, added bool) {
arc = cc.getKeyedCC(ctx, root, c.CloseInfo.CycleInfo, mode, checkClosed)

pos = len(*arc.group)

c.CloseInfo.cc = nil
added = !check || !hasConjunct(*arc.group, c)

var group ConjunctGroup
if arc.group != nil {
group = *arc.group
}
pos = len(group)

added = !check || !hasConjunct(group, c)
if added {
c.CloseInfo.cc = arc

if c.CloseInfo.cc.src != arc.src {
panic("Inconsistent src")
}
*arc.group = append(*arc.group, c)

group = append(group, c)
if arc.group == nil {
arc.group = &group
} else {
*arc.group = group
}
}

return arc, pos, added
Expand Down

0 comments on commit c8f3cad

Please sign in to comment.