Skip to content

Commit

Permalink
merge revision(s) 18ee7c9,4a6384ed9358e8fb8464f6e37efb5477182f01db: […
Browse files Browse the repository at this point in the history
…Backport #20246] (#10309)

Clear all refined CCs on reopening refinement mod

	In cfd7729 we started using inline
	caches for refinements. However, we weren't clearing inline caches when
	defined on a reopened refinement module.

	Fixes [Bug #20246]

	Fix [Bug #20246]: Don't set next_head_exact if a capture is called (#9897)
  • Loading branch information
nurse committed Mar 21, 2024
1 parent b2c2702 commit 0578789
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion regcomp.c
Original file line number Diff line number Diff line change
Expand Up @@ -3395,7 +3395,7 @@ next_setup(Node* node, Node* next_node, regex_t* reg)
}
else if (type == NT_ENCLOSE) {
EncloseNode* en = NENCLOSE(node);
if (en->type == ENCLOSE_MEMORY) {
if (en->type == ENCLOSE_MEMORY && !IS_ENCLOSE_CALLED(en)) {
node = en->target;
goto retry;
}
Expand Down
17 changes: 17 additions & 0 deletions test/ruby/test_refinement.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1606,18 +1606,35 @@ def m
end
using R
def m
C.new.m
end
assert_equal(:foo, C.new.m)
assert_equal(:foo, m)
module R
refine C do
assert_equal(:foo, C.new.m)
assert_equal(:foo, m)
alias m m
assert_equal(:foo, C.new.m)
assert_equal(:foo, m)
def m
:bar
end
assert_equal(:bar, C.new.m, "[ruby-core:71423] [Bug #11672]")
assert_equal(:bar, m, "[Bug #20285]")
end
end
assert_equal(:bar, C.new.m, "[ruby-core:71423] [Bug #11672]")
assert_equal(:bar, m, "[Bug #20285]")
end;
end

Expand Down
5 changes: 5 additions & 0 deletions test/ruby/test_regexp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2045,6 +2045,11 @@ def test_bug_20212 # [Bug #20212]
100.times.each { assert(regex.match?(string)) }
end

def test_bug_20246 # [Bug #20246]
assert_equal '1.2.3', '1.2.3'[/(\d+)(\.\g<1>){2}/]
assert_equal '1.2.3', '1.2.3'[/((?:\d|foo|bar)+)(\.\g<1>){2}/]
end

def test_linear_time_p
assert_send [Regexp, :linear_time?, /a/]
assert_send [Regexp, :linear_time?, 'a']
Expand Down
1 change: 1 addition & 0 deletions vm_method.c
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ rb_clear_method_cache(VALUE klass_or_module, ID mid)
VALUE refined_class = rb_refinement_module_get_refined_class(module);
rb_clear_method_cache(refined_class, mid);
rb_class_foreach_subclass(refined_class, clear_iclass_method_cache_by_id_for_refinements, mid);
rb_clear_all_refinement_method_cache();
}
rb_class_foreach_subclass(module, clear_iclass_method_cache_by_id, mid);
}
Expand Down

0 comments on commit 0578789

Please sign in to comment.