petdance/scratch — Issue #141: Subs in "built-in PMC" namespaces are treated as PMC methods
Author: petdance
Created: 2011-11-01 05:29:59+00:00
State: open
Labels: bug, Pri-normal, Sev-medium

A sub that is declared in a namespace that matches the name of a builtin PMC is automatically dispatched as a method:
{{{
$ cat x.pir
.sub main
$P0 = new 'Integer'
$P0.'foo'()
.end

.namespace ['Integer']

.sub 'foo'
say 'foo'
.end

$ ./parrot x.pir
foo
$
}}}

While this *does* make it possible to override builtin methods,
it also makes it impossible to write "class methods" that translate behaviors, since the presence or absence of the `:method` attribute on the sub is ignored.

This behavior does not happen with non-builtin classes:
{{{
$ cat y.pir
.sub main
$P1 = newclass ['XYZ']
$P0 = new ['XYZ']
$P0.'foo'()
.end

.namespace ['XYZ']

.sub 'foo'
say 'foo'
.end

$ ./parrot y.pir
Method 'foo' not found for invocant of class 'XYZ'
current instr.: 'main' pc 11 (y.pir:4)
$
}}}
Trac ID #1108