From 9152ea877aa878829c6dc519e764818487e47637 Mon Sep 17 00:00:00 2001 From: Petar Dambovaliev Date: Thu, 16 Jan 2025 16:25:50 +0100 Subject: [PATCH] save --- gnovm/pkg/gnolang/nodes.go | 1 + gnovm/pkg/gnolang/preprocess.go | 22 ++++++++++++++++++---- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/gnovm/pkg/gnolang/nodes.go b/gnovm/pkg/gnolang/nodes.go index b85d1ac7026..0f1f4388623 100644 --- a/gnovm/pkg/gnolang/nodes.go +++ b/gnovm/pkg/gnolang/nodes.go @@ -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 { diff --git a/gnovm/pkg/gnolang/preprocess.go b/gnovm/pkg/gnolang/preprocess.go index 0f62665a09f..8d9015de037 100644 --- a/gnovm/pkg/gnolang/preprocess.go +++ b/gnovm/pkg/gnolang/preprocess.go @@ -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 { @@ -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)