From 0e32d80270cddef44352ace734283065d6e37585 Mon Sep 17 00:00:00 2001 From: crossoverJie Date: Tue, 8 Nov 2022 14:26:23 +0800 Subject: [PATCH] fix #27 --- compiler_test.go | 7 +++++++ resolver/ref_resolver.go | 3 +++ 2 files changed, 10 insertions(+) diff --git a/compiler_test.go b/compiler_test.go index edd60da..3009ed1 100644 --- a/compiler_test.go +++ b/compiler_test.go @@ -458,6 +458,13 @@ println(dumpAST(code)); ` NewCompiler().Compiler(script) } +func TestInit(t *testing.T) { + script := ` +int a; +println(a); +` + NewCompiler().Compiler(script) +} func TestNativeReturn(t *testing.T) { s := testReturn() diff --git a/resolver/ref_resolver.go b/resolver/ref_resolver.go index fb8afab..63e7eea 100644 --- a/resolver/ref_resolver.go +++ b/resolver/ref_resolver.go @@ -121,6 +121,9 @@ func (s *RefResolver) ExitBlockStms(ctx *parser.BlockStmsContext) { if !ok { continue } + if variableDeclaratorContext.VariableInitializer() == nil { + continue + } initializerContext := variableDeclaratorContext.VariableInitializer().(*parser.VariableInitializerContext) exprContext, ok := initializerContext.Expr().(*parser.ExprContext) if !ok {