From 5c31552b05c78575f45876ab07abd73c1d96bf27 Mon Sep 17 00:00:00 2001 From: ltzmaxwell Date: Tue, 10 Dec 2024 21:50:53 +0800 Subject: [PATCH] fix(gnovm): make static-analysis handle block stmt (#3313) as the title says. it give incorrect error before fix: ``` unexpected panic: main/files/block0.gno:3:1: [function "foo" does not terminate] ``` --- gnovm/pkg/gnolang/static_analysis.go | 2 ++ gnovm/tests/files/block0.gno | 14 ++++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 gnovm/tests/files/block0.gno diff --git a/gnovm/pkg/gnolang/static_analysis.go b/gnovm/pkg/gnolang/static_analysis.go index 311a0d42feb..7094ccbb4c8 100644 --- a/gnovm/pkg/gnolang/static_analysis.go +++ b/gnovm/pkg/gnolang/static_analysis.go @@ -108,6 +108,8 @@ func (s *staticAnalysis) staticAnalysisExpr(expr Expr) bool { // indicating whether a statement is terminating or not func (s *staticAnalysis) staticAnalysisStmt(stmt Stmt) bool { switch n := stmt.(type) { + case *BlockStmt: + return s.staticAnalysisBlockStmt(n.Body) case *BranchStmt: switch n.Op { case BREAK: diff --git a/gnovm/tests/files/block0.gno b/gnovm/tests/files/block0.gno new file mode 100644 index 00000000000..b6d554ce500 --- /dev/null +++ b/gnovm/tests/files/block0.gno @@ -0,0 +1,14 @@ +package main + +func foo() int { + { + return 1 + } +} + +func main() { + println(foo()) +} + +// Output: +// 1