This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Test that entries in %^H are actually independant.
[perl5.git] / t / comp / fold.t
1 #!./perl
2
3 BEGIN {
4     chdir 't';
5     @INC = '../lib';
6     require './test.pl';
7 }
8 use strict;
9 use warnings;
10
11 plan (8);
12
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.
19
20 my $a;
21 $a = eval '$b = 0/0 if 0; 3';
22 is ($a, 3);
23 is ($@, "");
24
25 my $b = 0;
26 $a = eval 'if ($b) {return sqrt -3} 3';
27 is ($a, 3);
28 is ($@, "");
29
30 $a = eval q{
31         $b = eval q{if ($b) {return log 0} 4};
32         is ($b, 4);
33         is ($@, "");
34         5;
35 };
36 is ($a, 5);
37 is ($@, "");
38