Ticket #1736 (closed bug: fixed)

Opened 4 years ago

Last modified 4 years ago

NQP-rx generates wrong multi signature for :named params

Reported by: Austin Owned by: pmichaud
Priority: normal Milestone:
Component: nqp Version: 2.6.0
Severity: medium Keywords:
Cc: Language:
Patch status: Platform:

Description

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);

Austin@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)

Change History

Changed 4 years ago by Austin

A multi method with slurpy positional and named parameters has _ inserted for both. So it seems like slurpy checking is probably also needed.

Changed 4 years ago by bacek

  • status changed from new to closed
  • resolution set to fixed

Fixed in 83747bda. Please review if it expected behaviour.

Please reopend ticket with more examples if I broke something.

-- Bacek

Note: See TracTickets for help on using tickets.