Skip to content

Commit

Permalink
Merge pull request mruby#2729 from kou/fix-if-and-no-value-returned-case
Browse files Browse the repository at this point in the history
Fix a bug that if and no return value case can't return true clause value
  • Loading branch information
matz committed Feb 24, 2015
2 parents d0bc006 + 584d6de commit 68f6071
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/codegen.c
Expand Up @@ -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;
Expand Down
14 changes: 14 additions & 0 deletions test/t/syntax.rb
Expand Up @@ -241,6 +241,20 @@ def fb
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]
Expand Down

0 comments on commit 68f6071

Please sign in to comment.