From b73c26a3264dd3eb311f3b3974e742e98a1d4296 Mon Sep 17 00:00:00 2001 From: st0012 Date: Sun, 7 Jan 2018 14:23:05 +0800 Subject: [PATCH 1/2] Prevent panic when compileing empty expression. --- compiler/bytecode/expression_generation.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/compiler/bytecode/expression_generation.go b/compiler/bytecode/expression_generation.go index bfee13de0..ddf51c51f 100644 --- a/compiler/bytecode/expression_generation.go +++ b/compiler/bytecode/expression_generation.go @@ -6,6 +6,10 @@ import ( ) func (g *Generator) compileExpression(is *InstructionSet, exp ast.Expression, scope *scope, table *localTable) { + if exp == nil { + return + } + sourceLine := exp.Line() switch exp := exp.(type) { case *ast.Constant: From 567df5afef8a47eb331f1509e170d557fc56a7cf Mon Sep 17 00:00:00 2001 From: st0012 Date: Sun, 7 Jan 2018 14:45:50 +0800 Subject: [PATCH 2/2] Fix eval empty file cause panic issue. --- compiler/bytecode/statement_generation.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/compiler/bytecode/statement_generation.go b/compiler/bytecode/statement_generation.go index 6f36e1848..66e267c56 100644 --- a/compiler/bytecode/statement_generation.go +++ b/compiler/bytecode/statement_generation.go @@ -22,6 +22,11 @@ func (g *Generator) compileStatements(stmts []ast.Statement, scope *scope, table g.compileStatement(is, statement, scope, table) } + // empty input so no statement is given + if len(stmts) == 0 { + return + } + g.endInstructions(is, stmts[len(stmts)-1].Line()) g.instructionSets = append(g.instructionSets, is) }