summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2015-02-24 14:29:47 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2015-02-24 14:29:47 +0900
commit68f60714dc54f0b040243428822213f5f1c0fc2b (patch)
treefd3770e4e8dfb822043b428831d7bb2442972deb
parentd0bc006a739e5ee09ae00b09cda09902b1d71147 (diff)
parent584d6de3c29cb2cfef79ff17ac12f17ace000391 (diff)
downloadmruby-68f60714dc54f0b040243428822213f5f1c0fc2b.tar.gz
mruby-68f60714dc54f0b040243428822213f5f1c0fc2b.zip
Merge pull request #2729 from kou/fix-if-and-no-value-returned-case
Fix a bug that if and no return value case can't return true clause value
-rw-r--r--src/codegen.c9
-rw-r--r--test/t/syntax.rb14
2 files changed, 21 insertions, 2 deletions
diff --git a/src/codegen.c b/src/codegen.c
index 46d457885..1fe26355f 100644
--- a/src/codegen.c
+++ b/src/codegen.c
@@ -1462,8 +1462,13 @@ codegen(codegen_scope *s, node *tree, int val)
genop(s, MKOP_AB(OP_MOVE, cursp(), pos));
push();
}
- else if (pos3) {
- dispatch_linked(s, pos3);
+ else {
+ if (pos3) {
+ dispatch_linked(s, pos3);
+ }
+ if (head) {
+ pop();
+ }
}
}
break;
diff --git a/test/t/syntax.rb b/test/t/syntax.rb
index 7ec6272fe..2621e1b19 100644
--- a/test/t/syntax.rb
+++ b/test/t/syntax.rb
@@ -241,6 +241,20 @@ assert('Return values of case statements') do
assert_equal 1, fb.call
end
+assert('Return values of if and case statements') do
+ true_clause_value =
+ if true
+ 1
+ else
+ case 2
+ when 3
+ end
+ 4
+ end
+
+ assert_equal 1, true_clause_value
+end
+
assert('splat in case statement') do
values = [3,5,1,7,8]
testa = [1,2,7]