#1736: NQP-rx generates wrong multi signature for :named params
--------------------+-------------------------------------------------------
 Reporter:  Austin  |       Owner:  pmichaud
     Type:  bug     |      Status:  new     
 Priority:  normal  |   Milestone:          
Component:  nqp     |     Version:  2.6.0   
 Severity:  medium  |    Keywords:          
     Lang:          |       Patch:          
 Platform:          |  
--------------------+-------------------------------------------------------
 Declaring a method as 'multi' causes the parameter list to be processed
 for a multi signature.

 Named parameters, declared like `multi method foo($x, :$named)` are
 included in this processing, such that method foo would be declared in PIR
 as :multi with a signature of [_, _, _].

 But these parameters do not appear to be part of the multidispatch
 mechanism, so calls to those methods with 1 or 2 args (plus self, of
 course) fail with a dispatch error.

 I believe the solution is to check the parameter type, and omit multi
 signatures for non-positionals. (I am not sure what, if any, behavior
 exists with slurpy params, named or positional.)

 {{{
 $ cat test.nqp
 class Foo {
 }

 class Foo::Bar is Foo {
         our multi method aardvark( $s ) {
                 say("aardvark: Nothing special");
         }

         our multi method aardvark( String $s ) {
                 say("aardvark: String");
         }

         our multi method aardvark( Foo $s ) {
                 say("aardvark: Foo");
         }

         our multi method append( $s, :$dynamic? ) {
                 say("append: Nothing special");
         }

         our multi method append( String $s, :$dynamic? ) {
                 say("append: String");
         }

         our multi method append( Foo $s, :$dynamic? ) {
                 say("append: Foo");
         }
 }

 class Foo::Baz is Foo::Bar {
 }

 my $x := Foo::Baz.new;

 $x.aardvark("string");
 $x.aardvark($x);
 $x.aardvark(1);

 $x.append("string");
 $x.append($x);
 $x.append(1);

 aus...@lt-austin /d/My Documents/Sources/kakapo (master)
 $ parrot-nqp test.nqp
 aardvark: String
 aardvark: Foo
 aardvark: Nothing special
 No applicable candidates found to dispatch to for 'append'
 current instr.: '_block11' pc 143 (EVAL_1:47)
 called from Sub 'parrot;HLL;Compiler;_block470' pc 24271 (ext/nqp-
 rx/src/stage0/HLL-s0.pir:7848)
 called from Sub 'parrot;HLL;Compiler;eval' pc 24151 (ext/nqp-
 rx/src/stage0/HLL-s0.pir:0)
 called from Sub 'parrot;PCT;HLLCompiler;evalfiles' pc 1510
 (compilers/pct/src/PCT/HLLCompiler.pir:764)
 called from Sub 'parrot;PCT;HLLCompiler;command_line' pc 1712
 (compilers/pct/src/PCT/HLLCompiler.pir:872)
 called from Sub 'parrot;NQP;Compiler;main' pc 88661 (ext/nqp-
 rx/src/stage0/NQP-s0.pir:24164)
 }}}

-- 
Ticket URL: <https://trac.parrot.org/parrot/ticket/1736>
Parrot <https://trac.parrot.org/parrot/>
Parrot Development
_______________________________________________
parrot-tickets mailing list
[email protected]
http://lists.parrot.org/mailman/listinfo/parrot-tickets

Reply via email to