Skip to content

Commit

Permalink
Merge pull request #187 from Syuparn/fix-evaluator
Browse files Browse the repository at this point in the history
evaluator: fix jumpifstmt return wrapping
  • Loading branch information
Syuparn authored Aug 21, 2021
2 parents e074f85 + ef05321 commit 4e5d20b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 2 additions & 2 deletions evaluator/eval_jumpifstmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func evalJumpIfReturn(
if err, ok := ret.(*object.PanErr); ok {
return appendStackTrace(err, node.Source())
}
return &object.ReturnObj{PanObject: ret}
return ret
}

func evalJumpIfDefer(
Expand Down Expand Up @@ -111,5 +111,5 @@ func evalJumpIfRaise(
return appendStackTrace(&err, node.Source())
}

return &object.ReturnObj{PanObject: ret}
return ret
}
9 changes: 9 additions & 0 deletions evaluator/eval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2681,6 +2681,15 @@ func TestEvalJumpIfStmt(t *testing.T) {
`{|i| raise Err.new("new error") if false; i}(2)`,
object.NewPanInt(2),
},
// recursion
{
`fact := {|n| return 1 if n == 0; n * fact(n - 1)}; fact(4)`,
object.NewPanInt(24),
},
{
`fact := {|n| raise 1 if n == 0; n * fact(n - 1)}; fact(4)`,
object.NewPanInt(24),
},
}
for _, tt := range tests {
actual := testEval(t, tt.input)
Expand Down

0 comments on commit 4e5d20b

Please sign in to comment.