Skip to content

Commit

Permalink
save
Browse files Browse the repository at this point in the history
  • Loading branch information
petar-dambovaliev committed Jan 16, 2025
1 parent f513f14 commit 9152ea8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
1 change: 1 addition & 0 deletions gnovm/pkg/gnolang/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ const (
ATTR_LOOP_USES GnoAttribute = "ATTR_LOOP_USES" // []Name loop defines actually used.
ATTR_SHIFT_RHS GnoAttribute = "ATTR_SHIFT_RHS"
ATTR_LAST_BLOCK_STMT GnoAttribute = "ATTR_LAST_BLOCK_STMT"
ATTR_GLOBAL GnoAttribute = "ATTR_GLOBAL"
)

type Attributes struct {
Expand Down
22 changes: 18 additions & 4 deletions gnovm/pkg/gnolang/preprocess.go
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,17 @@ func preprocess1(store Store, ctx BlockNode, n Node) Node {
if cd, ok := d.(*ValueDecl); ok {
checkValDefineMismatch(cd)
}

isGlobal := true

for i := len(ns) - 1; i > 0; i-- {
if _, ok := ns[i].(*FuncDecl); ok {
isGlobal = false
}
}

d.SetAttribute(ATTR_GLOBAL, isGlobal)

// recursively predefine dependencies.
d2, ppd := predefineNow(store, last, d)
if ppd {
Expand Down Expand Up @@ -4364,13 +4375,16 @@ func findUndefined2(store Store, last BlockNode, x Expr, t Type, skipPredefined
ct.String()))
}
case *FuncLitExpr:
for _, stmt := range cx.Body {
un = findUndefinedStmt(store, cx, stmt, t)
if cx.GetAttribute(ATTR_GLOBAL) == true {
for _, stmt := range cx.Body {
un = findUndefinedStmt(store, cx, stmt, t)

if un != "" {
return
if un != "" {
return
}
}
}

return findUndefined2(store, last, &cx.Type, nil, skipPredefined)
case *FieldTypeExpr:
return findUndefined2(store, last, cx.Type, nil, skipPredefined)
Expand Down

0 comments on commit 9152ea8

Please sign in to comment.