Commit 584d6de3 authored by Kouhei Sutou's avatar Kouhei Sutou

Fix a bug that if and no return value case can't return true clause value

Here is a script that reproduce this problem:

     x = if true
           1
         else
           case 2
           when 3
           end
           4
         end
     p x # => nil # 1 is expected
parent 44d8a40b
......@@ -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;
......
......@@ -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]
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment