* [ruby-core:118514] [Ruby master Bug#20620] singleton_method undefined for module using "extend self"
@ 2024-07-09 5:47 dentarg (Patrik Ragnarsson) via ruby-core
2024-07-09 6:45 ` [ruby-core:118516] " jeremyevans0 (Jeremy Evans) via ruby-core
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: dentarg (Patrik Ragnarsson) via ruby-core @ 2024-07-09 5:47 UTC (permalink / raw)
To: ruby-core; +Cc: dentarg (Patrik Ragnarsson)
Issue #20620 has been reported by dentarg (Patrik Ragnarsson).
----------------------------------------
Bug #20620: singleton_method undefined for module using "extend self"
https://bugs.ruby-lang.org/issues/20620
* Author: dentarg (Patrik Ragnarsson)
* Status: Open
* ruby -v: ruby 3.4.0dev (2024-07-08T21:43:28Z master e500222de1) [x86_64-linux]
* Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN
----------------------------------------
Is this a bug? I expected `ExtendSelf.singleton_method(:foo)` to work when `ExtendSelf.singleton_methods` worked and `:foo` was in the list returned.
```ruby
# singleton_method.rb
class Klass
def self.foo
end
end
module ExtendSelf
extend self
def foo
end
end
p RUBY_DESCRIPTION
p "Klass"
p Klass.singleton_methods # => [:foo]
p Klass.singleton_method(:foo) # => #<Method: Klass.foo() singleton_method.rb:2>
p "ExtendSelf"
p ExtendSelf.singleton_methods # => [:foo]
p ExtendSelf.singleton_method(:foo) # => singleton_method.rb:19:in `singleton_method': undefined singleton method `foo' for `ExtendSelf' (NameError)
```
```shell
$ docker run --rm -it -v $(pwd):/app -w /app rubylang/ruby:master-nightly-jammy
Unable to find image 'rubylang/ruby:master-nightly-jammy' locally
master-nightly-jammy: Pulling from rubylang/ruby
...
Digest: sha256:922037b184b897786a26b2460f70a66139f87dce67f20ddf760cd4186790ed9f
root@9807305c322a:/app# ruby -v
ruby 3.4.0dev (2024-07-08T21:43:28Z master e500222de1) [x86_64-linux]
root@9807305c322a:/app# ruby singleton_method.rb
"ruby 3.4.0dev (2024-07-08T21:43:28Z master e500222de1) [x86_64-linux]"
"Klass"
[:foo]
#<Method: Klass.foo() singleton_method.rb:2>
"ExtendSelf"
[:foo]
singleton_method.rb:21:in 'Kernel#singleton_method': undefined singleton method 'foo' for 'ExtendSelf' (NameError)
```
--
https://bugs.ruby-lang.org/
______________________________________________
ruby-core mailing list -- ruby-core@ml.ruby-lang.org
To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/
^ permalink raw reply [flat|nested] 5+ messages in thread
* [ruby-core:118516] [Ruby master Bug#20620] singleton_method undefined for module using "extend self"
2024-07-09 5:47 [ruby-core:118514] [Ruby master Bug#20620] singleton_method undefined for module using "extend self" dentarg (Patrik Ragnarsson) via ruby-core
@ 2024-07-09 6:45 ` jeremyevans0 (Jeremy Evans) via ruby-core
2024-08-01 9:32 ` [ruby-core:118764] " matz (Yukihiro Matsumoto) via ruby-core
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: jeremyevans0 (Jeremy Evans) via ruby-core @ 2024-07-09 6:45 UTC (permalink / raw)
To: ruby-core; +Cc: jeremyevans0 (Jeremy Evans)
Issue #20620 has been updated by jeremyevans0 (Jeremy Evans).
I don't think this is a bug. It does seem inconsistent, but only because the `all` argument to `singleton_methods` defaults to true. If you call `singleton_methods(false)`, then you get the behavior you would expect from the method name (only show actual singleton methods, not methods in modules that extend the object).
----------------------------------------
Bug #20620: singleton_method undefined for module using "extend self"
https://bugs.ruby-lang.org/issues/20620#change-109037
* Author: dentarg (Patrik Ragnarsson)
* Status: Open
* ruby -v: ruby 3.4.0dev (2024-07-08T21:43:28Z master e500222de1) [x86_64-linux]
* Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN
----------------------------------------
Is this a bug? I expected `ExtendSelf.singleton_method(:foo)` to work when `ExtendSelf.singleton_methods` worked and `:foo` was in the list returned.
```ruby
# singleton_method.rb
class Klass
def self.foo
end
end
module ExtendSelf
extend self
def foo
end
end
p RUBY_DESCRIPTION
p "Klass"
p Klass.singleton_methods # => [:foo]
p Klass.singleton_method(:foo) # => #<Method: Klass.foo() singleton_method.rb:2>
p "ExtendSelf"
p ExtendSelf.singleton_methods # => [:foo]
p ExtendSelf.singleton_method(:foo) # => singleton_method.rb:19:in `singleton_method': undefined singleton method `foo' for `ExtendSelf' (NameError)
```
```shell
$ docker run --rm -it -v $(pwd):/app -w /app rubylang/ruby:master-nightly-jammy
Unable to find image 'rubylang/ruby:master-nightly-jammy' locally
master-nightly-jammy: Pulling from rubylang/ruby
...
Digest: sha256:922037b184b897786a26b2460f70a66139f87dce67f20ddf760cd4186790ed9f
root@9807305c322a:/app# ruby -v
ruby 3.4.0dev (2024-07-08T21:43:28Z master e500222de1) [x86_64-linux]
root@9807305c322a:/app# ruby singleton_method.rb
"ruby 3.4.0dev (2024-07-08T21:43:28Z master e500222de1) [x86_64-linux]"
"Klass"
[:foo]
#<Method: Klass.foo() singleton_method.rb:2>
"ExtendSelf"
[:foo]
singleton_method.rb:21:in 'Kernel#singleton_method': undefined singleton method 'foo' for 'ExtendSelf' (NameError)
```
--
https://bugs.ruby-lang.org/
______________________________________________
ruby-core mailing list -- ruby-core@ml.ruby-lang.org
To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/
^ permalink raw reply [flat|nested] 5+ messages in thread
* [ruby-core:118764] [Ruby master Bug#20620] singleton_method undefined for module using "extend self"
2024-07-09 5:47 [ruby-core:118514] [Ruby master Bug#20620] singleton_method undefined for module using "extend self" dentarg (Patrik Ragnarsson) via ruby-core
2024-07-09 6:45 ` [ruby-core:118516] " jeremyevans0 (Jeremy Evans) via ruby-core
@ 2024-08-01 9:32 ` matz (Yukihiro Matsumoto) via ruby-core
2024-09-12 14:23 ` [ruby-core:119138] " jeremyevans0 (Jeremy Evans) via ruby-core
2024-10-03 6:53 ` [ruby-core:119421] " matz (Yukihiro Matsumoto) via ruby-core
3 siblings, 0 replies; 5+ messages in thread
From: matz (Yukihiro Matsumoto) via ruby-core @ 2024-08-01 9:32 UTC (permalink / raw)
To: ruby-core; +Cc: matz (Yukihiro Matsumoto)
Issue #20620 has been updated by matz (Yukihiro Matsumoto).
I think `singleton_method` should traverse super-classes (as long as they are ICLASS) too. Probably we need to check for compatibility issues.
Matz.
----------------------------------------
Bug #20620: singleton_method undefined for module using "extend self"
https://bugs.ruby-lang.org/issues/20620#change-109316
* Author: dentarg (Patrik Ragnarsson)
* Status: Open
* ruby -v: ruby 3.4.0dev (2024-07-08T21:43:28Z master e500222de1) [x86_64-linux]
* Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN
----------------------------------------
Is this a bug? I expected `ExtendSelf.singleton_method(:foo)` to work when `ExtendSelf.singleton_methods` worked and `:foo` was in the list returned.
```ruby
# singleton_method.rb
class Klass
def self.foo
end
end
module ExtendSelf
extend self
def foo
end
end
p RUBY_DESCRIPTION
p "Klass"
p Klass.singleton_methods # => [:foo]
p Klass.singleton_method(:foo) # => #<Method: Klass.foo() singleton_method.rb:2>
p "ExtendSelf"
p ExtendSelf.singleton_methods # => [:foo]
p ExtendSelf.singleton_method(:foo) # => singleton_method.rb:19:in `singleton_method': undefined singleton method `foo' for `ExtendSelf' (NameError)
```
```shell
$ docker run --rm -it -v $(pwd):/app -w /app rubylang/ruby:master-nightly-jammy
Unable to find image 'rubylang/ruby:master-nightly-jammy' locally
master-nightly-jammy: Pulling from rubylang/ruby
...
Digest: sha256:922037b184b897786a26b2460f70a66139f87dce67f20ddf760cd4186790ed9f
root@9807305c322a:/app# ruby -v
ruby 3.4.0dev (2024-07-08T21:43:28Z master e500222de1) [x86_64-linux]
root@9807305c322a:/app# ruby singleton_method.rb
"ruby 3.4.0dev (2024-07-08T21:43:28Z master e500222de1) [x86_64-linux]"
"Klass"
[:foo]
#<Method: Klass.foo() singleton_method.rb:2>
"ExtendSelf"
[:foo]
singleton_method.rb:21:in 'Kernel#singleton_method': undefined singleton method 'foo' for 'ExtendSelf' (NameError)
```
--
https://bugs.ruby-lang.org/
______________________________________________
ruby-core mailing list -- ruby-core@ml.ruby-lang.org
To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/
^ permalink raw reply [flat|nested] 5+ messages in thread
* [ruby-core:119138] [Ruby master Bug#20620] singleton_method undefined for module using "extend self"
2024-07-09 5:47 [ruby-core:118514] [Ruby master Bug#20620] singleton_method undefined for module using "extend self" dentarg (Patrik Ragnarsson) via ruby-core
2024-07-09 6:45 ` [ruby-core:118516] " jeremyevans0 (Jeremy Evans) via ruby-core
2024-08-01 9:32 ` [ruby-core:118764] " matz (Yukihiro Matsumoto) via ruby-core
@ 2024-09-12 14:23 ` jeremyevans0 (Jeremy Evans) via ruby-core
2024-10-03 6:53 ` [ruby-core:119421] " matz (Yukihiro Matsumoto) via ruby-core
3 siblings, 0 replies; 5+ messages in thread
From: jeremyevans0 (Jeremy Evans) via ruby-core @ 2024-09-12 14:23 UTC (permalink / raw)
To: ruby-core; +Cc: jeremyevans0 (Jeremy Evans)
Issue #20620 has been updated by jeremyevans0 (Jeremy Evans).
I submitted a pull request to implement this: https://github.com/ruby/ruby/pull/11605
In terms of compatibility issues:
* For singleton classes that prepend a module, and have the method defined in both the singleton class and prepended module, `singleton_method` now returns the method in the prepended module.
* Cases where a method is defined in a module prepended to or included in the singleton classes and not in the singleton class itself now result in a `Method` Object being returned, instead of raising `NameError`.
Use of `singleton_method` isn't that common in my experience, so I think we should make the change. There is still time to back it out of 3.4 if it causes issues.
----------------------------------------
Bug #20620: singleton_method undefined for module using "extend self"
https://bugs.ruby-lang.org/issues/20620#change-109727
* Author: dentarg (Patrik Ragnarsson)
* Status: Open
* ruby -v: ruby 3.4.0dev (2024-07-08T21:43:28Z master e500222de1) [x86_64-linux]
* Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN
----------------------------------------
Is this a bug? I expected `ExtendSelf.singleton_method(:foo)` to work when `ExtendSelf.singleton_methods` worked and `:foo` was in the list returned.
```ruby
# singleton_method.rb
class Klass
def self.foo
end
end
module ExtendSelf
extend self
def foo
end
end
p RUBY_DESCRIPTION
p "Klass"
p Klass.singleton_methods # => [:foo]
p Klass.singleton_method(:foo) # => #<Method: Klass.foo() singleton_method.rb:2>
p "ExtendSelf"
p ExtendSelf.singleton_methods # => [:foo]
p ExtendSelf.singleton_method(:foo) # => singleton_method.rb:19:in `singleton_method': undefined singleton method `foo' for `ExtendSelf' (NameError)
```
```shell
$ docker run --rm -it -v $(pwd):/app -w /app rubylang/ruby:master-nightly-jammy
Unable to find image 'rubylang/ruby:master-nightly-jammy' locally
master-nightly-jammy: Pulling from rubylang/ruby
...
Digest: sha256:922037b184b897786a26b2460f70a66139f87dce67f20ddf760cd4186790ed9f
root@9807305c322a:/app# ruby -v
ruby 3.4.0dev (2024-07-08T21:43:28Z master e500222de1) [x86_64-linux]
root@9807305c322a:/app# ruby singleton_method.rb
"ruby 3.4.0dev (2024-07-08T21:43:28Z master e500222de1) [x86_64-linux]"
"Klass"
[:foo]
#<Method: Klass.foo() singleton_method.rb:2>
"ExtendSelf"
[:foo]
singleton_method.rb:21:in 'Kernel#singleton_method': undefined singleton method 'foo' for 'ExtendSelf' (NameError)
```
--
https://bugs.ruby-lang.org/
______________________________________________
ruby-core mailing list -- ruby-core@ml.ruby-lang.org
To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/
^ permalink raw reply [flat|nested] 5+ messages in thread
* [ruby-core:119421] [Ruby master Bug#20620] singleton_method undefined for module using "extend self"
2024-07-09 5:47 [ruby-core:118514] [Ruby master Bug#20620] singleton_method undefined for module using "extend self" dentarg (Patrik Ragnarsson) via ruby-core
` (2 preceding siblings ...)
2024-09-12 14:23 ` [ruby-core:119138] " jeremyevans0 (Jeremy Evans) via ruby-core
@ 2024-10-03 6:53 ` matz (Yukihiro Matsumoto) via ruby-core
3 siblings, 0 replies; 5+ messages in thread
From: matz (Yukihiro Matsumoto) via ruby-core @ 2024-10-03 6:53 UTC (permalink / raw)
To: ruby-core; +Cc: matz (Yukihiro Matsumoto)
Issue #20620 has been updated by matz (Yukihiro Matsumoto).
@jeremyevans0 Thank you. Let us merge the pull-request, and experiment with the preview.
Matz.
----------------------------------------
Bug #20620: singleton_method undefined for module using "extend self"
https://bugs.ruby-lang.org/issues/20620#change-110035
* Author: dentarg (Patrik Ragnarsson)
* Status: Open
* ruby -v: ruby 3.4.0dev (2024-07-08T21:43:28Z master e500222de1) [x86_64-linux]
* Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN
----------------------------------------
Is this a bug? I expected `ExtendSelf.singleton_method(:foo)` to work when `ExtendSelf.singleton_methods` worked and `:foo` was in the list returned.
```ruby
# singleton_method.rb
class Klass
def self.foo
end
end
module ExtendSelf
extend self
def foo
end
end
p RUBY_DESCRIPTION
p "Klass"
p Klass.singleton_methods # => [:foo]
p Klass.singleton_method(:foo) # => #<Method: Klass.foo() singleton_method.rb:2>
p "ExtendSelf"
p ExtendSelf.singleton_methods # => [:foo]
p ExtendSelf.singleton_method(:foo) # => singleton_method.rb:19:in `singleton_method': undefined singleton method `foo' for `ExtendSelf' (NameError)
```
```shell
$ docker run --rm -it -v $(pwd):/app -w /app rubylang/ruby:master-nightly-jammy
Unable to find image 'rubylang/ruby:master-nightly-jammy' locally
master-nightly-jammy: Pulling from rubylang/ruby
...
Digest: sha256:922037b184b897786a26b2460f70a66139f87dce67f20ddf760cd4186790ed9f
root@9807305c322a:/app# ruby -v
ruby 3.4.0dev (2024-07-08T21:43:28Z master e500222de1) [x86_64-linux]
root@9807305c322a:/app# ruby singleton_method.rb
"ruby 3.4.0dev (2024-07-08T21:43:28Z master e500222de1) [x86_64-linux]"
"Klass"
[:foo]
#<Method: Klass.foo() singleton_method.rb:2>
"ExtendSelf"
[:foo]
singleton_method.rb:21:in 'Kernel#singleton_method': undefined singleton method 'foo' for 'ExtendSelf' (NameError)
```
--
https://bugs.ruby-lang.org/
______________________________________________
ruby-core mailing list -- ruby-core@ml.ruby-lang.org
To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2024-10-03 6:53 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-07-09 5:47 [ruby-core:118514] [Ruby master Bug#20620] singleton_method undefined for module using "extend self" dentarg (Patrik Ragnarsson) via ruby-core
2024-07-09 6:45 ` [ruby-core:118516] " jeremyevans0 (Jeremy Evans) via ruby-core
2024-08-01 9:32 ` [ruby-core:118764] " matz (Yukihiro Matsumoto) via ruby-core
2024-09-12 14:23 ` [ruby-core:119138] " jeremyevans0 (Jeremy Evans) via ruby-core
2024-10-03 6:53 ` [ruby-core:119421] " matz (Yukihiro Matsumoto) via ruby-core
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 NNTP newsgroup(s).