tobyink/p5-type-tiny

Legacy `slurpy` handling breaks when using `default` option

Zhtwn opened this issue · 5 comments

Zhtwn commented

slurpy gives a compilation error on its generated code when used with a default option.

Internally, Type::Signature->_coderef_slurpy is not passing an input_var argument to Type::Param->_make_code, and since is_named is not true, $exists_check generates >= 0, which then fails to compile.

test code:

use strict; use warnings;

use Type::Params qw( compile );
use Types::Standard qw( Dict Str slurpy );

my $args_check = compile( slurpy Dict [ foo => Str, bar => Str ], { default => {} } );

output:

perl ./slurpy-test.pl 
Failed to compile source because: syntax error at parameter validation for __ANON__::__ANON__ line 10, near "=  >="
Global symbol "$dtmp" requires explicit package name (did you forget to declare "my $dtmp"?) at parameter validation for __ANON__::__ANON__ line 11.
Global symbol "$dtmp" requires explicit package name (did you forget to declare "my $dtmp"?) at parameter validation for __ANON__::__ANON__ line 11.
Global symbol "$dtmp" requires explicit package name (did you forget to declare "my $dtmp"?) at parameter validation for __ANON__::__ANON__ line 11.
Global symbol "$dtmp" requires explicit package name (did you forget to declare "my $dtmp"?) at parameter validation for __ANON__::__ANON__ line 11.
Global symbol "$dtmp" requires explicit package name (did you forget to declare "my $dtmp"?) at parameter validation for __ANON__::__ANON__ line 11.
Global symbol "$dtmp" requires explicit package name (did you forget to declare "my $dtmp"?) at parameter validation for __ANON__::__ANON__ line 11.
Global symbol "$dtmp" requires explicit package name (did you forget to declare "my $dtmp"?) at parameter validation for __ANON__::__ANON__ line 12.
Global symbol "@out" requires explicit package name (did you forget to declare "my @out"?) at parameter validation for __ANON__::__ANON__ line 13.
Global symbol "$dtmp" requires explicit package name (did you forget to declare "my $dtmp"?) at parameter validation for __ANON__::__ANON__ line 13.
Global symbol "@out" requires explicit package name (did you forget to declare "my @out"?) at parameter validation for __ANON__::__ANON__ line 15.
syntax error at parameter validation for __ANON__::__ANON__ line 17, near "}
}"
parameter validation for __ANON__::__ANON__ has too many errors. at /home/veure/perl5/perlbrew/perls/perl-5.26.3/lib/site_perl/5.26.3/Eval/TypeTiny/CodeAccumulator.pm line 113.

Did slurpy+default ever work in previous versions?

Zhtwn commented

It worked up through 1.014000 -- starts breaking with the Type::Param refactoring in 1.015_001

Zhtwn commented

I'm fine with slurpy+default not working in the long run, since I dont' think that combination was ever explicitly documented.

If it's not allowed, though, then at least it would be nice to catch it earlier and provide a useful error message. :)

I think my instinct would be to do the useful error message thing, as I don't see a lot of utility in supporting it. Slurpies have a kind of "defacto" default of either {} or [] depending on whether they're hashref-typed or arrayref-typed slurpies.

Pushed a fix to master and also the stable-1.016 branch, so it will definitely be included in Type::Tiny 2.x, and should be in the next Type::Tiny 1.x release too, if I release any more of them.