Ticket #1718 (new bug)

Opened 4 years ago

`NameSpace.add_sub($name, &sub)` does not honor given name for methods

Reported by: Austin Owned by:
Priority: normal Milestone:
Component: none Version: 2.5.0
Severity: medium Keywords:
Cc: Language:
Patch status: Platform:


The namespace.add_sub method accepts a name parameter for the sub object.

When passed a sub object that has the :method flag set, the given name parameter is ignored in favor of the name compiled into the sub object.

(git:master) ~/kakapo$ cat src/Pmc/test.nqp
module A {
	method a() { say("a"); }

class B {
		my $A := pir::get_hll_namespace__pp( pir::split('::', 'A') );
		my &a := pir::inspect__pps($A, 'methods')<a>;
		my $B := pir::get_hll_namespace__pp( pir::split('::', 'B') );
		$B.add_sub('foo', &a);

my $b := B.new;
$b.foo;(git:master) ~/kakapo$ parrot-nqp src/Pmc/test.nqp 
Method 'foo' not found for invocant of class 'B'
current instr.: '_block11' pc 95 (EVAL_1:34)
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 1500 (compilers/pct/src/PCT/HLLCompiler.pir:761)
called from Sub 'parrot;PCT;HLLCompiler;command_line' pc 1702 (compilers/pct/src/PCT/HLLCompiler.pir:869)
called from Sub 'parrot;NQP;Compiler;main' pc 88625 (ext/nqp-rx/src/stage0/NQP-s0.pir:24151)

See in particular the code at  namespace.pmc, line 173 which I think is a bug.

Note: See TracTickets for help on using tickets.