Type constraints in models are ignored on assignment
patrickbkr opened this issue · comments
use Red:api<2>;
model X is rw {
has Int $.foo is column{:nullable}
}
my X $x .= new;
$x.foo = "Hi";
say $x.foo ~ " " ~ $x.foo.^name;
The above prints "Hi Str".
While the corresponding
class X is rw {
has Int $.foo
}
my X $x .= new;
$x.foo = "Hi";
say $x.foo ~ " " ~ $x.foo.^name;
prints "Type check failed in assignment to $!foo; expected Int but got Str ("Hi")
in block at -e line 1"
Thank you for your issue! I'll take a look as soon as possible
Hi @patrickbkr thank you again! Could you confirm that was fixed, please?
The error message is a little bit different, but now errors when using model
as well.
With class
:
Type check failed in assignment to $!foo; expected Int but got Str ("Hi")
in block <unit> at test.raku line 5
With model
:
Type check failed in assignment; expected Int but got Str ("Hi")
in method <anon> at /home/patrick/repos/RakuCIBot/../Red/lib/MetamodelX/Red/Dirtable.pm6 (MetamodelX::Red::Dirtable) line 161
in block <unit> at test.raku line 6
could probably get the same backtrace by applying is hidden-from-backtrace
however that may hide other problems,
I've added the is hidden-from-backtrace
@jonathanstowe has suggested and also added the symbol to the exception to make the errors message closer to the original (I think now it's exactly equal). @patrickbkr is that working for you?
I tried it and it looks perfect. Thanks!