File tree Expand file tree Collapse file tree 2 files changed +160
-3
lines changed Expand file tree Collapse file tree 2 files changed +160
-3
lines changed Original file line number Diff line number Diff line change
1
+ -- in.cue --
2
+ // Allow lookup in partially evaluated struct as long as the end result is
3
+ // concrete.
4
+ A: {
5
+ a: {
6
+ parent: ""
7
+ children: [ for k, v in A if v.parent == k { k } ]
8
+ }
9
+ b: {
10
+ parent: "a"
11
+ children: [ for k, v in A if v.parent == k { k } ]
12
+ }
13
+ }
14
+
15
+ // TODO(errors): this should result in an incomplete error.
16
+ // A simplified control flow should help here.
17
+ B: {
18
+ a: {
19
+ parent: ""
20
+ children: [ for k, v in B for _, w in v.children { k } ]
21
+ }
22
+ }
23
+
24
+ // Issue #486
25
+ Issue486: {
26
+ A: {
27
+ a: {
28
+ parent: ""
29
+ children: [...string]
30
+ }
31
+ b: {
32
+ parent: "a"
33
+ children: [...string]
34
+ }
35
+ c: {
36
+ parent: "b"
37
+ children: [...string]
38
+ }
39
+ }
40
+
41
+ A: [Name=string]: {
42
+ children: [
43
+ for k, v in A
44
+ if v.parent == Name {
45
+ k
46
+ }
47
+ ]
48
+ }
49
+ }
50
+ -- out/eval --
51
+ (struct){
52
+ A: (struct){
53
+ a: (struct){
54
+ parent: (string){ "" }
55
+ children: (#list){
56
+ }
57
+ }
58
+ b: (struct){
59
+ parent: (string){ "a" }
60
+ children: (#list){
61
+ }
62
+ }
63
+ }
64
+ B: (struct){
65
+ a: (struct){
66
+ parent: (string){ "" }
67
+ children: (#list){
68
+ }
69
+ }
70
+ }
71
+ Issue486: (struct){
72
+ A: (struct){
73
+ a: (struct){
74
+ parent: (string){ "" }
75
+ children: (#list){
76
+ 0: (string){ "b" }
77
+ }
78
+ }
79
+ b: (struct){
80
+ parent: (string){ "a" }
81
+ children: (#list){
82
+ 0: (string){ "c" }
83
+ }
84
+ }
85
+ c: (struct){
86
+ parent: (string){ "b" }
87
+ children: (#list){
88
+ }
89
+ }
90
+ }
91
+ }
92
+ }
93
+ -- out/compile --
94
+ --- in.cue
95
+ {
96
+ A: {
97
+ a: {
98
+ parent: ""
99
+ children: [
100
+ for k, v in 〈2;A〉 if (〈0;v〉.parent == 〈0;k〉) {
101
+ 〈1;k〉
102
+ },
103
+ ]
104
+ }
105
+ b: {
106
+ parent: "a"
107
+ children: [
108
+ for k, v in 〈2;A〉 if (〈0;v〉.parent == 〈0;k〉) {
109
+ 〈1;k〉
110
+ },
111
+ ]
112
+ }
113
+ }
114
+ B: {
115
+ a: {
116
+ parent: ""
117
+ children: [
118
+ for k, v in 〈2;B〉 for _, w in 〈0;v〉.children {
119
+ 〈2;k〉
120
+ },
121
+ ]
122
+ }
123
+ }
124
+ Issue486: {
125
+ A: {
126
+ a: {
127
+ parent: ""
128
+ children: [
129
+ ...string,
130
+ ]
131
+ }
132
+ b: {
133
+ parent: "a"
134
+ children: [
135
+ ...string,
136
+ ]
137
+ }
138
+ c: {
139
+ parent: "b"
140
+ children: [
141
+ ...string,
142
+ ]
143
+ }
144
+ }
145
+ A: {
146
+ [string]: {
147
+ children: [
148
+ for k, v in 〈2;A〉 if (〈0;v〉.parent == 〈2;-〉) {
149
+ 〈1;k〉
150
+ },
151
+ ]
152
+ }
153
+ }
154
+ }
155
+ }
Original file line number Diff line number Diff line change @@ -582,7 +582,7 @@ func (x *SelectorExpr) Source() ast.Node {
582
582
}
583
583
584
584
func (x * SelectorExpr ) resolve (c * OpContext ) * Vertex {
585
- n := c .node (x .X , Partial )
585
+ n := c .node (x .X , EvaluatingArcs )
586
586
return c .lookup (n , x .Src .Sel .Pos (), x .Sel )
587
587
}
588
588
@@ -605,7 +605,7 @@ func (x *IndexExpr) Source() ast.Node {
605
605
606
606
func (x * IndexExpr ) resolve (ctx * OpContext ) * Vertex {
607
607
// TODO: support byte index.
608
- n := ctx .node (x .X , Partial )
608
+ n := ctx .node (x .X , EvaluatingArcs )
609
609
i := ctx .value (x .Index )
610
610
f := ctx .Label (i )
611
611
return ctx .lookup (n , x .Src .Index .Pos (), f )
@@ -1171,8 +1171,10 @@ func (x *ForClause) Source() ast.Node {
1171
1171
}
1172
1172
1173
1173
func (x * ForClause ) yield (c * OpContext , f YieldFunc ) {
1174
- n := c .node (x .Src , Finalized )
1174
+ n := c .node (x .Src , EvaluatingArcs )
1175
1175
for _ , a := range n .Arcs {
1176
+ c .Unify (c , a , Partial )
1177
+
1176
1178
if ! a .Label .IsRegular () {
1177
1179
continue
1178
1180
}
You can’t perform that action at this time.
0 commit comments