petdance/scratch — Issue #93: class associated to namespace ["parrot";"Class"] gets overridden
Author: petdance
Created: 2011-11-14 05:54:54+00:00
State: open
Labels: bug, core, Pri-normal, Sev-medium

When running the following code the the class associated to the ["parrot";"Class"] namespace gets overridden by the Foo9 class obj
newclass $P1, "Foo9"

typeof $P6, $P1

$P3 = get_root_namespace ["parrot";"Class"]

$P4 = get_class $P3

print $P4

return "Foo9" instead of the expected "Class"

the function get_class in the default.pmc calls the pmc_new_init(interp, enum_class_PMCProxy, type_num);
where the self object points to the Foo9 class obj.

In init_pmc in pmcproxy.pmc the interp->vtables[self->type_num = 102 in my case]->_namespace; points to the parrot;class namespace. Because this function effectually calls
Parrot_PCCINVOKE(interp, interp->vtables[self->type_num]->_namespace = parrot;Class, CONST_STRING(interp, "set_class"), "P->", SELF = class of Foo9);
the class associated to the parrot;Class namespace gets overridden.

I solved this problem by adding following line to init_class_from_hash in the class.pmc
new_vtable->_namespace = new_namespace;

But I don't know for what reason the interp->vtables[type_num]->_namespace is different from the interp->vtables[type_num]->pmc_class->_namespace

So I do not know whether this is the right solution to this problem.

But I added a special ticket for this because there is another bug.

''Test''

The test in t/pmc/objects.t fails to detect this condition because of the bug described in ticket #879.
But adding a special test with the code described above would be good thing to do.

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