13 # Historically constant folding was performed by evaluating the ops, and if
14 # they threw an exception compilation failed. This was seen as buggy, because
15 # even illegal constants in unreachable code would cause failure. So now
16 # illegal expressions are reported at runtime, if the expression is reached,
17 # making constant folding consistent with many other languages, and purely an
18 # optimisation rather than a behaviour change.
22 $a = eval '$b = 0/0 if 0; 3';
27 $a = eval 'if ($b) {return sqrt -3} 3';
32 $b = eval q{if ($b) {return log 0} 4};
40 # warn and die hooks should be disabled during constant folding
44 local $SIG{__WARN__} = sub { $c++ };
45 local $SIG{__DIE__} = sub { $c+= 2 };
47 is($c, 0, "premature warn/die: $c");
49 is($c, 1, "missing warn hook");
54 like ($@, qr/division/, "eval caught division");
55 is($c, 2, "missing die hook");