Skip to content
  • Jeremy Evans's avatar
    55b7ba36
    Make super in instance_eval in method in module raise TypeError · 55b7ba36
    Jeremy Evans authored
    This makes behavior the same as super in instance_eval in method
    in class.  The reason this wasn't implemented before is that
    there is a check to determine if the self in the current context
    is of the expected class, and a module itself can be included
    in multiple classes, so it doesn't have an expected class.
    
    Implementing this requires giving iclasses knowledge of which
    class created them, so that super call in the module method
    knows the expected class for super calls.  This reference
    is called includer, and should only be set for iclasses.
    
    Note that the approach Ruby uses in this check is not robust. If
    you instance_eval another object of the same class and call super,
    instead of an TypeError, you get super called with the
    instance_eval receiver instead of the method receiver.  Truly
    fixing super would require keeping a reference to the super object
    (method receiver) in each frame where scope has changed, and using
    that instead of current self when calling super.
    
    Fixes [Bug #11636]
    55b7ba36
    Make super in instance_eval in method in module raise TypeError
    Jeremy Evans authored
    This makes behavior the same as super in instance_eval in method
    in class.  The reason this wasn't implemented before is that
    there is a check to determine if the self in the current context
    is of the expected class, and a module itself can be included
    in multiple classes, so it doesn't have an expected class.
    
    Implementing this requires giving iclasses knowledge of which
    class created them, so that super call in the module method
    knows the expected class for super calls.  This reference
    is called includer, and should only be set for iclasses.
    
    Note that the approach Ruby uses in this check is not robust. If
    you instance_eval another object of the same class and call super,
    instead of an TypeError, you get super called with the
    instance_eval receiver instead of the method receiver.  Truly
    fixing super would require keeping a reference to the super object
    (method receiver) in each frame where scope has changed, and using
    that instead of current self when calling super.
    
    Fixes [Bug #11636]
Loading