#1492: Get_class <namespace> confuses NSes that have same final name.
-----------------------------+----------------------------------------------
Reporter: Austin_Hastings | Owner:
Type: bug | Status: new
Priority: normal | Milestone:
Component: core | Version: 2.1.0
Severity: high | Keywords: namespace, class, get_class
Lang: | Patch:
Platform: |
-----------------------------+----------------------------------------------
Having already created a class "Matcher", I was trying in NQP to create a
related class Mimus::CallSignature::Matcher. (Note the last name.)
Far too many hours later, it appears that the get_class op on a namespace
apparently returns invalid results when the namespace shares a last name
with an already-extant class.
This code, inspired by the `get_parrotclass` method in P6object.pir, looks
up (and tries to create, if needed) two classes with different namespace
paths but the same class name (last name in the nsp), one called P and the
other N::S::P :
{{{
.sub foo :main
.local pmc class_p
.local int addr_p
.local pmc class_nsp
.local int addr_nsp
class_p = newclass [ 'P' ]
addr_p = get_addr class_p
$S0 = 'N::S::P' # Change to ..Q and it changes
$P0 = split '::', $S0
$P1 = get_hll_namespace $P0
unless null $P1 goto have_ns
die "Namespace was null"
have_ns:
class_nsp = get_class $P1
$P2 = class_nsp
addr_nsp = get_addr class_nsp
print "Addr of class 'P' is: "
say addr_p
print "Addr of 'N::S::P' is: "
say addr_nsp
unless addr_p == addr_nsp goto end
say "*** The addrs are the same. I think that's wrong."
goto end
got_class:
say "Got the class. I didn't see that coming."
end:
.end
.namespace ['N';'S';'P']
.sub bar :method
.return (1)
.end
.namespace ['N';'S';'Q']
.sub bar :method
.return (1)
.end
}}}
The effect of this seems to be that any code which relies on P6object
cannot create classes that have the same name.
The workaround is, trivially, to make sure that class names are distinct.
Anyone who has ever coded C89 should be okay.
--
Ticket URL: <https://trac.parrot.org/parrot/ticket/1492>
Parrot <https://trac.parrot.org/parrot/>
Parrot Development
_______________________________________________
parrot-tickets mailing list
[email protected]
http://lists.parrot.org/mailman/listinfo/parrot-tickets