Skip to content

Commit efd38e6

Browse files
committed
internal/core/export: fix dereferencing bug
In a previous fix we posponed the dereferencing of a value, because we needed the non-dereferenced value of the ArcType. As it turns out, we also need the non-dereferenced value for the docs and attributes. This change fixes that. Note that the test has some modifications for a debug testing. We leave this in for convenience down the line. We leave the snippet itself to get an idea of the reducer that was used to fix the code. Issue #2884 Signed-off-by: Marcel van Lohuizen <[email protected]> Change-Id: I59c97bfdb53918cd83b88be23a3a4bc5391fdb6f Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1194651 TryBot-Result: CUEcueckoo <[email protected]> Unity-Result: CUE porcuepine <[email protected]> Reviewed-by: Daniel Martí <[email protected]>
1 parent 645d586 commit efd38e6

File tree

4 files changed

+24
-203
lines changed

4 files changed

+24
-203
lines changed

internal/core/export/testdata/main/attrs.txtar

Lines changed: 13 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ dynamicSimple: {
331331
} @field(2) @field(1) @field(4) @field(3) @field(5)
332332
doNotPropagate: {
333333
#A: {} @attr1()
334-
a: {} @attr1()
334+
a: {}
335335

336336
// Do not accumulated field attributes in embedding.
337337
#B: {} @attr1()
@@ -399,7 +399,7 @@ dynamicSimple: {
399399
} @field(2) @field(1) @field(4) @field(3) @field(5)
400400
doNotPropagate: {
401401
#A: {} @attr1()
402-
a: {} @attr1()
402+
a: {}
403403
#B: {} @attr1()
404404
b: {}
405405
}
@@ -456,35 +456,10 @@ dynamicSimple: {
456456
diff old new
457457
--- old
458458
+++ new
459-
@@ -125,44 +125,45 @@
460-
} @field(2) @field(1) @field(4) @field(3) @field(5)
461-
doNotPropagate: {
462-
#A: {} @attr1()
463-
- a: {}
464-
-
465-
- // Do not accumulated field attributes in embedding.
466-
- #B: {} @attr1()
467-
- b: {}
468-
- }
469-
- embedScalarField: {
470-
- a: 2 @attr1() @attr2()
471-
- }
472-
- embedScalarDecl: {
473-
- b0: {
474-
- 2, @attr1()
475-
- }
476-
- b1: {
477-
- 2, @attr1()
478-
- }
479-
- b2: {
480-
- 2, @attr2(), @attr1()
481-
- }
482-
- }
483-
- dontMergeForDef: {
484-
- a: {
485-
- @decl1()
486-
- }
487-
- b: {
459+
@@ -150,19 +150,20 @@
460+
@decl1()
461+
}
462+
b: {
488463
- @decl1(), @decl2()
489464
- x: 1
490465
- }
@@ -498,31 +473,6 @@ diff old new
498473
- comprehensions: {
499474
- @step(0)
500475
- @step(2c)
501-
+ a: {} @attr1()
502-
+
503-
+ // Do not accumulated field attributes in embedding.
504-
+ #B: {} @attr1()
505-
+ b: {}
506-
+ }
507-
+ embedScalarField: {
508-
+ a: 2 @attr1() @attr2()
509-
+ }
510-
+ embedScalarDecl: {
511-
+ b0: {
512-
+ 2, @attr1()
513-
+ }
514-
+ b1: {
515-
+ 2, @attr1()
516-
+ }
517-
+ b2: {
518-
+ 2, @attr2(), @attr1()
519-
+ }
520-
+ }
521-
+ dontMergeForDef: {
522-
+ a: {
523-
+ @decl1()
524-
+ }
525-
+ b: {
526476
+ @decl2(), @decl1()
527477
+ x: 1
528478
+ }
@@ -540,33 +490,10 @@ diff old new
540490
c1: {} @step(1)
541491
c2: {
542492
@step(2a)
543-
@@ -192,42 +193,43 @@
544-
} @field(2) @field(1) @field(4) @field(3) @field(5)
545-
doNotPropagate: {
546-
#A: {} @attr1()
547-
- a: {}
548-
- #B: {} @attr1()
549-
- b: {}
550-
- }
551-
- embedScalarField: {
552-
- a: 2 @attr1() @attr2()
553-
- }
554-
- embedScalarDecl: {
555-
- b0: {
556-
- 2, @attr1()
557-
- }
558-
- b1: {
559-
- 2, @attr1()
560-
- }
561-
- b2: {
562-
- 2, @attr2(), @attr1()
563-
- }
564-
- }
565-
- dontMergeForDef: {
566-
- a: {
567-
- @decl1()
568-
- }
569-
- b: {
493+
@@ -215,19 +216,20 @@
494+
@decl1()
495+
}
496+
b: {
570497
- @decl1(), @decl2()
571498
- x: 1
572499
- }
@@ -580,29 +507,6 @@ diff old new
580507
- comprehensions: {
581508
- @step(0)
582509
- @step(2c)
583-
+ a: {} @attr1()
584-
+ #B: {} @attr1()
585-
+ b: {}
586-
+ }
587-
+ embedScalarField: {
588-
+ a: 2 @attr1() @attr2()
589-
+ }
590-
+ embedScalarDecl: {
591-
+ b0: {
592-
+ 2, @attr1()
593-
+ }
594-
+ b1: {
595-
+ 2, @attr1()
596-
+ }
597-
+ b2: {
598-
+ 2, @attr2(), @attr1()
599-
+ }
600-
+ }
601-
+ dontMergeForDef: {
602-
+ a: {
603-
+ @decl1()
604-
+ }
605-
+ b: {
606510
+ @decl2(), @decl1()
607511
+ x: 1
608512
+ }
@@ -621,9 +525,9 @@ diff old new
621525
c2: {
622526
@step(2a)
623527
-- diff/value/todo/p1 --
624-
== Eval.doNotPropagate
625-
.a: missing attribute.
626-
#B: missing comment
528+
comprehension: @step(4c) added in comprehensions
529+
-- diff/value/todo/p3 --
530+
Reordering of attributes.
627531
-- out/value --
628532
== Simplified
629533
{

internal/core/export/testdata/main/def.txtar

Lines changed: 0 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -38,98 +38,6 @@ g: #d
3838

3939
[g e]
4040
[g f]
41-
-- out/value-v3 --
42-
== Simplified
43-
{
44-
a: *2 | int
45-
c: {}
46-
g: {
47-
e!: =~"a"
48-
}
49-
}
50-
== Raw
51-
{
52-
a: *2 | int
53-
b?: 4 | 5
54-
c: {}
55-
#d: {
56-
e!: =~"a"
57-
f?: 1
58-
}
59-
g: {
60-
e!: =~"a"
61-
f?: 1
62-
}
63-
}
64-
== Final
65-
{
66-
a: 2
67-
c: {}
68-
g: {
69-
e!: =~"a"
70-
}
71-
}
72-
== All
73-
{
74-
a: *2 | int
75-
b?: 4 | 5
76-
c: {}
77-
#d: {
78-
e!: =~"a"
79-
f?: 1
80-
}
81-
g: {
82-
e!: =~"a"
83-
f?: 1
84-
}
85-
}
86-
== Eval
87-
{
88-
a: 2
89-
b?: 4 | 5
90-
c: {}
91-
#d: {
92-
e!: =~"a"
93-
f?: 1
94-
}
95-
g: {
96-
e!: =~"a"
97-
f?: 1
98-
}
99-
}
100-
-- diff/-out/value-v3<==>+out/value --
101-
diff old new
102-
--- old
103-
+++ new
104-
@@ -2,8 +2,6 @@
105-
{
106-
a: *2 | int
107-
c: {}
108-
-
109-
- // Issue #2305
110-
g: {
111-
e!: =~"a"
112-
}
113-
@@ -17,8 +15,6 @@
114-
e!: =~"a"
115-
f?: 1
116-
}
117-
-
118-
- // Issue #2305
119-
g: {
120-
e!: =~"a"
121-
f?: 1
122-
@@ -41,8 +37,6 @@
123-
e!: =~"a"
124-
f?: 1
125-
}
126-
-
127-
- // Issue #2305
128-
g: {
129-
e!: =~"a"
130-
f?: 1
131-
-- diff/value/todo/p1 --
132-
Missing comments.
13341
-- out/value --
13442
== Simplified
13543
{

internal/core/export/value.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -446,8 +446,7 @@ func (e *exporter) structComposite(v *adt.Vertex, attrs []*ast.Attribute) ast.Ex
446446

447447
internal.SetConstraint(f, arc.ArcType.Token())
448448

449-
arc = arc.DerefValue()
450-
f.Value = e.vertex(arc)
449+
f.Value = e.vertex(arc.DerefValue())
451450

452451
if label.IsDef() {
453452
e.inDefinition--

internal/core/export/value_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,21 @@ var exclude = map[string]string{
3737
}
3838

3939
func TestValue(t *testing.T) {
40+
const debugValue = `
41+
-- in.cue --
42+
// Issue #2305
43+
g: #d
44+
#d: 1
45+
`
46+
4047
test := cuetxtar.TxTarTest{
4148
Root: "./testdata/main",
4249
Name: "value",
4350
Skip: exclude,
4451
Matrix: cuetdtest.SmallMatrix,
52+
53+
// Uncomment to debug an isolated test case.
54+
// DebugArchive: debugValue,
4555
}
4656

4757
test.Run(t, func(t *cuetxtar.Test) {

0 commit comments

Comments
 (0)