On Fri, 02 Dec 2016 13:13:36 -0800, TimTom wrote:
> If you create a typed array attribute for a class and then attempt to
> assign it in the constructor using a hash slip, it fails type
> validation.
> 
> 
> Error message: Type check failed in assignment to @!b; expected Str
> but got Array ($["a", "b", "c"])
> 
> 
> use v6;
> use Test;
> 
> plan 8;
> class A {
>     has @.b;
> }
> class A-validate {
>     has Str @b;
> }
> my $a;
> my @b = <a b c>;
> my %attr = (b => @b);
> lives-ok { $a = A.new(b => @b) }, 'A Created';
> is($a.b, @b, 'A.b valid');
> lives-ok { $a = A.new(|%attr) }, 'A created (slip)';
> is($a.b, @b, 'A.b valid (slip)');
> lives-ok { $a = A-validate.new(b => @b) }, 'A Created (validate)';
> is($a.b, @b, 'A.b valid (validate)');
> lives-ok { $a = A-validate.new(|%attr) }, 'A created (validate,
> slip)'; # fails
> is($a.b, @b, 'A.b valid (validate, slip)');
> 
> 
> Thanks,
> 
> Tim Bollman


This is the crux of the issue:

dd [ | (b => []) ]; #  [:b([])]
dd [ |%(b => []) ]; #  [:b($[])]

A pair (slipped or not), does not itemize the array, so the array's values get 
assigned to the attribute,
but if such a pair has lived in a hash, the array gets itemized, and instead of 
its values being,
passed into the attribute, the array itself--as a single item--gets passed 
instead, which in the
second case presented above, triggers the type mismatch.

I don't know whether that's a bug or whether there's anything we can do about 
this behaviour.


Reply via email to