Subject: | interesting parsing differences with parameterized types on 5.10 |
Travis found this bug for me on perls 5.10 and 5.12 (not 5.14). I ran it through Deparse as well to see the difference (note that the "bar" key in the Dict has been lost on earlier perls):
on 5.31.10:
perl -MTypes::Standard=Dict,InstanceOf,HashRef,Str -wle'my $isa = Dict[ foo => InstanceOf["Path::Tiny"]|HashRef, bar => Str ]; print $isa'
Dict[bar=>Str,foo=>InstanceOf["Path::Tiny"]|HashRef]
perl -MO=Deparse,-p -MTypes::Standard=Dict,InstanceOf,HashRef,Str -wle'my $isa = Dict[ foo => InstanceOf["Path::Tiny"]|HashRef, bar => Str ]; print $isa'
BEGIN { $^W = 1; }
BEGIN { $/ = "\n"; $\ = "\n"; }
use Types::Standard (split(/,/, 'Dict,InstanceOf,HashRef,Str', 0));
(my $isa = &Dict(['foo', (&InstanceOf(['Path::Tiny']) | &HashRef()), 'bar', &Str()]));
print($isa);
-e syntax OK
on 5.10.1:
perl -MTypes::Standard=Dict,InstanceOf,HashRef,Str -wle'my $isa = Dict[ foo => InstanceOf["Path::Tiny"]|HashRef, bar => Str ]; print $isa'
Dict[foo=>InstanceOf["Path::Tiny"]|HashRef]
perl -MO=Deparse,-p -MTypes::Standard=Dict,InstanceOf,HashRef,Str -wle'my $isa = Dict[ foo => InstanceOf["Path::Tiny"]|HashRef, bar => Str ]; print $isa'
BEGIN { $^W = 1; }
BEGIN { $/ = "\n"; $\ = "\n"; }
use Types::Standard (split(/,/, 'Dict,InstanceOf,HashRef,Str', 0));
(my $isa = Dict(['foo', InstanceOf((['Path::Tiny'] | HashRef()), 'bar', Str)]));
print($isa);
-e syntax OK
The extra key is not lost if parentheses are added, like so:
perl -MTypes::Standard=Dict,InstanceOf,HashRef,Str -wle'my $isa = Dict[ foo => (InstanceOf["Path::Tiny"]|HashRef), bar => Str ]; print $isa'
Dict[bar=>Str,foo=>InstanceOf["Path::Tiny"]|HashRef]