Ticket #1108 (new bug)

Opened 5 years ago

Subs in "built-in PMC" namespaces are treated as PMC methods

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

Description

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)
$ 
Note: See TracTickets for help on using tickets.