# New Ticket Created by Chris Dolan # Please include the string: [perl #60946] # in the subject line of all future correspondence about this issue. # <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=60946 >
I'm trying to make mock objects in Rakudo, but the 'isa' opcode in PIR seems to ignore my overridden isa() method. The attached code sample demonstrates the problem by: 1) creating a mock class that overrides isa() 2) calling .WHAT to ensure I built the right class 3) calling .isa to show that the mock works 4) invokes the isa opcode in PIR to test that the mock acts like the mocked class Expected result: step 4 returns true, just like step 3 Actual result: step 4 returns false The last step shows that PIR is not fooled by the mock class. I worry that this scenario will cause UNIVERSAL::isa problems all over again. I expect that the same problem will arise from the 'can' opcode.
use v6; class Mock::PGE::Match { method isa($x) { return $x === PGE::Match || self.HOW.isa(self, $x); } # ... } my $m = Mock::PGE::Match.new; say 'What: ' ~ $m.WHAT; say 'm.isa(PGE::Match): ' ~ $m.isa(PGE::Match); # Hack to embed PIR: 'a' ~~ /{{ get_hll_global $P0, ["Mock";"PGE"], "Match" $P1 = $P0."new"() $I0 = isa $P1, ["PGE";"Match"] $S0 = $I0 $S1 = "PIR opcode isa [PGE;Match]: " $S2 = concat $S1, $S0 say $S2 }}/