Skip to content
Permalink
Browse files

Return values at the end of a script, without semicolon, aren't returned

This fixes a small bug in the code that interprets returns without semicolons,
introduced in `1.6.0`.
  • Loading branch information...
odino committed Aug 5, 2019
1 parent f5a044e commit cdf9604dfece2c2aaadd067b5ef906a6cb29bc22
Showing with 4 additions and 1 deletion.
  1. +2 −0 evaluator/evaluator_test.go
  2. +1 −1 parser/parser.go
  3. +1 −0 parser/parser_test.go
@@ -459,7 +459,9 @@ func TestReturnStatements(t *testing.T) {
}{
{"return;", nil},
{"return", nil},
{"return 1", 1},
{"fn = f() { return }; fn()", nil},
{"fn = f() { return 1 }; fn()", 1},
{"return 10;", 10},
{"return 10; 9;", 10},
{"return 2 * 5; 9;", 10},
@@ -335,7 +335,7 @@ func (p *Parser) parseReturnStatement() *ast.ReturnStatement {
// return;
if p.curTokenIs(token.SEMICOLON) {
stmt.ReturnValue = &ast.NullLiteral{Token: p.curToken}
} else if p.peekTokenIs(token.RBRACE) || p.peekTokenIs(token.EOF) {
} else if p.curTokenIs(token.RBRACE) || p.curTokenIs(token.EOF) {
// return
stmt.ReturnValue = &ast.NullLiteral{Token: returnToken}
} else {
@@ -58,6 +58,7 @@ func TestReturnStatements(t *testing.T) {
}{
{"return", nil},
{"return;", nil},
{"return 5", 5},
{"return 5;", 5},
{"return true;", true},
{"return foobar;", "foobar"},

0 comments on commit cdf9604

Please sign in to comment.
You can’t perform that action at this time.