p5-type-tiny icon indicating copy to clipboard operation
p5-type-tiny copied to clipboard

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

Open XSven opened this issue 1 year ago • 0 comments

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.

XSven avatar Dec 28 '23 13:12 XSven