On 4/27/07, Matt Diephouse <[EMAIL PROTECTED]> wrote:
On 4/27/07, via RT Jerry Gay <[EMAIL PROTECTED]> wrote: > # New Ticket Created by Jerry Gay > # Please include the string: [perl #42776] > # in the subject line of all future correspondence about this issue. > # <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=42776 > > > > there are two 'isa' ops, defined in src/ops/object.ops > > one takes a string param, and the other a pmc. it seems the string > variant is used frequently throughout the source and tests, but the > pmc variant is much less frequently used, and i haven't come across > any tests, either. it seems these two ops don't agree on return > value... which is problematic. > > D:\usr\local\parrot\head>parrot - > .sub main > .local pmc class, obj > class = new 'Class' > obj = class.'new'() > $I0 = isa obj, 'Object' > print $I0 > .local pmc cl > cl = new 'String' > cl = 'Object' > $I1 = isa obj, cl > print $I1 > .end > ^Z > 10 > > why? iunno. but this is causing me problems when using 'isa_ok' in > 'Test/More.pir', since it uses the pmc variant.It looks like the PMC variant is correct in this case, because Object isn't actually a class. There's a class flag for PMCs that sets whether or not they are a class and Object doesn't have this set. When you call the PMC variant of isa, it calls Parrot_object_isa, and that has this code: /* if this is not a class */ if (!PObj_is_class_TEST(pmc)) { pmc = VTABLE_get_class(interp, pmc); } So since Object isn't a class, it calls the get_class vtable and gets the Class pmc. It then tests the object to see if it's a Class, which it obviously isn't. Contrast this to the String isa variant. It calls the isa vtable function. Object inherits whatever default isa implementation is provided. I'm not sure where that code is (it's a little harder to find), but I'm guessing it just does a string comparison on the PMC names without testing if the PMC is a class.
thanks for the explanation. i believe src/pmc/default.pmc has the isa vtable implementation for Object, by the way. so, given this differing behavior, these ops must be better documented. also, isa_ok in Test/More.pir should be modified to use the string variant of isa, which seems more appropriate. expect a patch soon. ~jerry
