ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:50356] [ruby-trunk - Bug #7475][Open] Unexpected behavior of Module#append_features on singleton class
@ 2012-11-30  1:56 ernie (Ernie Miller)
  2012-11-30 13:51 ` [ruby-core:50394] [ruby-trunk - Bug #7475] " ernie (Ernie Miller)
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: ernie (Ernie Miller) @ 2012-11-30  1:56 UTC (permalink / raw)
  To: ruby-core


Issue #7475 has been reported by ernie (Ernie Miller).

----------------------------------------
Bug #7475: Unexpected behavior of Module#append_features on singleton class
https://bugs.ruby-lang.org/issues/7475

Author: ernie (Ernie Miller)
Status: Open
Priority: Normal
Assignee: 
Category: 
Target version: 1.9.3
ruby -v: ruby 1.9.3p327 (2012-11-10 revision 37606) [x86_64-darwin12.2.0] 


A more involved explanation is available at http://erniemiller.org/2012/11/29/ruby-tidbit-include-vs-extend-with-module-class-variables/

In short, the handling of class variables (and constants) when a module is extended vs included is not as expected.

Example:

    module Foo
      @@foo = 'foo'
    end
 
    class Bar
      include Foo
    end

    class Baz
      extend Foo
    end

    Bar.class_variable_get :@@foo # => "foo"
    Baz.singleton_class.class_variable_get :@@foo # => NameError: uninitialized class variable @@foo in Class

We would expect constant and class variable lookup on the singleton class to work, but it doesn't. Both Rubinius and JRuby seem to behave as expected in this case.

Thanks!


-- 
http://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [ruby-core:50394] [ruby-trunk - Bug #7475] Unexpected behavior of Module#append_features on singleton class
  2012-11-30  1:56 [ruby-core:50356] [ruby-trunk - Bug #7475][Open] Unexpected behavior of Module#append_features on singleton class ernie (Ernie Miller)
@ 2012-11-30 13:51 ` ernie (Ernie Miller)
  2013-02-17 23:52 ` [ruby-core:52405] " ko1 (Koichi Sasada)
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: ernie (Ernie Miller) @ 2012-11-30 13:51 UTC (permalink / raw)
  To: ruby-core


Issue #7475 has been updated by ernie (Ernie Miller).


Another quick set of observations from this morning:

    class Baz
      class << self
        Const = 'Const'
        @@foo = 'foo'
      end
    end

    Baz.class_variables.inspect # => [:@@foo]
    Baz.singleton_class.class_variables.inspect # => []
    Baz.singleton_class.class_variable_get :@@foo # => 'foo' ???
    Baz.const_get(:Const, false) rescue "Nope." # => 'Nope.'
    Baz.singleton_class.const_get(:Const, false) rescue "Nope." # => Const

    # Let's try setting it explicitly.
    Baz.singleton_class.class_variable_set :@@foo, 'foo'
    Baz.singleton_class.class_variables.inspect # => [] -- still "empty"

However, if we extend Foo on Baz, vs opening the singleton class with "class << self",  we can class_variable_set on the singleton and see it show up in the list of class variables, vs being empty.

All of this is to say that I think some unexpected weirdness is going on in rb_include_module and/or include_class_new.
----------------------------------------
Bug #7475: Unexpected behavior of Module#append_features on singleton class
https://bugs.ruby-lang.org/issues/7475#change-34221

Author: ernie (Ernie Miller)
Status: Open
Priority: Normal
Assignee: 
Category: 
Target version: 1.9.3
ruby -v: ruby 1.9.3p327 (2012-11-10 revision 37606) [x86_64-darwin12.2.0] 


A more involved explanation is available at http://erniemiller.org/2012/11/29/ruby-tidbit-include-vs-extend-with-module-class-variables/

In short, the handling of class variables (and constants) when a module is extended vs included is not as expected.

Example:

    module Foo
      @@foo = 'foo'
    end
 
    class Bar
      include Foo
    end

    class Baz
      extend Foo
    end

    Bar.class_variable_get :@@foo # => "foo"
    Baz.singleton_class.class_variable_get :@@foo # => NameError: uninitialized class variable @@foo in Class

We would expect constant and class variable lookup on the singleton class to work, but it doesn't. Both Rubinius and JRuby seem to behave as expected in this case.

Thanks!


-- 
http://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [ruby-core:52405] [ruby-trunk - Bug #7475] Unexpected behavior of Module#append_features on singleton class
  2012-11-30  1:56 [ruby-core:50356] [ruby-trunk - Bug #7475][Open] Unexpected behavior of Module#append_features on singleton class ernie (Ernie Miller)
  2012-11-30 13:51 ` [ruby-core:50394] [ruby-trunk - Bug #7475] " ernie (Ernie Miller)
@ 2013-02-17 23:52 ` ko1 (Koichi Sasada)
  2013-02-18  1:47 ` [ruby-core:52425] " nobu (Nobuyoshi Nakada)
  2019-08-15 15:28 ` [ruby-core:94367] [Ruby master Bug#7475] " merch-redmine
  3 siblings, 0 replies; 5+ messages in thread
From: ko1 (Koichi Sasada) @ 2013-02-17 23:52 UTC (permalink / raw)
  To: ruby-core


Issue #7475 has been updated by ko1 (Koichi Sasada).

Assignee set to matz (Yukihiro Matsumoto)
Target version changed from 1.9.3 to next minor

Matz, could you check it?

----------------------------------------
Bug #7475: Unexpected behavior of Module#append_features on singleton class
https://bugs.ruby-lang.org/issues/7475#change-36458

Author: ernie (Ernie Miller)
Status: Open
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: 
Target version: next minor
ruby -v: ruby 1.9.3p327 (2012-11-10 revision 37606) [x86_64-darwin12.2.0] 


A more involved explanation is available at http://erniemiller.org/2012/11/29/ruby-tidbit-include-vs-extend-with-module-class-variables/

In short, the handling of class variables (and constants) when a module is extended vs included is not as expected.

Example:

    module Foo
      @@foo = 'foo'
    end
 
    class Bar
      include Foo
    end

    class Baz
      extend Foo
    end

    Bar.class_variable_get :@@foo # => "foo"
    Baz.singleton_class.class_variable_get :@@foo # => NameError: uninitialized class variable @@foo in Class

We would expect constant and class variable lookup on the singleton class to work, but it doesn't. Both Rubinius and JRuby seem to behave as expected in this case.

Thanks!


-- 
http://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [ruby-core:52425] [ruby-trunk - Bug #7475] Unexpected behavior of Module#append_features on singleton class
  2012-11-30  1:56 [ruby-core:50356] [ruby-trunk - Bug #7475][Open] Unexpected behavior of Module#append_features on singleton class ernie (Ernie Miller)
  2012-11-30 13:51 ` [ruby-core:50394] [ruby-trunk - Bug #7475] " ernie (Ernie Miller)
  2013-02-17 23:52 ` [ruby-core:52405] " ko1 (Koichi Sasada)
@ 2013-02-18  1:47 ` nobu (Nobuyoshi Nakada)
  2019-08-15 15:28 ` [ruby-core:94367] [Ruby master Bug#7475] " merch-redmine
  3 siblings, 0 replies; 5+ messages in thread
From: nobu (Nobuyoshi Nakada) @ 2013-02-18  1:47 UTC (permalink / raw)
  To: ruby-core


Issue #7475 has been updated by nobu (Nobuyoshi Nakada).

Description updated


----------------------------------------
Bug #7475: Unexpected behavior of Module#append_features on singleton class
https://bugs.ruby-lang.org/issues/7475#change-36480

Author: ernie (Ernie Miller)
Status: Open
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: 
Target version: next minor
ruby -v: ruby 1.9.3p327 (2012-11-10 revision 37606) [x86_64-darwin12.2.0] 


=begin
A more involved explanation is available at ((<URL:http://erniemiller.org/2012/11/29/ruby-tidbit-include-vs-extend-with-module-class-variables/>))

In short, the handling of class variables (and constants) when a module is extended vs included is not as expected.

Example:

    module Foo
      @@foo = 'foo'
    end
 
    class Bar
      include Foo
    end

    class Baz
      extend Foo
    end

    Bar.class_variable_get :@@foo # => "foo"
    Baz.singleton_class.class_variable_get :@@foo # => NameError: uninitialized class variable @@foo in Class

We would expect constant and class variable lookup on the singleton class to work, but it doesn't. Both Rubinius and JRuby seem to behave as expected in this case.

Thanks!
=end



-- 
http://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [ruby-core:94367] [Ruby master Bug#7475] Unexpected behavior of Module#append_features on singleton class
  2012-11-30  1:56 [ruby-core:50356] [ruby-trunk - Bug #7475][Open] Unexpected behavior of Module#append_features on singleton class ernie (Ernie Miller)
                   ` (2 preceding siblings ...)
  2013-02-18  1:47 ` [ruby-core:52425] " nobu (Nobuyoshi Nakada)
@ 2019-08-15 15:28 ` merch-redmine
  3 siblings, 0 replies; 5+ messages in thread
From: merch-redmine @ 2019-08-15 15:28 UTC (permalink / raw)
  To: ruby-core

Issue #7475 has been updated by jeremyevans0 (Jeremy Evans).

Status changed from Open to Closed

I believe this is not a bug, it is expected behavior.  Class variable lookup for singleton classes is different from regular classes.  Class variable lookup for singleton classes is (with example class A):

* Singleton Class (A.singleton_class)
* All Ancestors of Class (A.ancestors)

Note that this does not include modules included in the singleton class.

Class variable access is different for singleton classes because class variable access from the singleton class should access class variables in the class itself.

Class variable lookup could certainly be changed to include modules included in the singleton class, but that would be a separate feature request, and we would have to decide if we want to only include modules before the superclass's singleton class, or all modules and singleton classes before `Class`.  Please submit a feature request if you would like to change class variable lookup.

----------------------------------------
Bug #7475: Unexpected behavior of Module#append_features on singleton class
https://bugs.ruby-lang.org/issues/7475#change-80779

* Author: ernie (Ernie Miller)
* Status: Closed
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
* Target version: 
* ruby -v: ruby 1.9.3p327 (2012-11-10 revision 37606) [x86_64-darwin12.2.0] 
* Backport: 2.3: UNKNOWN, 2.4: UNKNOWN, 2.5: UNKNOWN
----------------------------------------
=begin
A more involved explanation is available at ((<URL:http://erniemiller.org/2012/11/29/ruby-tidbit-include-vs-extend-with-module-class-variables/>))

In short, the handling of class variables (and constants) when a module is extended vs included is not as expected.

Example:

    module Foo
      @@foo = 'foo'
    end
 
    class Bar
      include Foo
    end

    class Baz
      extend Foo
    end

    Bar.class_variable_get :@@foo # => "foo"
    Baz.singleton_class.class_variable_get :@@foo # => NameError: uninitialized class variable @@foo in Class

We would expect constant and class variable lookup on the singleton class to work, but it doesn't. Both Rubinius and JRuby seem to behave as expected in this case.

Thanks!
=end




-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-08-15 15:28 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-11-30  1:56 [ruby-core:50356] [ruby-trunk - Bug #7475][Open] Unexpected behavior of Module#append_features on singleton class ernie (Ernie Miller)
2012-11-30 13:51 ` [ruby-core:50394] [ruby-trunk - Bug #7475] " ernie (Ernie Miller)
2013-02-17 23:52 ` [ruby-core:52405] " ko1 (Koichi Sasada)
2013-02-18  1:47 ` [ruby-core:52425] " nobu (Nobuyoshi Nakada)
2019-08-15 15:28 ` [ruby-core:94367] [Ruby master Bug#7475] " 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).