* [ruby-dev:50964] [Ruby master Bug#14006] 2.5.0preview1でWarning.warnを再定義するとSystemStackErrorが発生する
[not found] <redmine.issue-14006.20171012021319.13352@ruby-lang.org>
@ 2020-10-01 20:40 ` eregontp
0 siblings, 0 replies; only message in thread
From: eregontp @ 2020-10-01 20:40 UTC (permalink / raw)
To: ruby-dev
Issue #14006 has been updated by Eregon (Benoit Daloze).
I think the `SystemStackError` is expected in that case.
By default there is Warning (which `extend self`) with Warning#warn and Kernel#warn.
Using `super` in Warning#warn calls Kernel#warn which calls Warning.warn which is resolved to Warning#warn, etc.
One should not define Warning#warn, but instead Warning.warn, or better `prepend` a module to Warning.
----------------------------------------
Bug #14006: 2.5.0preview1でWarning.warnを再定義するとSystemStackErrorが発生する
https://bugs.ruby-lang.org/issues/14006#change-87848
* Author: y-yagi (Yuji Yaginuma)
* Status: Closed
* Priority: Normal
* ruby -v: ruby 2.5.0preview1 (2017-10-10 trunk 60153) [x86_64-linux]
* Backport: 2.3: UNKNOWN, 2.4: UNKNOWN
----------------------------------------
下記スクリプトを2.5.0.preview1で実行するとSystemStackErrorが発生します。 なお、下記スクリプトはRuby 2.4.1p111ではエラーが発生せず正常に動作します。
~~~ ruby
# warning_test.rb
module Warning
def warn(message)
return if message.match?("warning: possibly useless use of a variable in void context")
super
end
end
@a
~~~
バックトレースは下記の通りです。
~~~
ruby -v warning_test.rb
ruby 2.5.0preview1 (2017-10-10 trunk 60153) [x86_64-linux]
warning_test.rb:9: warning: possibly useless use of a variable in void context
warning_test.rb:2: warning: method redefined; discarding old warn
Traceback (most recent call last):
7580: from warning_test.rb:9:in `<main>'
7579: from warning_test.rb:5:in `warn'
7578: from warning_test.rb:5:in `warn'
7577: from warning_test.rb:5:in `warn'
7576: from warning_test.rb:5:in `warn'
7575: from warning_test.rb:5:in `warn'
7574: from warning_test.rb:5:in `warn'
7573: from warning_test.rb:5:in `warn'
... 7568 levels...
4: from warning_test.rb:5:in `warn'
3: from warning_test.rb:5:in `warn'
2: from warning_test.rb:5:in `warn'
1: from warning_test.rb:5:in `warn'
warning_test.rb:5:in `warn': stack level too deep (SystemStackError)
~~~
なお、再定義の方法を、
~~~ ruby
def Warning.warn(message)
...
end
~~~
のように変更すると、エラーが発生せず正常に動作します。
これは意図的な挙動でしょうか?
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2020-10-01 20:40 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <redmine.issue-14006.20171012021319.13352@ruby-lang.org>
2020-10-01 20:40 ` [ruby-dev:50964] [Ruby master Bug#14006] 2.5.0preview1でWarning.warnを再定義するとSystemStackErrorが発生する eregontp
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).