Skip to content

mruby-regexp: rename __match_pattern to __check_pattern - #7005

Merged
matz merged 1 commit into
mruby:masterfrom
takumin:regexp-check-pattern-rename
Aug 3, 2026
Merged

mruby-regexp: rename __match_pattern to __check_pattern#7005
matz merged 1 commit into
mruby:masterfrom
takumin:regexp-check-pattern-rename

Conversation

@takumin

@takumin takumin commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

The pattern type check is a single C function serving six String methods,
but it is still named after the two it was written for.

caller string_regexp.rb
String#match :14
String#match? :20
String#sub :45
String#gsub :72
String#scan :115
String#split :153

Line numbers are those of 8f85a84, the current master.

match and match? are two of six now, so the name points at a minority
of the callers.

__check_pattern names what the helper does rather than who calls it. It
is a check: an accepted argument comes back untouched, anything else
raises, and no caller treats the return value as a conversion.

  • match and match? compile an accepted String themselves.
  • sub, gsub and scan quote it first.
  • split never sees one: nil and String patterns have already gone to
    __split by then, so that branch is unreachable.

The C function regexp_match_pattern()
is renamed to regexp_check_pattern() in the same change, so the mismatch
is not moved from the Ruby side of the binding to the C side.

The private __check_pattern on the
StringMatchHelperOverride
test subclass is renamed too. It is not a caller, but the assertion built
on it is that a same-named method on the receiver cannot widen what the
check accepts, and that only means anything while the name matches the
helper.

Compatibility

None affected. __check_pattern is an undocumented __-prefixed helper,
and the rename changes no observable behaviour.

Why this was not folded into #7001

#7001 is what widened the caller set, and the rename was kept out of it
deliberately: it touches the match and match? lines, which #7001 does
not go near, and CONTRIBUTING.md asks that a pull request not mix
several things. The comment above the C function was updated there to name
all six callers instead, so the name and the reality did not contradict
each other in the meantime.

Testing

rake test passes: 1922 OK, 0 KO, 18 skipped (all pre-existing).

Summary by CodeRabbit

  • Bug Fixes
    • Updated regular expression pattern validation across string matching, substitution, scanning, splitting, quoting, and compilation operations.
    • Preserved existing behavior while improving consistency in pattern checking.

The helper was named after `String#match` and `String#match?`, the two
methods it was written for. It now serves six: `sub`, `gsub`, `scan` and
`split` check their pattern through it as well, so the name points at a
minority of its callers.

`__check_pattern` names what the helper does instead. It is a check and
nothing more: an accepted argument comes back untouched and anything else
raises. No caller uses the return value as a conversion. `match` and
`match?` compile an accepted String themselves, `sub`, `gsub` and `scan`
quote it first, and in `split` the String branch is unreachable because
nil and String patterns have already gone to `__split`.

The C function is renamed alongside the Ruby name, so the mismatch is not
merely moved from one side of the binding to the other. The private
`__check_pattern` on the `StringMatchHelperOverride` test subclass follows
too: that test asserts a same-named method on the receiver cannot widen
what the check accepts, which only holds while the name matches.

`__check_pattern` is an undocumented `__`-prefixed helper and the rename
changes no observable behaviour.
@takumin
takumin requested a review from matz as a code owner August 3, 2026 08:15
@coderabbitai

coderabbitai Bot commented Aug 3, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The regexp pattern-validation helper is renamed from __match_pattern to __check_pattern. String regexp methods and the related test override now use the renamed helper without changing validation or matching behavior.

Changes

Regexp pattern helper rename

Layer / File(s) Summary
Rename the Regexp validation helper
mrbgems/mruby-regexp/src/regexp.c
The internal helper and registered class method are renamed to __check_pattern while retaining argument validation.
Update String regexp callers and test override
mrbgems/mruby-regexp/mrblib/string_regexp.rb, mrbgems/mruby-regexp/test/regexp.rb
String regexp methods and the test helper use __check_pattern; existing behavior remains unchanged.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

  • mruby/mruby#6994: Introduced the Regexp.__match_pattern helper used by these String regexp methods.
  • mruby/mruby#7001: Updated the shared regexp pattern-validation helper used by these methods.

Suggested reviewers: matz, nattzn

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely identifies the main change: renaming the private helper from __match_pattern to __check_pattern.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@mrbgems/mruby-regexp/src/regexp.c`:
- Line 1160: Preserve the existing public Regexp.__match_pattern API by
retaining or adding a class-method alias alongside the updated internal method
registration in regexp_check_pattern. Update internal mruby-regex and Ruby
callers to use the new method as needed, while ensuring direct callers of
__match_pattern continue to resolve compatibly.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: c4b81380-4019-4336-a129-e468b0e03cde

📥 Commits

Reviewing files that changed from the base of the PR and between 8f85a84 and 51099e5.

📒 Files selected for processing (3)
  • mrbgems/mruby-regexp/mrblib/string_regexp.rb
  • mrbgems/mruby-regexp/src/regexp.c
  • mrbgems/mruby-regexp/test/regexp.rb

Comment thread mrbgems/mruby-regexp/src/regexp.c
@matz
matz merged commit c25f3fb into mruby:master Aug 3, 2026
21 checks passed
@takumin
takumin deleted the regexp-check-pattern-rename branch August 3, 2026 10:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants