You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hey,
I was trying to convert ast.Comprehension.Value (of type ast.Expr) into cue.Value. I tried the method (*Context) BuildExpr. Now, this works fine for case
body:{
a?: int
b?: int
if b != null {
a !: int
}
}
However, for nested if-else such as
body:{
a?: int
b?: int
if b != null {
if b < 10 {
a !: int
}
}
}
it gives error: -
6:4
reference "b" set to unknown node in AST; this can result from incorrect API usage or a compiler bug
7:5
{
a!: int
}
Now, my speculation is when I try to convert the outer if's ast.Node to cue.Value the BuildExpr tries to find the reference of b used in inner if condition which is not present in the scope of outer if.
I tried the Scope buildOption, but couldn't resolve the reference (maybe I am not using it correctly). I tried making a small change to inner if but nothing changed. It now gives error reference for 'body' not found.
body:{
a?: int
b?: int
if b != null {
if body.b < 10 {
a !: int
}
}
}
Go Code : -
var arr []ast.Comprehension
for _, ele := range arr {
fmt.Println(ele.Clauses[0].Pos())
cueVal := ctx.BuildExpr(ele.Value, []cue.BuildOption{
cue.Scope(insts),
}...)
if (cueVal.Err() != nil){
fmt.Println(cueVal.Err())
continue
}
fmt.Println(cueVal)
}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hey,
I was trying to convert
ast.Comprehension.Value (of type ast.Expr)
intocue.Value
. I tried the method(*Context) BuildExpr
. Now, this works fine for caseHowever, for nested if-else such as
it gives error: -
Now, my speculation is when I try to convert the
outer if's ast.Node
tocue.Value
theBuildExpr
tries to find the reference ofb
used in innerif
condition which is not present in the scope ofouter if
.I tried the
Scope
buildOption, but couldn't resolve the reference (maybe I am not using it correctly). I tried making a small change to inner if but nothing changed. It now gives errorreference for 'body' not found.
Go Code : -
Beta Was this translation helpful? Give feedback.
All reactions