Skip to content

Commit

Permalink
internal/core/adt: fix dropping of field
Browse files Browse the repository at this point in the history
Previously, inline struct were reapproriated
by linking them into the destination struct
by setting the parent and label. However,
labels are used to look up fields. This resulted
in fields being dropped.

To keep access to the field, rather than overwriting
it, we now point the parent to the node in which it is
shared, rather than its parent. This introduces an
additional path component upon traversal, which
we subsequently adjust for in the code that generates
paths.

Issue #3601

Signed-off-by: Marcel van Lohuizen <mpvl@gmail.com>
Change-Id: I41987d4201ce34b25904f06afaf3e5474fbf926d
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1205232
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
Reviewed-by: Matthew Sackman <matthew@cue.works>
mpvl committed Dec 8, 2024
1 parent 787d04c commit 432c114
Showing 3 changed files with 8 additions and 12 deletions.
12 changes: 3 additions & 9 deletions cue/testdata/eval/sharing.txtar
Original file line number Diff line number Diff line change
@@ -75,10 +75,7 @@ Disjuncts: 48
}
}
out: (struct){
b: (_|_){
// [incomplete] issue3601.ok1.out.b: undefined field: a:
// ./in.cue:12:11
}
b: (_){ _ }
}
}
}
@@ -149,7 +146,7 @@ diff old new
}
X: (struct){
a: (struct){
@@ -31,47 +24,40 @@
@@ -31,47 +24,37 @@
b: (_){ _ }
}
}
@@ -161,10 +158,7 @@ diff old new
- debug: (_|_){
- // [eval]
+ out: (struct){
+ b: (_|_){
+ // [incomplete] issue3601.ok1.out.b: undefined field: a:
+ // ./in.cue:12:11
+ }
+ b: (_){ _ }
+ }
+ }
+ }
5 changes: 4 additions & 1 deletion internal/core/adt/composite.go
Original file line number Diff line number Diff line change
@@ -1479,7 +1479,10 @@ func appendPath(a []Feature, v *Vertex) []Feature {
return a
}
a = appendPath(a, v.Parent)
if v.Label != 0 {
// Skip if the node is a structure-shared node that has been assingned to
// the parent as it's new location: in this case the parent node will
// have the desired label.
if v.Label != 0 && v.Parent.BaseValue != v {
// A Label may be 0 for programmatically inserted nodes.
a = append(a, v.Label)
}
3 changes: 1 addition & 2 deletions internal/core/adt/share.go
Original file line number Diff line number Diff line change
@@ -79,7 +79,6 @@ func (n *nodeContext) finalizeSharing() {
// its assigned location.
if v.state != nil && v.state.parent != nil {
v.Parent = v.state.parent
v.Label = n.node.Label

// TODO: see if this can be removed and why some errors are not
// propagated when removed.
@@ -112,7 +111,7 @@ func (n *nodeContext) share(c Conjunct, arc *Vertex, id CloseInfo) {
// Setting the parent in the state instead allows us to defer setting
// Parent until it is safe to do so..
if s := arc.getState(n.ctx); s != nil {
s.parent = n.node.Parent
s.parent = n.node
}
}

0 comments on commit 432c114

Please sign in to comment.