Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Weird Perl <5.14 error with Union Types #29

Closed
bluefeet opened this issue Jul 16, 2015 · 5 comments
Closed

Weird Perl <5.14 error with Union Types #29

bluefeet opened this issue Jul 16, 2015 · 5 comments

Comments

@bluefeet
Copy link

Travis CI complained to me about all my builds using Perl less than 5.14. It only happens with a very particular combination of union types. I've narrowed it down to a unit test:

: perl -v
This is perl, v5.10.1 (*) built for darwin-2level
#!/usr/bin/env perl

use Test::More;
use Test::Fatal;

use Types::Standard -types;

is(
    exception { InstanceOf[ 'Foo::Bar' ] },
    undef,
    'InstanceOf worked',
);

is(
    exception { InstanceOf[ 'Foo::Bar' ] | Str },
    undef,
    'InstanceOf|Str worked',
);

is(
    exception { InstanceOf[ 'Foo::Bar' ] | HashRef },
    undef,
    'InstanceOf|HashRef worked',
);

is(
    exception { InstanceOf[ 'Foo::Bar' ] | HashRef | Str },
    undef,
    'InstanceOf|HashRef|Str worked',
);

done_testing;
ok 1 - InstanceOf worked
ok 2 - InstanceOf|Str worked
ok 3 - InstanceOf|HashRef worked
not ok 4 - InstanceOf|HashRef|Str worked
#   Failed test 'InstanceOf|HashRef|Str worked'
#   at lib/Starch/Store/DBI.pm line 29.
#          got: 'Can't locate object method "has_coercion" via package "Type::Tiny::_HalfOp" at /Users/aran/perl5/perlbrew/perls/perl-5.10.1/lib/site_perl/5.10.1/Type/Tiny/Union.pm line 55.
# '
#     expected: undef
1..4
# Looks like you failed 1 test of 4.
@bluefeet
Copy link
Author

Note that the error is not produced if I build the type in two steps:

my $type = InstanceOf[ 'Foo::Bar' ] | HashRef;
$type = $type | Str;

@bluefeet
Copy link
Author

Seems I can get around this with minimal change, but its really funky:

((InstanceOf['Foo::Bar']) | HashRef) | Str;

preaction added a commit to preaction/Statocles that referenced this issue Jul 4, 2016
Type::Tiny has a strange bug
(tobyink/p5-type-tiny#29) that only manifests
in certain Perls with a certain pattern of coercion unions. Using grouping
parens to ensure an order to the unions.
@preaction
Copy link

This also happened to me with the union HashRef[ArrayRef[HashRef|Str]|HashRef|Str] which I fixed by doing HashRef[(ArrayRef[HashRef|Str]|HashRef)|Str].

preaction added a commit to preaction/Statocles that referenced this issue Jul 4, 2016
Type::Tiny has a strange bug
(tobyink/p5-type-tiny#29) that only manifests
in certain Perls with a certain pattern of coercion unions. Using grouping
parens to ensure an order to the unions.
@tobyink
Copy link
Owner

tobyink commented Feb 3, 2017

Hmmm. Interesting. There used to be an issue when it came to this:

ArrayRef[Int] | Int

Because older Perls would interpret it as:

ArrayRef(   [Int] | Int   )

@haarg fixed it with the Type::Tiny::_HalfOp class, but it seems that the fix is only partial.

@tobyink
Copy link
Owner

tobyink commented May 18, 2017

@tobyink tobyink closed this as completed May 18, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants