Skip to content

Commit 20ed9ab

Browse files
committed
internal/core/compile: fix let cycle error
Method was not marked with a '*', causing error to be lost. Fixes #1042 Change-Id: I600940fe933c7122c7f2e06b97542cb44655d5ae Reviewed-on: https://cue-review.googlesource.com/c/cue/+/10001 Reviewed-by: CUE cueckoo <[email protected]> Reviewed-by: Paul Jolly <[email protected]>
1 parent 0070bb1 commit 20ed9ab

File tree

3 files changed

+87
-149
lines changed

3 files changed

+87
-149
lines changed

cue/testdata/compile/let.txtar

Lines changed: 2 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ issue767: {
5757
}
5858
}
5959
-- out/compile --
60+
b.let[]: cyclic references in let clause or alias:
61+
./in.cue:10:13
6062
--- in.cue
6163
{
6264
a: {
@@ -92,60 +94,5 @@ issue767: {
9294
}
9395
}
9496
-- out/eval --
95-
Errors:
9697
b.let[]: cyclic references in let clause or alias:
9798
./in.cue:10:13
98-
99-
Result:
100-
(_|_){
101-
// [eval]
102-
a: (struct){
103-
b: (int){ 5 }
104-
c: (int){ 5 }
105-
}
106-
b: (_|_){
107-
// [eval]
108-
b: (_|_){
109-
// [eval] b.let[]: cyclic references in let clause or alias:
110-
// ./in.cue:10:13
111-
}
112-
c: (int){ 5 }
113-
}
114-
fieldOffset: (struct){
115-
a: (struct){
116-
p1: (struct){
117-
x: (struct){
118-
value: (int){ 2 }
119-
}
120-
}
121-
p2: (struct){
122-
x: (struct){
123-
value: (int){ 2 }
124-
}
125-
}
126-
}
127-
b: (struct){
128-
p1: (struct){
129-
x: (struct){
130-
x: (struct){
131-
y: (int){ 2 }
132-
}
133-
}
134-
}
135-
p2: (struct){
136-
x: (struct){
137-
x: (struct){
138-
y: (int){ 2 }
139-
}
140-
}
141-
}
142-
}
143-
}
144-
issue767: (struct){
145-
#Foo: (#struct){
146-
out: (#struct){
147-
x: (string){ "" }
148-
}
149-
}
150-
}
151-
}

cue/testdata/references/let.txtar

Lines changed: 84 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,57 @@ incompleteLet: {
6464
}
6565
}
6666

