File tree Expand file tree Collapse file tree 1 file changed +70
-0
lines changed
Expand file tree Collapse file tree 1 file changed +70
-0
lines changed Original file line number Diff line number Diff line change @@ -1189,6 +1189,76 @@ def test
11891189 } , call_threshold : 2
11901190 end
11911191
1192+ # Test that including a module after compilation correctly changes the super target.
1193+ # The included module's method should be called, not the original super target.
1194+ def test_invokesuper_with_include
1195+ assert_compiles '["B", "M"]' , %q{
1196+ class A
1197+ def foo
1198+ "A"
1199+ end
1200+ end
1201+
1202+ class B < A
1203+ def foo
1204+ ["B", super]
1205+ end
1206+ end
1207+
1208+ def test
1209+ B.new.foo
1210+ end
1211+
1212+ test # profile invokesuper (super -> A#foo)
1213+ test # compile with super -> A#foo
1214+
1215+ # Now include a module in B that defines foo - super should go to M#foo instead
1216+ module M
1217+ def foo
1218+ "M"
1219+ end
1220+ end
1221+ B.include(M)
1222+
1223+ test # should call M#foo, not A#foo
1224+ } , call_threshold : 2
1225+ end
1226+
1227+ # Test that prepending a module after compilation correctly changes the super target.
1228+ # The prepended module's method should be called, not the original super target.
1229+ def test_invokesuper_with_prepend
1230+ assert_compiles '["B", "M"]' , %q{
1231+ class A
1232+ def foo
1233+ "A"
1234+ end
1235+ end
1236+
1237+ class B < A
1238+ def foo
1239+ ["B", super]
1240+ end
1241+ end
1242+
1243+ def test
1244+ B.new.foo
1245+ end
1246+
1247+ test # profile invokesuper (super -> A#foo)
1248+ test # compile with super -> A#foo
1249+
1250+ # Now prepend a module that defines foo - super should go to M#foo instead
1251+ module M
1252+ def foo
1253+ "M"
1254+ end
1255+ end
1256+ A.prepend(M)
1257+
1258+ test # should call M#foo, not A#foo
1259+ } , call_threshold : 2
1260+ end
1261+
11921262 def test_invokebuiltin
11931263 # Not using assert_compiles due to register spill
11941264 assert_runs '["."]' , %q{
You can’t perform that action at this time.
0 commit comments