Hi

I've posed a similar question on IRC a couple of times without a
response. So I've posted it here for a wider audience.

This really follows on from my previous post about inheritance and
results from a small investigation (with a little help from Andrew).

After subclassing a base class and attempting to run a method (that
exists in the base class) on the new derived class, this causes an
error. I use the term method loosely as their appears to be several
types of functions, namely vtables, methods and i guess plain subs.

I wrote a simple PIR sub (http://nopaste.snit.ch/16339): -

<code>
.include 'library/dumper.pir'

.sub '' :main

    $P0 = get_class 'Integer'

    $P1 = $P0.'find_method'('i_subtract')
    _dumper($P1, 'find_method result')

    $P2 = new 'Integer'
    $P2 = 10
    $P2.'i_subtract'(1)
    _dumper($P2, '10 - 1')

    $P3 = inspect $P0
    _dumper($P3, 'inspect')

.end

What is interesting in the above code is I use i_subtract as a method
on $P2 but it's not findable using find_method. In actual fact, the
output from the above script is as follows: -

<output>
"find_method result" => null
"10 - 1" => 9
"inspect" => Hash {
    "methods" => Hash {
        "get_as_base" => undef
    },
    "name" => "Integer",
    "namespace" => NameSpace {
        ...
        "i_subtract" => MultiSub (size:3) [
            PMC 'NCI' { ... },
            PMC 'NCI' { ... },
            PMC 'NCI' { ... }
        ],
        ...
    },
    "parents" => ResizablePMCArray (size:0) [
    ]

</output>
</code>

This shows the i_subtract sub under a namespace hash.

This seems to be a cause for inheritance not working since it relies
on the find_method. This also seems to happen if one creates their own
method in the new derived class's namespace - that new method is no
longer under methods but under namespace.

I've looked at PDD15 and not been able to find the info I need to
determine what is the correct behaviour. But then, perhaps I am
reading it wrong.

Can anyone help and offer some insight. If I know what the proper
behaviour should be then I might be able to supply a patch.

Cheers
Blair
_______________________________________________
http://lists.parrot.org/mailman/listinfo/parrot-dev

Reply via email to