Ticket #1487 (new bug)

Opened 5 years ago

Last modified 4 years ago

Object.find_method fails if PIR 'find_method' vtable override returns null

Reported by: Austin_Hastings Owned by:
Priority: normal Milestone:
Component: core Version: 2.1.0
Severity: medium Keywords:
Cc: Language:
Patch status: Platform:

Description

If I override the 'find_method' vtable for a class, the object.pmc code correctly locates the override and calls it.

However, the same code assumes that any overridden find_method will automatically succeed.

This is inconsistent with the way the default behavior is implemented, which allows a class to return null and then passes on to the next class in the MRO.

(I can see where it might be desirable to "block" method lookup from parent classes. But I think it's more likely that some kind of AUTOLOAD behavior is going to match-these-names or pass to the ancestor. Blocking can be implemented with a sub that dies, or Undef.)

Change History

Changed 5 years ago by Austin_Hastings

nqp-rx test case:

class Test {
	method Xfoo() { say("Xfoo!"); }
	
	method Xify($name) {
		say("Looking for: $name");
		my &sub := $name eq 'foo' ?? Test::Xfoo !! pir::null__P();
	}
}

INIT {
	P6metaclass.get_parrotclass(Test).add_vtable_override('find_method',  Test::Xify);
}

my $obj := Test.new;
$obj.foo;
$obj.HOW;

outputs:

austin@andLinux:~/kakapo$ parrot-nqp test.nqp
Looking for: foo
Xfoo!
Looking for: HOW
Method 'HOW' not found for invocant of class 'Test'
current instr.: '_block11' pc 0 (EVAL_1:6)
called from Sub 'parrot;PCT;HLLCompiler;eval' pc -1 ((unknown file):-1)
called from Sub 'parrot;PCT;HLLCompiler;evalfiles' pc 1303 (compilers/pct/src/PCT/HLLCompiler.pir:707)
called from Sub 'parrot;PCT;HLLCompiler;command_line' pc 1489 (compilers/pct/src/PCT/HLLCompiler.pir:794)
called from Sub 'parrot;NQP;Compiler;main' pc -1 ((unknown file):-1)

Changed 4 years ago by jkeenan

Austin,

For purposes of classification by Component, would you say this is 'nqp' or 'core'?

Thank you very much.

kid51

Changed 4 years ago by pmichaud

It'd have to be a core component issue (specifically with the implementation of the Object PMC).

Pm

Changed 4 years ago by jkeenan

  • component changed from none to core
Note: See TracTickets for help on using tickets.