Skip to content

Commit

Permalink
Fix if bug.
Browse files Browse the repository at this point in the history
Add a test 86 for more tricky if cases.
  • Loading branch information
pmurias committed Jan 24, 2015
1 parent 5dd0a3e commit 45cbf79
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/vm/js/QAST/Compiler.nqp
Original file line number Diff line number Diff line change
Expand Up @@ -663,20 +663,21 @@ class QAST::OperationsJS {

my $boolifed_cond := $comp.coerce($cond, $T_BOOL);

my $cond_without_sideeffects := Chunk.new($cond.type, $cond.expr, []);

if $node.op eq 'if' {
$then := $comp.as_js($node[1], :$want);

if $operands == 3 {
$else := $comp.as_js($node[2], :$want);
} else {
$else := $comp.coerce($cond, $want);
$else := $comp.coerce($cond_without_sideeffects, $want);
}
} else {
if $operands == 3 {
$then := $comp.as_js($node[2], :$want);
} else {
$then := $comp.coerce($cond, $want);
$then := $comp.coerce($cond_without_sideeffects, $want);
}
$else := $comp.as_js($node[1], :$want);
}
Expand Down
2 changes: 1 addition & 1 deletion src/vm/js/bin/run_tests
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash
# 19 and 30 where moved out as they were parrot specific, 52,54 is missing, we can't pass 49 till we are bootstraped
prove -e './nqp-js' t/nqp/{01..18}* t/nqp/{20,21,22,23,25,26,27,28,33,35,36,37,38,39,40,41,42,46,48,53,57,58,59,63,65,68,69,70,75,76,81,83}* t/js/getcomp-js.t
prove -e './nqp-js' t/nqp/{01..18}* t/nqp/{20,21,22,23,25,26,27,28,33,35,36,37,38,39,40,41,42,46,48,53,57,58,59,63,65,68,69,70,75,76,81,83, 86}* t/js/getcomp-js.t
4 changes: 4 additions & 0 deletions t/nqp/86-more-if-tests.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
plan(1);
my $foo := 0;
1 if $foo++;
ok($foo == 1, "the if condition is evaluated once");

0 comments on commit 45cbf79

Please sign in to comment.