[#94657] [Ruby master Feature#16131] Remove $SAFE, taint and trust — naruse@...
Issue #16131 has been reported by naruse (Yui NARUSE).
3 messages
2019/08/29
[ruby-core:94242] [Ruby master Bug#8297] extend & inherited class variable issue
From:
merch-redmine@...
Date:
2019-08-10 04:33:48 UTC
List:
ruby-core #94242
Issue #8297 has been updated by jeremyevans0 (Jeremy Evans).
Backport deleted (1.9.3: UNKNOWN, 2.0.0: UNKNOWN)
File singleton-class-class-variable-lookup-8297.patch added
This bug is still present in the master branch. I think the best way to fix it is to modify `Module#class_variables` for singleton classes of classes/modules to use the same lookup order as `Module#class_variable_get`:
* Singleton Class
* Class
* All Ancestors of Class
Note that this does not include modules included in the singleton class.
Attached is a patch that implements this behavior.
----------------------------------------
Bug #8297: extend & inherited class variable issue
https://bugs.ruby-lang.org/issues/8297#change-80549
* Author: dunric (David Unric)
* Status: Open
* Priority: Normal
* Assignee:
* Target version:
* ruby -v: 2.0.0p0
* Backport:
----------------------------------------
=begin
By the current documentation, (({Object#extend})) method has to (only) add instance methods of a module given as a parameter.
In the following example, the class ((|C|)) is extended with module ((|M|)).
By (({class_variables})) method sent to singleton class of C also did inherit class variable ((|@@xyz|)).
However when inherited ((|@@xyz|)) is accessed, (({NameError})) exception is raised as it is was not initialized.
module M
@@xyz = 123
end
M.class_variables # [:@@xyz]
M.class_variable_get :@@xyz # 123 , so far so good
class C
extend M
end
p C.singleton_class.class_variables # [:@@xyz]
p C.singleton_class.class_variable_get :@@xyz # NameError exception
Either (({class_variables})) returns invalid array - ie. ((|@@xyz|)) was not inherited at all or (({class_variable_get})) ignores class variables inherited from module (when sent to a singleton).
=end
Prior Ruby versions like 1.9.3p392 does not suffer this issue as return with Module#class_variables returns an empty array.
---Files--------------------------------
singleton-class-class-variable-lookup-8297.patch (2.75 KB)
--
https://bugs.ruby-lang.org/
Unsubscribe: <mailto:[email protected]?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>