Skip to content

Commit

Permalink
Return values at the end of a script, without semicolon, aren't returned
Browse files Browse the repository at this point in the history
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 ec94f32 commit 5ff9a53
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 1 deletion.
2 changes: 2 additions & 0 deletions evaluator/evaluator_test.go
Expand Up @@ -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},
Expand Down
2 changes: 1 addition & 1 deletion parser/parser.go
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions parser/parser_test.go
Expand Up @@ -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"},
Expand Down

0 comments on commit 5ff9a53

Please sign in to comment.