Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

problem mixing in role with multi builds #5642

Open
p6rt opened this issue Sep 6, 2016 · 2 comments
Open

problem mixing in role with multi builds #5642

p6rt opened this issue Sep 6, 2016 · 2 comments

Comments

@p6rt
Copy link

@p6rt p6rt commented Sep 6, 2016

Migrated from rt.perl.org#129212 (status was 'new')

Searchable as RT129212$

@p6rt

This comment has been minimized.

Copy link
Author

@p6rt p6rt commented Sep 6, 2016

From @MARTIMM

Hi,

I get the following error using version 2016.08.1-66-g1ff1aae built on
MoarVM version 2016.08
implementing Perl 6.c.

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

The code which generates the error (on the line with '$c does RR');

role RR { }

class CC {

  multi submethod BUILD ( Str :$t! ) { }
  multi submethod BUILD ( Int :$i! ) { }
}

my CC $c .= new(​:t<text1>);
$c does RR;

Removing the last line and add a trait 'does' to the class works but is
not what I want.

Greetings,
Marcel

P.s. I've sent this mail before to rakudobug but I did not see it appear
in the list. Sorry for duplication if it did appear somewhere else.

@p6rt

This comment has been minimized.

Copy link
Author

@p6rt p6rt commented Oct 17, 2016

From @MARTIMM

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant
You can’t perform that action at this time.