Skip to content

Commit 02ff29b

Browse files
committed
internal/core/convert: fix faulty label update
The code assumed that the arc for which the label was updated was generated by convert.go itself. This is not always the case, however. This fix is to always use a new Vertex. Fixes #616 Change-Id: Icddda11d9a5f178e7ae402d80a8d57d315be04d7 Reviewed-on: https://cue-review.googlesource.com/c/cue/+/8047 Reviewed-by: Marcel van Lohuizen <[email protected]>
1 parent cefe38b commit 02ff29b

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

internal/core/convert/go.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,8 @@ func convertRec(ctx *adt.OpContext, nilIsTop bool, x interface{}) adt.Value {
451451
obj.Decls = append(obj.Decls, &adt.Field{Label: f, Value: sub})
452452
arc, ok := sub.(*adt.Vertex)
453453
if ok {
454+
a := *arc
455+
arc = &a
454456
arc.Label = f
455457
} else {
456458
arc = &adt.Vertex{Label: f, BaseValue: sub}
@@ -497,6 +499,8 @@ func convertRec(ctx *adt.OpContext, nilIsTop bool, x interface{}) adt.Value {
497499
f := ctx.StringLabel(s)
498500
arc, ok := sub.(*adt.Vertex)
499501
if ok {
502+
a := *arc
503+
arc = &a
500504
arc.Label = f
501505
} else {
502506
arc = &adt.Vertex{Label: f, BaseValue: sub}

pkg/list/testdata/sort.txtar

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// Issue #616
2+
-- in.cue --
3+
import "list"
4+
5+
t1: {
6+
l: ["c","b","a"]
7+
ls: list.Sort(l, list.Ascending)
8+
il: list.IsSorted(l, list.Ascending)
9+
ils: list.IsSorted(ls, list.Ascending)
10+
}
11+
12+
t2: {
13+
l: ["c","b","a"]
14+
il: list.IsSorted(l, list.Ascending)
15+
16+
ls: list.Sort(l, list.Ascending)
17+
ils: list.IsSorted(ls, list.Ascending)
18+
}
19+
20+
t3: {
21+
L: ["c","b","a", "e", "d"]
22+
l: list.Take(L, 4)
23+
il: list.IsSorted(l, list.Ascending)
24+
25+
ls: list.Sort(l, list.Ascending)
26+
ils: list.IsSorted(ls, list.Ascending)
27+
28+
l2: l
29+
l3: ls
30+
}
31+
32+
-- out/list --
33+
t1: {
34+
l: ["c", "b", "a"]
35+
ls: ["a", "b", "c"]
36+
il: false
37+
ils: true
38+
}
39+
t2: {
40+
l: ["c", "b", "a"]
41+
il: false
42+
ls: ["a", "b", "c"]
43+
ils: true
44+
}
45+
t3: {
46+
L: ["c", "b", "a", "e", "d"]
47+
l: ["c", "b", "a", "e"]
48+
il: false
49+
ls: ["a", "b", "c", "e"]
50+
ils: true
51+
l2: ["c", "b", "a", "e"]
52+
l3: ["a", "b", "c", "e"]
53+
}
54+

0 commit comments

Comments
 (0)