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 {