[#69084] [Ruby trunk - Feature #11124] [Open] [PATCH] lib/*: use monotonic clock for timeouts — normalperson@...
Issue #11124 has been reported by Eric Wong.
5 messages
2015/05/06
[#69138] [Ruby trunk - Feature #11136] [PATCH] webrick: avoid fcntl module — nobu@...
Issue #11136 has been updated by Nobuyoshi Nakada.
3 messages
2015/05/12
[#69160] [Ruby trunk - Feature #11146] [PATCH] variable.c: initialize generic_iv_tbl at start — nobu@...
Issue #11146 has been updated by Nobuyoshi Nakada.
4 messages
2015/05/13
[#69175] Re: [Ruby trunk - Feature #11146] [PATCH] variable.c: initialize generic_iv_tbl at start
— Eric Wong <normalperson@...>
2015/05/13
nobu@ruby-lang.org wrote:
[ruby-core:69108] [Ruby trunk - Bug #11120] Unexpected behavior when mixing Module#prepend with method aliasing
From:
pablodherrero@...
Date:
2015-05-08 21:00:36 UTC
List:
ruby-core #69108
Issue #11120 has been updated by Pablo Herrero.
I gave some more thought to this but I can't really find a way to improve the migration path from aliases to prepend without creating new problems.
I think this issue should be closed.
----------------------------------------
Bug #11120: Unexpected behavior when mixing Module#prepend with method aliasing
https://bugs.ruby-lang.org/issues/11120#change-52353
* Author: Pablo Herrero
* Status: Open
* Priority: Normal
* Assignee:
* ruby -v: ruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-linux]
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN
----------------------------------------
I'm not completely sure myself if this should be considered a bug, but at least it should be up for discussion.
I stumbled upon this behavior when migrating some code using alias chains to Module#prepend.
Consider the following code:
```ruby
# thingy.rb
class Thingy
def thingy
puts "thingy"
end
end
# thingy_with_foo.rb
module ThingyWithFoo
def thingy
puts "thingy with foo"
super
end
end
Thingy.prepend(ThingyWithFoo)
# thingy_with_bar.rb
class Thingy
alias_method :thingy_without_bar, :thingy # Wont't alias create an alias for Thingy#thingy but ThingyWithFoo#thingy instead
def thingy_with_bar
puts "thingy with bar"
thingy_without_bar # Expected to call original Thingy#thingy method but will call prepended method instead
end
alias_method :thingy, :thingy_with_bar
end
# some_file.rb
Thingy.new.thingy # raises: stack level too deep (SystemStackError))
```
In a nutshell when calling `super` from `ThingyWithFoo#foo` it will call `thingy_with_bar` method, and this method will call back to `ThingyWithFoo#foo` by invoking `thingy_without_bar`, thus producing an endless loop.
This situation arises because `alias_method` is producing an alias not for the Thingy#thingy method the but for the upper method from `ThingyWithFoo` instead. May be this behavior could be considered correct, I'm still not sure, but it will probably became a problem for source code migrating from alias chains to use `Modue#prepend`, specially when other active gems could potentially still be using alias chains themselves without the user knowledge.
--
https://bugs.ruby-lang.org/