Skip to content

Commit

Permalink
[test] sub dispatch with builtin namespace
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Reini Urban committed Feb 17, 2016
1 parent 9430d61 commit 8ae5ffe
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions t/pmc/namespace-subs.t
@@ -1,5 +1,5 @@
#!./parrot
# Copyright (C) 2010, Parrot Foundation.
# Copyright (C) 2010-2016, Parrot Foundation.

=head1 NAME

Expand All @@ -20,12 +20,13 @@ specified behavior for :method, :vtable, :nsentry, and :anon.

.sub 'main' :main
.include 'test_more.pir'
plan(17)
plan(18)
anon_sub_and_method()
anon_vtable()
store_method()
store_nsentry()
store_multisub()
method_with_builtin()
.end


Expand Down Expand Up @@ -116,6 +117,21 @@ specified behavior for :method, :vtable, :nsentry, and :anon.

.end

# Subs in "built-in PMC" namespaces should not be treated as PMC methods
# unless they have the :method attribute

.sub method_with_builtin
$P1 = new 'Integer'
push_eh method_not_found
$S1 = $P1.'foo'()
todo(0, "sub of builtin pmc treated as method. GH #304")
pop_eh
goto failed
method_not_found:
ok(1, "sub of builtin pmc. GH #304s")
failed:
.end

.namespace ['AnonTest']
.sub 'anonsub' :anon
.return(14)
Expand Down Expand Up @@ -157,6 +173,10 @@ specified behavior for :method, :vtable, :nsentry, and :anon.
.return("called num variant")
.end

.namespace ['Integer']
.sub 'foo'
.return(1)
.end

# Local Variables:
# mode: pir
Expand Down

0 comments on commit 8ae5ffe

Please sign in to comment.