1*0Sstevel@tonic-gate#!./perl 2*0Sstevel@tonic-gate 3*0Sstevel@tonic-gateprint "1..12\n"; 4*0Sstevel@tonic-gatesub context { 5*0Sstevel@tonic-gate my ( $cona, $testnum ) = @_; 6*0Sstevel@tonic-gate my $conb = (defined wantarray) ? ( wantarray ? 'A' : 'S' ) : 'V'; 7*0Sstevel@tonic-gate unless ( $cona eq $conb ) { 8*0Sstevel@tonic-gate print "# Context $conb should be $cona\nnot "; 9*0Sstevel@tonic-gate } 10*0Sstevel@tonic-gate print "ok $testnum\n"; 11*0Sstevel@tonic-gate} 12*0Sstevel@tonic-gate 13*0Sstevel@tonic-gatecontext('V',1); 14*0Sstevel@tonic-gate$a = context('S',2); 15*0Sstevel@tonic-gate@a = context('A',3); 16*0Sstevel@tonic-gatescalar context('S',4); 17*0Sstevel@tonic-gate$a = scalar context('S',5); 18*0Sstevel@tonic-gate($a) = context('A',6); 19*0Sstevel@tonic-gate($a) = scalar context('S',7); 20*0Sstevel@tonic-gate 21*0Sstevel@tonic-gate{ 22*0Sstevel@tonic-gate # [ID 20020626.011] incorrect wantarray optimisation 23*0Sstevel@tonic-gate sub simple { wantarray ? 1 : 2 } 24*0Sstevel@tonic-gate sub inline { 25*0Sstevel@tonic-gate my $a = wantarray ? simple() : simple(); 26*0Sstevel@tonic-gate $a; 27*0Sstevel@tonic-gate } 28*0Sstevel@tonic-gate my @b = inline(); 29*0Sstevel@tonic-gate my $c = inline(); 30*0Sstevel@tonic-gate print +(@b == 1 && "@b" eq "2") ? "ok 8\n" : "not ok 8\t# <@b>\n"; 31*0Sstevel@tonic-gate print +($c == 2) ? "ok 9\n" : "not ok 9\t# <$c>\n"; 32*0Sstevel@tonic-gate} 33*0Sstevel@tonic-gate 34*0Sstevel@tonic-gatemy $qcontext = q{ 35*0Sstevel@tonic-gate $q = (defined wantarray) ? ( wantarray ? 'A' : 'S' ) : 'V'; 36*0Sstevel@tonic-gate}; 37*0Sstevel@tonic-gateeval $qcontext; 38*0Sstevel@tonic-gateprint $q eq 'V' ? "ok 10\n" : "not ok 10\n"; 39*0Sstevel@tonic-gate$a = eval $qcontext; 40*0Sstevel@tonic-gateprint $q eq 'S' ? "ok 11\n" : "not ok 11\n"; 41*0Sstevel@tonic-gate@a = eval $qcontext; 42*0Sstevel@tonic-gateprint $q eq 'A' ? "ok 12\n" : "not ok 12\n"; 43*0Sstevel@tonic-gate 44*0Sstevel@tonic-gate1; 45