Project

General

Profile

Bug #14006

2.5.0preview1でWarning.warnを再定義するとSystemStackErrorが発生する

Added by y-yagi (Yuji Yaginuma) 2 months ago. Updated about 2 months ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
-
ruby -v:
ruby 2.5.0preview1 (2017-10-10 trunk 60153) [x86_64-linux]
[ruby-dev:50293]

Description

下記スクリプトを2.5.0.preview1で実行するとSystemStackErrorが発生します。 なお、下記スクリプトはRuby 2.4.1p111ではエラーが発生せず正常に動作します。

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

なお、再定義の方法を、

def Warning.warn(message) 
  ... 
end 

のように変更すると、エラーが発生せず正常に動作します。

これは意図的な挙動でしょうか?


Related issues

Related to Ruby trunk - Feature #12944: Change Kernel#warn to call Warning.warnClosed

Associated revisions

Revision 60175
Added by nobu (Nobuyoshi Nakada) about 2 months ago

error.c: infinite recursion at Warning#warn

  • error.c (rb_warn_m): write the message to rb_stderr directly, to get rid of infinite recursion when called on Warning module itself, by super in redefined Warning#warn. [Bug #14006]

History

#1 Updated by y-yagi (Yuji Yaginuma) 2 months ago

  • ruby -v set to ruby 2.5.0preview1 (2017-10-10 trunk 60153) [x86_64-linux]

#2 Updated by wanabe (_ wanabe) 2 months ago

  • Related to Feature #12944: Change Kernel#warn to call Warning.warn added

#3 [ruby-dev:50294] Updated by shevegen (Robert A. Heiler) 2 months ago

Sorry that I distract, please ignore me :) - that kanji ッ looks like a smiley face!

No wonder matz recognized the "lonely person staring at the ground" syntax. :D

#4 [ruby-dev:50295] Updated by nobu (Nobuyoshi Nakada) 2 months ago

再定義は Warning.warn にするという想定だったんですが、 Warning#warn の再定義はどうしましょうかねぇ。

#5 Updated by nobu (Nobuyoshi Nakada) about 2 months ago

  • Status changed from Open to Closed

Applied in changeset trunk|r60175.


error.c: infinite recursion at Warning#warn

  • error.c (rb_warn_m): write the message to rb_stderr directly, to get rid of infinite recursion when called on Warning module itself, by super in redefined Warning#warn. [Bug #14006]

Also available in: Atom PDF