tobyink / p5-type-tiny

Perl 5 distribution Type-Tiny; see homepage for downloads and documentation.
https://typetiny.toby.ink/
54 stars 48 forks source link

empty string expected when tying an undefined variable to a Str type constraint #152

Closed XSven closed 1 month ago

XSven commented 10 months ago

I am expecting both tests to pass. Unfortunately the empty string test is failing.

use Test::More tests => 2;

use Type::Tie       qw( ttie );
use Types::Standard qw( Num Str );

ttie my @n, Num;
is_deeply \@n, [], 'empty list';

ttie my $s, Str;
is $s, '', 'empty string';

From my perspective, a proper initial value ("zero" value in golang terminology) should be assigned to an undefined scalar variable. The value has to honour the type constraint. Maybe Type::Tie::SCALAR::_DEFAULT has to depend on the type constraint.

tobyink commented 1 month ago

This will be fixed in the next release.