summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJeremy Evans <code@jeremyevans.net>2026-05-15 12:01:42 -0700
committerJeremy Evans <code@jeremyevans.net>2026-05-16 10:38:53 -0700
commit9736b7ab56c87b589b8c8a638a019b6bbb19b127 (patch)
tree17d0e3d83e807d97041b6c0ba843c7e287ba455c /test
parentad1415546716a13d00fc7f0435a86b018a1a6731 (diff)
Prohibit super in refined module method
Before, this super could result in a call to a method in BasicObject (or a module included in or prepended to BasicObject), or a call to method_missing for the receiver's class. This explicitly disallows the use of super in such a case, with a specific error message. Fixes [Bug #22071]
Diffstat (limited to 'test')
-rw-r--r--test/ruby/test_refinement.rb37
1 files changed, 37 insertions, 0 deletions
diff --git a/test/ruby/test_refinement.rb b/test/ruby/test_refinement.rb
index daff07ecb0..c3ded524fc 100644
--- a/test/ruby/test_refinement.rb
+++ b/test/ruby/test_refinement.rb
@@ -1035,6 +1035,43 @@ class TestRefinement < Test::Unit::TestCase
RUBY
end
+ def test_prohibit_super_in_refined_module_method
+ assert_separately([], <<-"end;")
+ bug22071 = '[ruby-core:125511] [Bug #22071]'
+ class BasicObject
+ def a; "B" end
+ end
+
+ module G
+ def a; "G" + super end
+ end
+
+ module F
+ include G
+ def a; "F" + super end
+ end
+
+ class A
+ def a; "A" + super end
+ end
+
+ class B < A
+ include F
+ end
+
+ module R
+ refine F do
+ def a; "R"+super end
+ end
+ end
+ using R
+
+ msg = "super in a method in a module that has been refined and that is called via super" +
+ " from a refinement method is not supported."
+ assert_raise(NoMethodError, msg, bug22071) { B.new.a }
+ end;
+ end
+
def test_refine_after_using
assert_separately([], <<-"end;")
bug8880 = '[ruby-core:57079] [Bug #8880]'