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
This commit is contained in:
Kouhei Sutou
2015-02-24 00:21:49 +09:00
parent 68f60714dc
commit 4b4ddd5a28
2 changed files with 11 additions and 1 deletions
+1 -1
View File
@@ -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();
}
+10
View File
@@ -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]