Skip to content
This repository has been archived by the owner on Nov 18, 2021. It is now read-only.

Commit

Permalink
internal/core/adt: track more incomplete errors
Browse files Browse the repository at this point in the history
This was sometimes lost in computation,
for instance across package boundaries.

This results in less nice errors for certain cycle cases.
This should be handled in an evaluator rework.

Fixes #854

Change-Id: Ieb927dbb8d11d2ad2651b85a375d11913a8612b2
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/9181
Reviewed-by: Marcel van Lohuizen <[email protected]>
  • Loading branch information
mpvl committed Mar 29, 2021
1 parent 6195171 commit 9b263eb
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 25 deletions.
40 changes: 15 additions & 25 deletions cue/testdata/cycle/compbottomnofinal.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -370,14 +370,8 @@ medium.p1.#Y: cycle: field port was added after an if clause evaluated it
medium.p2.#Y: cycle: field port was added after an if clause evaluated it
medium.p3.Y: cycle: new field port inserted by if clause that was previously evaluated by another if clause
medium.p4.Y: cycle: new field port inserted by if clause that was previously evaluated by another if clause
medium.p5.#X: cycle: new field port inserted by if clause that was previously evaluated by another if clause
medium.p6.#X: cycle: new field port inserted by if clause that was previously evaluated by another if clause
minimal.b: cycle: new field port inserted by if clause that was previously evaluated by another if clause
small.p1.#Y: cycle: field port was added after an if clause evaluated it
small.p2.#X: cycle: new field port inserted by if clause that was previously evaluated by another if clause
small.p2.#Y: cycle: field port was added after an if clause evaluated it
small.p2.#X: cannot use "" (type string) as int in argument 1 to strconv.FormatInt:
./in.cue:50:7

Result:
(_|_){
Expand All @@ -404,17 +398,13 @@ Result:
port: (string){ "" }
}
}
p2: (_|_){
// [eval]
#X: (_|_){
// [eval] small.p2.#X: cycle: new field port inserted by if clause that was previously evaluated by another if clause
port: (_|_){
// [eval] small.p2.#X: cannot use "" (type string) as int in argument 1 to strconv.FormatInt:
// ./in.cue:50:7
}
p2: (struct){
#X: (#struct){
port: (string){ "" }
}
#Y: (_|_){
// [eval] small.p2.#Y: cycle: field port was added after an if clause evaluated it
// [incomplete] small.p2.#Y: undefined field port:
// ./in.cue:50:50
port: (string){ "" }
}
}
Expand Down Expand Up @@ -476,28 +466,28 @@ Result:
port: (string){ "" }
}
}
p5: (_|_){
// [eval]
#X: (_|_){
// [eval] medium.p5.#X: cycle: new field port inserted by if clause that was previously evaluated by another if clause
p5: (struct){
#X: (#struct){
port: (string){ "" }
}
#Y: (_|_){
// [eval] medium.p5.#X: cycle: new field port inserted by if clause that was previously evaluated by another if clause
// [incomplete] medium.p5.#Y: undefined field port:
// ./in.cue:158:56
port: (string){ "" }
}
Y: (struct){
}
}
p6: (_|_){
// [eval]
#X: (_|_){
// [eval] medium.p6.#X: cycle: new field port inserted by if clause that was previously evaluated by another if clause
p6: (struct){
#X: (#struct){
port: (string){ "" }
}
Y: (struct){
}
#Y: (_|_){
// [eval] medium.p6.#X: cycle: new field port inserted by if clause that was previously evaluated by another if clause
// [incomplete] medium.p6.#Y: undefined field port:
// ./in.cue:186:56
port: (string){ "" }
}
}
}
Expand Down
32 changes: 32 additions & 0 deletions cue/testdata/export/issue854.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
-- cue.mod/module.cue --
module: "mod.com"
-- a.cue --
package a

import "mod.com/b"

theb: b.name
-- b/b.cue --
package b

import "mod.com/c"

b: c.c & {
other: "name"
}

name: b.other
-- c/c.cue --
package c
-- out/compile --
--- a.cue
{
theb: 〈import;"mod.com/b"〉.name
}
-- out/eval --
(struct){
theb: (_|_){
// [incomplete] b: undefined field c:
// ./b/b.cue:5:6
}
}
12 changes: 12 additions & 0 deletions internal/core/adt/expr.go
Original file line number Diff line number Diff line change
Expand Up @@ -864,6 +864,12 @@ func (x *SelectorExpr) resolve(c *OpContext, state VertexStatus) *Vertex {
if n == emptyNode {
return n
}
if n.status == Partial {
if b := n.state.incompleteErrors(); b != nil && b.Code < CycleError {
n.BaseValue = b
return n
}
}
return c.lookup(n, x.Src.Sel.Pos(), x.Sel, state)
}

Expand Down Expand Up @@ -891,6 +897,12 @@ func (x *IndexExpr) resolve(ctx *OpContext, state VertexStatus) *Vertex {
if n == emptyNode {
return n
}
if n.status == Partial {
if b := n.state.incompleteErrors(); b != nil && b.Code < CycleError {
n.BaseValue = b
return n
}
}
f := ctx.Label(x.Index, i)
return ctx.lookup(n, x.Src.Index.Pos(), f, state)
}
Expand Down

0 comments on commit 9b263eb

Please sign in to comment.