summaryrefslogtreecommitdiff
path: root/class.c
diff options
context:
space:
mode:
authorJeremy Evans <code@jeremyevans.net>2019-08-21 13:59:36 -0700
committerNobuyoshi Nakada <nobu@ruby-lang.org>2019-12-12 15:50:19 +0900
commit55b7ba368696033f2e89b77cbcd4a05dec97b139 (patch)
tree797c7c459c25bd585cb56a3eb5b159181594ac5e /class.c
parent1a4a9bdb5da973f8a89e699ce6d0fb1ca21090bd (diff)
Make super in instance_eval in method in module raise TypeError
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]
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/2717
Diffstat (limited to 'class.c')
-rw-r--r--class.c1
1 files changed, 1 insertions, 0 deletions
diff --git a/class.c b/class.c
index 736e227..4129647 100644
--- a/class.c
+++ b/class.c
@@ -921,6 +921,7 @@ include_modules_at(const VALUE klass, VALUE c, VALUE module, int search_super)
}
iclass = rb_include_class_new(module, RCLASS_SUPER(c));
c = RCLASS_SET_SUPER(c, iclass);
+ RCLASS_SET_INCLUDER(iclass, klass);
{
VALUE m = module;