[ruby-core:113903] [Ruby master Bug#19731] Can’t call an instance method inside an Endless method definition

Issue #19731 has been reported by ttanimichi (Tsukuru Tanimichi). ---------------------------------------- Bug #19731: Can’t call an instance method inside an Endless method definition https://bugs.ruby-lang.org/issues/19731 * Author: ttanimichi (Tsukuru Tanimichi) * Status: Open * Priority: Normal * ruby -v: ruby 3.2.2 (2023-03-30 revision e51014f9c0) [arm64-darwin22] * Backport: 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN ---------------------------------------- Can’t call an instance method inside an Endless method definition. ``` $ ruby -v ruby 3.2.2 (2023-03-30 revision e51014f9c0) [arm64-darwin22] $ cat withend.rb class A def show puts 'ok' if params end def params 42 end end A.new.show $ ruby withend.rb ok $ cat endless.rb class A def show = puts 'ok' if params def params 42 end end A.new.show $ ruby endless.rb endless.rb:2:in `<class:A>': undefined local variable or method `params' for A:Class (NameError) def show = puts 'ok' if params ^^^^^^ from endless.rb:1:in `<main>' exit status: 1 ``` But, the example below works fine. Is this an expected behavior? ``` $ cat endless2.rb class A def show = puts params def params 42 end end A.new.show $ ruby endless2.rb 42 ``` -- https://bugs.ruby-lang.org/

Issue #19731 has been updated by mame (Yusuke Endoh). Currently it is an expected behavior because it is parsed as `(def show = puts 'ok') if params`. Related to #19392. ---------------------------------------- Bug #19731: Can’t call an instance method inside an Endless method definition https://bugs.ruby-lang.org/issues/19731#change-103556 * Author: ttanimichi (Tsukuru Tanimichi) * Status: Open * Priority: Normal * ruby -v: ruby 3.2.2 (2023-03-30 revision e51014f9c0) [arm64-darwin22] * Backport: 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN ---------------------------------------- Can’t call an instance method inside an Endless method definition. ``` $ ruby -v ruby 3.2.2 (2023-03-30 revision e51014f9c0) [arm64-darwin22] $ cat withend.rb class A def show puts 'ok' if params end def params 42 end end A.new.show $ ruby withend.rb ok $ cat endless.rb class A def show = puts 'ok' if params def params 42 end end A.new.show $ ruby endless.rb endless.rb:2:in `<class:A>': undefined local variable or method `params' for A:Class (NameError) def show = puts 'ok' if params ^^^^^^ from endless.rb:1:in `<main>' exit status: 1 ``` But, the example below works fine. Is this an expected behavior? ``` $ cat endless2.rb class A def show = puts params def params 42 end end A.new.show $ ruby endless2.rb 42 ``` -- https://bugs.ruby-lang.org/
participants (2)
-
mame (Yusuke Endoh)
-
ttanimichi (Tsukuru Tanimichi)