67+
cycles: {
68+
a: {
69+
let A = { c: B }
70+
let B = A
71+
out: A
72+
}
73+
74+
b: {
75+
let A = { c: B }
76+
let B = { A.c }
77+
out: A
78+
}
79+
80+
issue1042: {
81+
#FullAdder: {
82+
// IN
83+
a: bool
84+
b: bool
85+
c: bool
86+
// OUT
87+
sum: bool
88+
carry: bool
89+
}
90+
91+
#Add16: {
92+
a: [bool] * 16
93+
b: [bool] * 16
94+
out: [bool] * 16
95+
96+
let fulladders = [
97+
for i in list.Range(0, 4, 1) {
98+
#FullAdder & {"a": a[i], "b": b[i], c: carries[i]}
99+
}
100+
]
101+
let carries = [
102+
false,
103+
for i in list.Range(0, 4, 1) { fulladders[i].carry }
104+
]
105+
out: [
106+
for i in list.Range(0, 4, 1) { fulladders[i].sum }
107+
]
108+
}
109+
}
110+
}
67111
-- out/compile --
112+
cycles.a.let[].c.c: cyclic references in let clause or alias:
113+
./in.cue:68:18
114+
cycles.b.let[].c.c: cyclic references in let clause or alias:
115+
./in.cue:74:18
116+
cycles.issue1042.#Add16.let[].for[].c.for[].for[].c: cyclic references in let clause or alias:
117+
./in.cue:97:50
68118
--- in.cue
69119
{
70120
a1list: [
@@ -183,103 +233,44 @@ incompleteLet: {
183233
if (〈import;list〉.max < 0) {}
184234
}
185235
}
186-
}
187-
-- out/eval --
188-
(struct){
189-
a1list: (#list){
190-
0: (int){ 1 }
191-
}
192-
a1: (int){ 101 }
193-
a2list: (#list){
194-
0: (int){ 2 }
195-
}
196-
a2: (struct){
197-
b: (int){ 202 }
198-
}
199-
a3list: (#list){
200-
0: (int){ 3 }
201-
}
202-
a3: (struct){
203-
b: (struct){
204-
c: (int){ 303 }
205-
}
206-
}
207-
a4list: (#list){
208-
0: (int){ 4 }
209-
}
210-
a4: (#list){
211-
0: (struct){
212-
v: (int){ 404 }
236+
cycles: {
237+
a: {
238+
out: 〈0;let A〉
213239
}
214-
}
215-
a5list: (#list){
216-
0: (int){ 5 }
217-
}
218-
a5: (struct){
219-
b: (#list){
220-
0: (struct){
221-
v: (int){ 505 }
222-
}
223-
}
224-
}
225-
a6list: (#list){
226-
0: (int){ 6 }
227-
}
228-
a6: (struct){
229-
b: (struct){
230-
c: (#list){
231-
0: (struct){
232-
v: (int){ 606 }
233-
}
234-
}
235-
}
236-
}
237-
a7list: (#list){
238-
0: (int){ 7 }
239-
}
240-
a7: (struct){
241-
v: (int){ 707 }
242-
}
243-
a8list: (#list){
244-
0: (int){ 8 }
245-
}
246-
a8: (struct){
247-
b: (struct){
248-
v: (int){ 808 }
240+
b: {
241+
out: 〈0;let A〉
249242
}
250-
}
251-
a9list: (#list){
252-
0: (int){ 9 }
253-
}
254-
a9: (struct){
255-
b: (struct){
256-
c: (struct){
257-
v: (int){ 909 }
243+
issue1042: {
244+
#FullAdder: {
245+
a: bool
246+
b: bool
247+
c: bool
248+
sum: bool
249+
carry: bool
258250
}
259-
}
260-
}
261-
incompleteLet: (struct){
262-
input: (#list){
263-
0: (int){ 1 }
264-
1: (int){ 2 }
265-
2: (int){ 3 }
266-
3: (int){ 4 }
267-
4: (int){ 5 }
268-
}
269-
last: (struct){
270-
min: (int){ 1 }
271-
max: (int){ 5 }
272-
}
273-
bar: (struct){
274-
min: (int){ 1 }
275-
max: (_|_){
276-
// [incomplete] incompleteLet.bar.max: undefined field: max:
277-
// ./in.cue:54:23
251+
#Add16: {
252+
a: ([
253+
bool,
254+
] * 16)
255+
b: ([
256+
bool,
257+
] * 16)
258+
out: ([
259+
bool,
260+
] * 16)
261+
out: [
262+
for _, i in 〈import;list〉.Range(0, 4, 1) {
263+
〈2;let fulladders〉[〈1;i〉].sum
264+
},
265+
]
278266
}
279267
}
280-
x: (_|_){
281-
// [incomplete] incompleteLet.x: undefined field: max:
282-
// ./in.cue:61:17
283-
}
284268
}
285269
}
270+
-- out/eval --
271+
cycles.a.let[].c.c: cyclic references in let clause or alias:
272+
./in.cue:68:18
273+
cycles.b.let[].c.c: cyclic references in let clause or alias:
274+
./in.cue:74:18
275+
cycles.issue1042.#Add16.let[].for[].c.for[].for[].c: cyclic references in let clause or alias:
276+
./in.cue:97:50

internal/core/compile/compile.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ func (c *compiler) updateAlias(id *ast.Ident, expr adt.Expr) {
190190
}
191191

192192
// lookupAlias looks up an alias with the given name at the k'th stack position.
193-
func (c compiler) lookupAlias(k int, id *ast.Ident) aliasEntry {
193+
func (c *compiler) lookupAlias(k int, id *ast.Ident) aliasEntry {
194194
m := c.stack[k].aliases
195195
name := id.Name
196196
entry, ok := m[name]

0 commit comments

Comments
 (0)