Ticket #713: try-to-handle-subclasses-better.patch

File try-to-handle-subclasses-better.patch, 1.6 KB (added by Infinoid, 6 years ago)

Potential fix for Integer.i_add.

  • src/pmc/integer.pmc

    commit f27df51b02fe68171c9671832f0aa921e05cae63
    Author: Mark Glines <mark@glines.org>
    Date:   Wed May 27 08:29:10 2009 -0700
    
        [pmc] Try to make integer.i_add handle subclasses a bit better.
    
    diff --git a/src/pmc/integer.pmc b/src/pmc/integer.pmc
    index 4a166e7..31a26ec 100644
    a b  
    428428    VTABLE void i_add(PMC *value) { 
    429429        const INTVAL type = value->vtable->base_type; 
    430430 
    431         switch (type) { 
    432             case enum_class_Integer: 
    433                 STATICSELF.i_add_int(VTABLE_get_integer(INTERP, value)); 
    434                 break; 
    435  
    436             case enum_class_Complex: 
    437                 pmc_reuse(INTERP, SELF, enum_class_Complex, 0); 
    438                 VTABLE_set_number_native(INTERP, SELF, 
    439                         SELF.get_integer() + VTABLE_get_number(INTERP, value)); 
    440                 break; 
    441  
    442             default: 
    443                 VTABLE_set_number_native(INTERP, SELF, 
    444                         SELF.get_integer() + VTABLE_get_number(INTERP, value)); 
    445                 break; 
     431        if(VTABLE_isa(interp, value, CONST_STRING(interp, "Integer"))) { 
     432            STATICSELF.i_add_int(VTABLE_get_integer(INTERP, value)); 
     433        } else 
     434        if(VTABLE_isa(interp, value, CONST_STRING(interp, "Complex"))) { 
     435            pmc_reuse(INTERP, SELF, enum_class_Complex, 0); 
     436            VTABLE_set_number_native(INTERP, SELF, 
     437                    SELF.get_integer() + VTABLE_get_number(INTERP, value)); 
     438        } else { 
     439            VTABLE_set_number_native(INTERP, SELF, 
     440                    SELF.get_integer() + VTABLE_get_number(INTERP, value)); 
    446441        } 
    447442    } 
    448443