Rakudo: Smartmatch and type checks fail when using MOP-created class as attribute

Created on 13 Jan 2019  路  3Comments  路  Source: rakudo/rakudo

The Problem

my $inner = Metamodel::ClassHOW.new_type(name => 'Inner');
$inner.^compose;

my $outer = Metamodel::ClassHOW.new_type(name => 'Outer');
my $attr = Attribute.new(name => '$!inner', type => $inner, package => $outer, :has_accessor);
$outer.^add_attribute($attr);
$outer.^compose;

say $inner.WHICH eq $outer.^attributes[0].type.WHICH; # True
say $inner === $outer.^attributes[0].type; # True
say $inner ~~ $outer.^attributes[0].type; # False ???

# Type check failed in assignment to $!inner; expected Inner but got Inner.new ???
say $outer.new(inner => $inner.new);

Expected Behavior

For smartmatch to be True and for type check to be passed.

Actual Behavior

Smartmatch fails and type check fails too.

Steps to Reproduce

Run the code above.

Environment

  • Operating system: gnu/linux
  • Compiler version (perl6 -v): This is Rakudo version 2018.12 built on MoarVM version 2018.12
tests needed

Most helpful comment

Fixed with bf0dbbe6d2

All 3 comments

This is because there's a decont missing in the metamodel: if you bind to $attr it works as expected.

Testing a fix now

Fixed with bf0dbbe6d2

Not sure where tests for this should live. In roast? or in rakudo? @jnthn?

Was this page helpful?
0 / 5 - 0 ratings