[#99002] [Ruby master Feature#17004] Provide a way for methods to omit their return value — shyouhei@...

Issue #17004 has been reported by shyouhei (Shyouhei Urabe).

21 messages 2020/07/01

[#99044] [Ruby master Bug#17007] SystemStackError when using super inside Module included and lexically inside refinement — eregontp@...

Issue #17007 has been reported by Eregon (Benoit Daloze).

7 messages 2020/07/03

[#99078] [Ruby master Feature#17016] Enumerable#scan_left — finch.parker@...

Issue #17016 has been reported by parker (Parker Finch).

42 messages 2020/07/07

[#99079] [Ruby master Bug#17017] Range#max & Range#minmax incorrectly use Float end as max — bosticko@...

Issue #17017 has been reported by sambostock (Sam Bostock).

25 messages 2020/07/07

[#99097] [Ruby master Bug#17021] "arm64" and "arm" are mixed in RbConfig on Apple silicon — watson1978@...

Issue #17021 has been reported by watson1978 (Shizuo Fujita).

9 messages 2020/07/09

[#99115] [Ruby master Bug#17023] How to prevent String memory to be relocated in ruby-ffi — larskanis@...

Issue #17023 has been reported by larskanis (Lars Kanis).

22 messages 2020/07/10

[#99156] [Ruby master Bug#17030] Enumerable#grep{_v} should be optimized for Regexp — marcandre-ruby-core@...

Issue #17030 has been reported by marcandre (Marc-Andre Lafortune).

25 messages 2020/07/13

[#99257] [Ruby master Misc#17041] DevelopersMeeting20200826Japan — mame@...

Issue #17041 has been reported by mame (Yusuke Endoh).

18 messages 2020/07/22

[#99308] [Ruby master Feature#17047] Support parameters for MAIL FROM and RCPT TO — bugs.ruby-lang.org@...

Issue #17047 has been reported by c960657 (Christian Schmidt).

11 messages 2020/07/23

[#99311] [Ruby master Bug#17048] Calling initialize_copy on live modules leads to crashes — XrXr@...

Issue #17048 has been reported by alanwu (Alan Wu).

17 messages 2020/07/24

[#99351] [Ruby master Bug#17052] Ruby with LTO enabled on {aarch64, ppc64le} architectures. — v.ondruch@...

Issue #17052 has been reported by vo.x (Vit Ondruch).

35 messages 2020/07/27

[#99375] [Ruby master Feature#17055] Allow suppressing uninitialized instance variable and method redefined verbose mode warnings — merch-redmine@...

Issue #17055 has been reported by jeremyevans0 (Jeremy Evans).

29 messages 2020/07/28

[#99391] [Ruby master Feature#17059] epoll as IO.select — dsh0416@...

Issue #17059 has been reported by dsh0416 (Delton Ding).

18 messages 2020/07/29

[#99418] [Ruby master Feature#17097] `map_min`, `map_max` — sawadatsuyoshi@...

Issue #17097 has been reported by sawa (Tsuyoshi Sawada).

11 messages 2020/07/31

[ruby-core:99104] [Ruby master Bug#16982] Define instance_methods and so on explicitly on classes generated by DelegateClass

From: merch-redmine@...
Date: 2020-07-09 22:02:55 UTC
List: ruby-core #99104
Issue #16982 has been updated by jeremyevans0 (Jeremy Evans).


I agree that this is a bug, and your pull request is a good way to fix it.  I have squash merged your pull request.  Thank you @pocke!

----------------------------------------
Bug #16982: Define instance_methods and so on explicitly on classes generated by DelegateClass
https://bugs.ruby-lang.org/issues/16982#change-86480

* Author: pocke (Masataka Kuwabara)
* Status: Closed
* Priority: Normal
* ruby -v: ruby 2.8.0dev (2020-06-23T13:58:26Z master dc351ff984) [x86_64-linux]
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN
----------------------------------------
I found two problems with `DelegateClass`.
The patch is available on GitHub. https://github.com/ruby/ruby/pull/3221

# `instance_methods`

First, `instance_methods` method's result does not contain the names of methods that are added after the class is defined.
For example

```ruby
require 'delegate'

class Parent
  def parent_public; end

  protected

  def parent_protected; end
end

class Child < DelegateClass(Parent)
end

class Parent
  def parent_public_added; end

  protected

  def parent_protected_added; end
end

# They're ok.
p Child.instance_methods.include? :parent_public    # => true
p Child.instance_methods.include? :parent_protected # => true

# They're wrong. :parent_public_added and :parent_protected_added should be included, but they are not.
p Child.instance_methods.include? :parent_public_added    # => false
p Child.instance_methods.include? :parent_protected_added # => false
```

So I think `DelegateClass` should define `instance_methods` method explicitly, like `public_instance_methods` and `protected_instance_methods`.

I've added `instance_methods` in this commit https://github.com/ruby/ruby/pull/3221/commits/3f49e3ff094288e41b5629fd07aa8fa858abb196

# `instance_method` and `public_instance_method`

Second, `instance_method` and `public_instance_method` cannot get a method object for methods that are added after the class is defined.
And they cannot get a method object for `:to_s` and so on because of https://github.com/ruby/ruby/blob/fbb32b1f483925987d225b4dc08efd197775bcae/lib/delegate.rb#L390.

For example:

```ruby
require 'delegate'

class Parent
  def parent() end
end

class Child < DelegateClass(Parent)
end

class Parent
  def parent_added() end
end

p Child.instance_method(:parent) # returns an UnboundMethod
p Child.instance_method(:parent_added) # undefined method `parent_added' for class `Child' (NameError)
p Child.instance_method(:to_s) # undefined method `to_s' for class `Child' (NameError)
```

But actually a `Child` instance has all these methods.
So I think `instance_method` method should return a method object.

I actually got the error when I tried to use `rbs prototype runtime`.
https://github.com/ruby/rbs/blob/150bc6e65838eab2be088a5cc456b6f4b04bc81c/lib/rbs/prototype/runtime.rb#L172
This code raises an error when it analyses a class that inherits a class generated by `DelegateClass` method.
For example

```ruby
# test.rb
require 'delegate'

class Parent
end
class Child < DelegateClass(Parent)
end
class Parent
  def foo() end
end
```

```bash
$ rbs prototype runtime --require-relative test.rb  Child 
W, [2020-06-24T21:17:45.628527 #890363]  WARN -- rbs: Skipping anonymous superclass #<Class:0x000056098f280750> of Child
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.8.0/gems/rbs-0.4.0/lib/rbs/prototype/runtime.rb:172:in `instance_method': undefined method `foo' for class `Child' (NameError)
	from /home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.8.0/gems/rbs-0.4.0/lib/rbs/prototype/runtime.rb:172:in `target_method?'
	from /home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.8.0/gems/rbs-0.4.0/lib/rbs/prototype/runtime.rb:210:in `block in generate_methods'
	from /home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.8.0/gems/rbs-0.4.0/lib/rbs/prototype/runtime.rb:210:in `select'
	from /home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.8.0/gems/rbs-0.4.0/lib/rbs/prototype/runtime.rb:210:in `generate_methods'
	from /home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.8.0/gems/rbs-0.4.0/lib/rbs/prototype/runtime.rb:351:in `generate_class'
	from /home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.8.0/gems/rbs-0.4.0/lib/rbs/prototype/runtime.rb:43:in `block in decls'
	from /home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.8.0/gems/rbs-0.4.0/lib/rbs/prototype/runtime.rb:40:in `each'
	from /home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.8.0/gems/rbs-0.4.0/lib/rbs/prototype/runtime.rb:40:in `decls'
	from /home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.8.0/gems/rbs-0.4.0/lib/rbs/cli.rb:455:in `run_prototype'
	from /home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.8.0/gems/rbs-0.4.0/lib/rbs/cli.rb:85:in `run'
	from /home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.8.0/gems/rbs-0.4.0/exe/rbs:7:in `<top (required)>'
	from /home/pocke/.rbenv/versions/trunk/bin/rbs:23:in `load'
	from /home/pocke/.rbenv/versions/trunk/bin/rbs:23:in `<main>'
```

And I also got the same error when I applied the first patch to `instance_methods` method. The first patch broke `ruby/test/ruby/test_method.rb`.
https://github.com/ruby/ruby/blob/d1fb446b62b1e114252606dcf040dd9392f25170/test/ruby/test_method.rb#L1300

I fixed the problem with this commit https://github.com/ruby/ruby/pull/3221/commits/d1fb446b62b1e114252606dcf040dd9392f25170.



-- 
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>

In This Thread

Prev Next