Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
aghast opened this issue Oct 14, 2009 · 1 comment
Closed

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

aghast opened this issue Oct 14, 2009 · 1 comment

Comments

@aghast
Copy link

aghast commented Oct 14, 2009

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)
$ 

Originally http://trac.parrot.org/parrot/ticket/1108

rurban pushed a commit that referenced this issue Feb 17, 2016
Subs in "built-in PMC" namespaces are treated as PMC methods even
without the :method attribute.

P1=new Integer
P1.foo()

namespace Integer
sub foo

Should error with
  Method 'foo' not found for invocant of class 'Integer'
as it happens with subs of new namespaces.

This allows overriding of builtin methods, but 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.

See GH #304, prev. TT #1108
rurban pushed a commit that referenced this issue Feb 17, 2016
Filter out pure-subs without a method attribute in
Parrot_find_method_direct(). This harmonizes behavior
with user-defined namespaces.

    P1=new Integer
    P1.foo()

    namespace Integer
    sub foo

Does now error with
      Method foo not found for invocant of class Integer
as it happens with subs of new namespaces.
You need to add a :method attribute.

This allows to write user class methods that translate behaviors.
Fixes GH #304, prev. TT #1108
rurban pushed a commit that referenced this issue Feb 17, 2016
Subs in "built-in PMC" namespaces are treated as PMC methods even
without the :method attribute.

P1=new Integer
P1.foo()

namespace Integer
sub foo

Should error with
  Method 'foo' not found for invocant of class 'Integer'
as it happens with subs of new namespaces.

This allows overriding of builtin methods, but 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.

See GH #304, prev. TT #1108
rurban pushed a commit that referenced this issue Feb 17, 2016
Filter out pure-subs without a method attribute in
Parrot_find_method_direct(). This harmonizes behavior
with user-defined namespaces.

    P1=new Integer
    P1.foo()

    namespace Integer
    sub foo

Does now error with
      Method foo not found for invocant of class Integer
as it happens with subs of new namespaces.
You need to add a :method attribute.

This allows to write user class methods that translate behaviors.
Fixes GH #304, prev. TT #1108
@rurban rurban self-assigned this Feb 17, 2016
@rurban rurban added this to the 8.2.0 milestone Feb 17, 2016
rurban pushed a commit that referenced this issue Feb 17, 2016
Subs in "built-in PMC" namespaces are treated as PMC methods even
without the :method attribute.

P1=new Integer
P1.foo()

namespace Integer
sub foo

Should error with
  Method 'foo' not found for invocant of class 'Integer'
as it happens with subs of new namespaces.

This allows overriding of builtin methods, but 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.

See GH #304, prev. TT #1108
rurban pushed a commit that referenced this issue Feb 17, 2016
Filter out pure-subs without a method attribute in
Parrot_find_method_direct(). This harmonizes behavior
with user-defined namespaces.

    P1=new Integer
    P1.foo()

    namespace Integer
    sub foo

Does now error with
      Method foo not found for invocant of class Integer
as it happens with subs of new namespaces.
You need to add a :method attribute.

This allows to write user class methods that translate behaviors.
Fixes GH #304, prev. TT #1108
@rurban rurban closed this as completed Feb 17, 2016
@rurban
Copy link
Member

rurban commented Feb 17, 2016

will be in 8.2.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants