Project

General

Profile

Bug #15720

SystemStackError when referencing a refinement in a module that isn't used

Added by chocolateboy (Chocolate Boy) 9 months ago. Updated 4 months ago.

Status:
Closed
Priority:
Normal
Target version:
-
ruby -v:
ruby 2.7.0dev (2019-03-21 trunk 67332) [x86_64-linux]
[ruby-core:91916]

Description

module M1
  refine Kernel do
    def foo
      'foo called!'
    end
  end
end

module M2
  refine Kernel do
    def bar
      'bar called!'
    end
  end
end

using M1

puts foo
puts bar

Expected:

foo called!
Traceback (most recent call last):
bug.rb:20:in `<main>': undefined local variable or method `bar' for main:Object (NameError)

Actual:

foo called!
Traceback (most recent call last):
bug.rb:20:in `<main>': stack level too deep (SystemStackError)

Platform: Linux (Arch)

ruby -v:

  • ruby 2.7.0dev (2019-03-21 trunk 67332) [x86_64-linux]
  • ruby 2.6.2p47 (2019-03-13 revision 67232) [x86_64-linux]
  • ruby 2.5.5p157 (2019-03-15 revision 67260) [x86_64-linux]

Files

bug.rb (188 Bytes) bug.rb chocolateboy (Chocolate Boy), 03/21/2019 08:07 PM
sse-unused-refinement.patch (1.85 KB) sse-unused-refinement.patch jeremyevans0 (Jeremy Evans), 06/10/2019 10:56 PM

Associated revisions

Revision 5e018214
Added by jeremyevans (Jeremy Evans) 6 months ago

Fix SystemStackError when calling a method in an unused refinement

Fixes [Bug #15720]

Revision 6bb473ea
Added by nagachika (Tomoyuki Chikanaga) 4 months ago

merge revision(s) 5e018214e7435030727a97ac49db038d96438e74: [Backport #15720]

    Fix SystemStackError when calling a method in an unused refinement

    Fixes [Bug #15720]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_6@67729 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 67729
Added by nagachika (Tomoyuki Chikanaga) 4 months ago

merge revision(s) 5e018214e7435030727a97ac49db038d96438e74: [Backport #15720]

Fix SystemStackError when calling a method in an unused refinement

Fixes [Bug #15720]

Revision 470dae33
Added by usa (Usaku NAKAMURA) 4 months ago

merge revision(s) 5e018214e7435030727a97ac49db038d96438e74: [Backport #15720]

    Fix SystemStackError when calling a method in an unused refinement

    Fixes [Bug #15720]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_5@67765 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 67765
Added by usa (Usaku NAKAMURA) 4 months ago

merge revision(s) 5e018214e7435030727a97ac49db038d96438e74: [Backport #15720]

Fix SystemStackError when calling a method in an unused refinement

Fixes [Bug #15720]

History

#1

Updated by chocolateboy (Chocolate Boy) 9 months ago

  • Description updated (diff)
#2

Updated by chocolateboy (Chocolate Boy) 9 months ago

  • Description updated (diff)
#3

Updated by chocolateboy (Chocolate Boy) 9 months ago

  • Description updated (diff)

Updated by jeremyevans0 (Jeremy Evans) 6 months ago

I can confirm this issue. I believe it stems from the fact that in vm_call_method_each_type, cc->me is getting overwritten by ref_me even if they already have the same def but a different defined_class, which results in infinite recursion. The attached patch should fix your example, but my understanding of this code is limited. ko1 or shugo should probably review this patch and determine if it is the proper way to fix this issue. This could possibly be related to #14068.

Updated by nobu (Nobuyoshi Nakada) 6 months ago

Seems fine.
Just rename test_refining_module_repeatedly which redefines an existing method.

#6

Updated by jeremyevans (Jeremy Evans) 6 months ago

  • Status changed from Assigned to Closed

Applied in changeset git|5e018214e7435030727a97ac49db038d96438e74.


Fix SystemStackError when calling a method in an unused refinement

Fixes [Bug #15720]

#7

Updated by nagachika (Tomoyuki Chikanaga) 6 months ago

  • Backport changed from 2.4: UNKNOWN, 2.5: UNKNOWN, 2.6: UNKNOWN to 2.4: UNKNOWN, 2.5: REQUIRED, 2.6: REQUIRED

Updated by nagachika (Tomoyuki Chikanaga) 4 months ago

  • Backport changed from 2.4: UNKNOWN, 2.5: REQUIRED, 2.6: REQUIRED to 2.4: UNKNOWN, 2.5: REQUIRED, 2.6: DONE

ruby_2_6 r67729 merged revision(s) 5e018214e7435030727a97ac49db038d96438e74.

Updated by usa (Usaku NAKAMURA) 4 months ago

  • Backport changed from 2.4: UNKNOWN, 2.5: REQUIRED, 2.6: DONE to 2.4: UNKNOWN, 2.5: DONE, 2.6: DONE

ruby_2_5 r67765 merged revision(s) 5e018214e7435030727a97ac49db038d96438e74.

Also available in: Atom PDF