* [ruby-core:54463] [ruby-trunk - Bug #8297][Open] extend & inherited class variable issue
@ 2013-04-19 12:02 dunric (David Unric)
2013-04-19 12:12 ` [ruby-core:54464] [ruby-trunk - Bug #8297] " dunric (David Unric)
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: dunric (David Unric) @ 2013-04-19 12:02 UTC (permalink / raw
To: ruby-core
Issue #8297 has been reported by dunric (David Unric).
----------------------------------------
Bug #8297: extend & inherited class variable issue
https://bugs.ruby-lang.org/issues/8297
Author: dunric (David Unric)
Status: Open
Priority: Normal
Assignee:
Category: core
Target version:
ruby -v: 2.0.0p0
Backport: 1.9.3: UNKNOWN, 2.0.0: UNKNOWN
=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.
--
http://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 5+ messages in thread
* [ruby-core:54464] [ruby-trunk - Bug #8297] extend & inherited class variable issue
2013-04-19 12:02 [ruby-core:54463] [ruby-trunk - Bug #8297][Open] extend & inherited class variable issue dunric (David Unric)
@ 2013-04-19 12:12 ` dunric (David Unric)
2013-04-19 14:53 ` [ruby-core:54469] " nobu (Nobuyoshi Nakada)
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: dunric (David Unric) @ 2013-04-19 12:12 UTC (permalink / raw
To: ruby-core
Issue #8297 has been updated by dunric (David Unric).
=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).
Prior Ruby versions like 1.9.3p392 does not suffer this issue as Module#class_variables returns an empty array.
=end
----------------------------------------
Bug #8297: extend & inherited class variable issue
https://bugs.ruby-lang.org/issues/8297#change-38747
Author: dunric (David Unric)
Status: Open
Priority: Normal
Assignee:
Category: core
Target version:
ruby -v: 2.0.0p0
Backport: 1.9.3: UNKNOWN, 2.0.0: UNKNOWN
=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.
--
http://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 5+ messages in thread
* [ruby-core:54469] [ruby-trunk - Bug #8297] extend & inherited class variable issue
2013-04-19 12:02 [ruby-core:54463] [ruby-trunk - Bug #8297][Open] extend & inherited class variable issue dunric (David Unric)
2013-04-19 12:12 ` [ruby-core:54464] [ruby-trunk - Bug #8297] " dunric (David Unric)
@ 2013-04-19 14:53 ` nobu (Nobuyoshi Nakada)
2019-01-14 17:37 ` [ruby-core:91085] [Ruby trunk Bug#8297] " justin
2019-08-10 4:33 ` [ruby-core:94242] [Ruby master " merch-redmine
3 siblings, 0 replies; 5+ messages in thread
From: nobu (Nobuyoshi Nakada) @ 2013-04-19 14:53 UTC (permalink / raw
To: ruby-core
Issue #8297 has been updated by nobu (Nobuyoshi Nakada).
Description updated
----------------------------------------
Bug #8297: extend & inherited class variable issue
https://bugs.ruby-lang.org/issues/8297#change-38757
Author: dunric (David Unric)
Status: Open
Priority: Normal
Assignee:
Category: core
Target version:
ruby -v: 2.0.0p0
Backport: 1.9.3: UNKNOWN, 2.0.0: UNKNOWN
=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.
--
http://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 5+ messages in thread
* [ruby-core:91085] [Ruby trunk Bug#8297] extend & inherited class variable issue
2013-04-19 12:02 [ruby-core:54463] [ruby-trunk - Bug #8297][Open] extend & inherited class variable issue dunric (David Unric)
2013-04-19 12:12 ` [ruby-core:54464] [ruby-trunk - Bug #8297] " dunric (David Unric)
2013-04-19 14:53 ` [ruby-core:54469] " nobu (Nobuyoshi Nakada)
@ 2019-01-14 17:37 ` justin
2019-08-10 4:33 ` [ruby-core:94242] [Ruby master " merch-redmine
3 siblings, 0 replies; 5+ messages in thread
From: justin @ 2019-01-14 17:37 UTC (permalink / raw
To: ruby-core
Issue #8297 has been updated by jsc (Justin Collins).
This appears to still be an issue with Ruby 2.6.0 (ruby 2.6.0p0 (2018-12-25 revision 66547) [x86_64-linux]):
Example:
~~~
module M
@@xyz = 123
end
puts "M.class_variables: #{M.class_variables.inspect}"
puts "M.class_variable_get :@@xyz: #{M.class_variable_get :@@xyz}"
class C
extend M
end
puts "C.class_variables: #{C.class_variables.inspect}"
puts "C.class_variable_get :@@xyz: #{C.class_variable_get :@@xyz}"
~~~
Output:
~~~
M.class_variables: [:@@xyz]
M.class_variable_get :@@xyz: 123
C.class_variables: []
Traceback (most recent call last):
1: from 8297.rb:13:in `<main>'
8297.rb:13:in `class_variable_get': uninitialized class variable @@xyz in C (NameError)
~~~
----------------------------------------
Bug #8297: extend & inherited class variable issue
https://bugs.ruby-lang.org/issues/8297#change-76313
* Author: dunric (David Unric)
* Status: Open
* Priority: Normal
* Assignee:
* Target version:
* ruby -v: 2.0.0p0
* Backport: 1.9.3: UNKNOWN, 2.0.0: UNKNOWN
----------------------------------------
=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.
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 5+ messages in thread
* [ruby-core:94242] [Ruby master Bug#8297] extend & inherited class variable issue
2013-04-19 12:02 [ruby-core:54463] [ruby-trunk - Bug #8297][Open] extend & inherited class variable issue dunric (David Unric)
` (2 preceding siblings ...)
2019-01-14 17:37 ` [ruby-core:91085] [Ruby trunk Bug#8297] " justin
@ 2019-08-10 4:33 ` merch-redmine
3 siblings, 0 replies; 5+ messages in thread
From: merch-redmine @ 2019-08-10 4:33 UTC (permalink / raw
To: ruby-core
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/
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2019-08-10 4:33 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-04-19 12:02 [ruby-core:54463] [ruby-trunk - Bug #8297][Open] extend & inherited class variable issue dunric (David Unric)
2013-04-19 12:12 ` [ruby-core:54464] [ruby-trunk - Bug #8297] " dunric (David Unric)
2013-04-19 14:53 ` [ruby-core:54469] " nobu (Nobuyoshi Nakada)
2019-01-14 17:37 ` [ruby-core:91085] [Ruby trunk Bug#8297] " justin
2019-08-10 4:33 ` [ruby-core:94242] [Ruby master " merch-redmine
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).