[ruby-core:94463] [Ruby master Bug#11636] super in instance_eval in a method defined in a module is invoked with a wrong receiver
From:
merch-redmine@...
Date:
2019-08-21 21:15:57 UTC
List:
ruby-core #94463
Issue #11636 has been updated by jeremyevans0 (Jeremy Evans).
File instance_eval-module-super-11636.patch added
This is still a bug in the master branch. Attached is a patch that
fixes it, making the behavior for super in instance_eval in method
in module the same as super in instance_eval in method in class,
raising a TypeError.
This is implemented by keeping a reference to the including class
when creating all iclasses, and using that reference in the check
for expected class in the super check.
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 a 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.
----------------------------------------
Bug #11636: super in instance_eval in a method defined in a module is invoked with a wrong receiver
https://bugs.ruby-lang.org/issues/11636#change-80897
* Author: shugo (Shugo Maeda)
* Status: Assigned
* Priority: Normal
* Assignee: ko1 (Koichi Sasada)
* Target version:
* ruby -v:
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN
----------------------------------------
super in instance_eval in a method defined in a module is invoked with a wrong receiver:
```ruby
class Foo
def initialize
@foo = :foo
end
def foo
p [self, @foo]
end
end
module M
def foo
x = Object.new
x.instance_eval do
super
end
end
end
class Bar < Foo
include M
end
Bar.new.foo
```
The output should be [#<Foo:...>, :foo] or an exception.
Matz prefer the former (https://twitter.com/yukihiro_matz/status/659913844861464576).
---Files--------------------------------
instance_eval-module-super-11636.patch (4.93 KB)
--
https://bugs.ruby-lang.org/
Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>