Hi,

Revisiting the problem using rakudo version 2016.10-31-g6ed3a68 built on MoarVM version 2016.10 implementing Perl 6.c.

The issue still exist but tried to rewrite things to get it working


role RR1 {
  submethod BUILD ( Int :$i ) { say $i // 'No i'; }
}

role RR2 {
  submethod BUILD ( Str :$t ) { say $t // 'No t'; }
}

class CC {
  multi submethod BUILD ( Int :$i! ) {
    say "Integer $i";
    self does RR1;
  }

  multi submethod BUILD ( Str :$t! ) {
    say "String $t";
    self does RR2;
  }
}

for <t i> {
  when 'i' {
    my CC $c .= new(:i(10));
  }

  when 't' {
    my CC $c .= new(:t<text1>);
  }
}


This version works, but output is

String text1
No t
Integer 10
No i

This means that the BUILD submethods in the roles are called without arguments, while the signatures must be the same from the use in the class. The required '!' must be removed(no arguments delivered).

The roles, if needed, must be initialized with a later call, e.g. via method init(Int $i) to get the values in the role.

Removing the submethods BUILD from the roles will trigger again the exception;

Cannot resolve caller BUILD(CC+{RR1}: ); none of these signatures match:
    (CC $: Str :$t!, *%_)
    (CC $: Int :$i!, *%_)
  in block  at Does.pl6 line 23
  in block <unit> at Does.pl6 line 20


Greetings
Marcel

Reply via email to