diff options
| author | Kouhei Sutou <[email protected]> | 2015-02-24 00:21:49 +0900 |
|---|---|---|
| committer | Kouhei Sutou <[email protected]> | 2015-02-24 20:53:12 +0900 |
| commit | 4b4ddd5a28b74ce6add69667d542aaa3f3dfa38c (patch) | |
| tree | 3f7b782081a8ace63a854b4d68485d31ca439130 | |
| parent | 68f60714dc54f0b040243428822213f5f1c0fc2b (diff) | |
| download | mruby-4b4ddd5a28b74ce6add69667d542aaa3f3dfa38c.tar.gz mruby-4b4ddd5a28b74ce6add69667d542aaa3f3dfa38c.zip | |
Fix a bug that no expression case doesn't return valid value
Here is a script that reproduces this problem:
x = case
when true; 1
end
p x # => main # 1 is expected
| -rw-r--r-- | src/codegen.c | 2 | ||||
| -rw-r--r-- | test/t/syntax.rb | 10 |
2 files changed, 11 insertions, 1 deletions
diff --git a/src/codegen.c b/src/codegen.c index 1fe26355f..c8f964f56 100644 --- a/src/codegen.c +++ b/src/codegen.c @@ -1458,7 +1458,7 @@ codegen(codegen_scope *s, node *tree, int val) int pos = cursp(); genop(s, MKOP_A(OP_LOADNIL, cursp())); if (pos3) dispatch_linked(s, pos3); - pop(); + if (head) pop(); genop(s, MKOP_AB(OP_MOVE, cursp(), pos)); push(); } diff --git a/test/t/syntax.rb b/test/t/syntax.rb index 2621e1b19..d21748de1 100644 --- a/test/t/syntax.rb +++ b/test/t/syntax.rb @@ -255,6 +255,16 @@ assert('Return values of if and case statements') do assert_equal 1, true_clause_value end +assert('Return values of no expression case statement') do + when_value = + case + when true + 1 + end + + assert_equal 1, when_value +end + assert('splat in case statement') do values = [3,5,1,7,8] testa = [1,2,7] |
