5 # Uncomment this for testing, but don't leave it in for "production", as
6 # we've not yet verified that use works.
11 # Historically constant folding was performed by evaluating the ops, and if
12 # they threw an exception compilation failed. This was seen as buggy, because
13 # even illegal constants in unreachable code would cause failure. So now
14 # illegal expressions are reported at runtime, if the expression is reached,
15 # making constant folding consistent with many other languages, and purely an
16 # optimisation rather than a behaviour change.
20 $a = eval '$b = 0/0 if 0; 3';
25 $a = eval 'if ($b) {return sqrt -3} 3';
30 $b = eval q{if ($b) {return log 0} 4};
38 # warn and die hooks should be disabled during constant folding
42 local $SIG{__WARN__} = sub { $c++ };
43 local $SIG{__DIE__} = sub { $c+= 2 };
45 is($c, 0, "premature warn/die: $c");
47 is($c, 1, "missing warn hook");
52 like ($@, qr/division/, "eval caught division");
53 is($c, 2, "missing die hook");