Skip to content

mruby-regexp: fix wrong comments on the String#split override - #7065

Merged
matz merged 1 commit into
mruby:masterfrom
takumin:regexp-split-alias-comment
Aug 10, 2026
Merged

mruby-regexp: fix wrong comments on the String#split override#7065
matz merged 1 commit into
mruby:masterfrom
takumin:regexp-split-alias-comment

Conversation

@takumin

@takumin takumin commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Three comments around the String#split override describe mechanisms that are not
there. Comments only; no behavior change.

__split is a Ruby alias, not a C one

mrbgems/mruby-regexp/mrblib/string_regexp.rb says:

  # Regexp-aware split.  Falls back to the C-defined split (aliased as
  # `__split` in mrb_mruby_regexp_gem_init before this override loads) for
  # nil or string patterns, and handles regexp patterns in Ruby.

__split is not installed anywhere in C. mrb_mruby_regexp_gem_init() defines
Regexp and MatchData and their methods only, and never touches String;
nothing under mrbgems/mruby-regexp/src/ mentions __split. The alias is made
in Ruby, at the top of the class body in the same file:

  alias __split split

The fix points the parenthetical there:

  # Regexp-aware split.  Falls back to the C-defined split (aliased as
  # `__split` above) for nil or string patterns, and handles regexp patterns
  # in Ruby.

That is the wording the file already uses for its three other captured methods.
String#[] reads "Falls back to the C-defined [] (aliased as __aref
above)", and String#[]= and String#slice! say the same for __aset and
__slice_bang. Deleting the clause instead would leave split the only one of
the four saying nothing about where its fallback comes from.

The bintest repeats it

mrbgems/mruby-bin-mruby/bintest/mruby.rb makes the same claim about the same
helper, so it is corrected in the same change.

__to_int no longer exists

Inside the override, the limit conversion is explained as:

    # `__to_int` is `mrb_ensure_integer_type()`, which asks the object nothing.

Two things are wrong with the one line. __to_int was bound to
mrb_ensure_int_type(), not mrb_ensure_integer_type(); the two differ on a
BigInt, which the first narrows and the second returns unchanged. And __to_int
is gone: it was removed by the change closing #7014, which replaced the call with
Integer.__ensure(limit). The same comment block already names __ensure five
lines on, so the paragraph contradicted itself. It now reads:

    # `Integer.__ensure` is `mrb_ensure_int_type()`, which asks the object nothing.

Testing

The change touches comments only, so there is nothing to reproduce and no
behavior to compare against CRuby. ruby -c passes on both edited files.

Summary by CodeRabbit

  • Documentation

    • Clarified internal comments describing how String#split delegates to its aliased implementation.
    • Documented the integer conversion helper used by String#split.
    • Updated regression test commentary for improved accuracy.
  • Bug Fixes

    • No runtime behavior changes.

The comment above the `String#split` override says `__split` is aliased in
`mrb_mruby_regexp_gem_init` before mrblib loads. Nothing under
`mrbgems/mruby-regexp/src/` mentions `__split`, and
`mrb_mruby_regexp_gem_init()` defines `Regexp` and `MatchData` and their
methods only; it never touches `String`. The alias is made in Ruby, at the
top of the class body in the same file.

Point the parenthetical at that alias, matching what the three other
captured methods in the file already say: `String#[]` reads "aliased as
`__aref` above", and `String#[]=` and `String#slice!` say the same for
`__aset` and `__slice_bang`. Deleting the clause instead would leave
`split` the only one of the four saying nothing about where its fallback
comes from.

The bintest for the same helper repeats the claim, so correct it there too.

Fix the line above the limit conversion as well. It calls the conversion
`__to_int` and names `mrb_ensure_integer_type()` behind it. `__to_int` was
bound to `mrb_ensure_int_type()`, which differs on a BigInt, and the method
is gone: the call is `Integer.__ensure(limit)` now, which the rest of the
same comment block already names.

Comments only; no behavior change.
@takumin
takumin requested a review from matz as a code owner August 10, 2026 08:27
@coderabbitai

coderabbitai Bot commented Aug 10, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 7aa50386-f7f6-481c-8ff1-0d5305630a60

📥 Commits

Reviewing files that changed from the base of the PR and between 8ad6907 and c2f4928.

📒 Files selected for processing (2)
  • mrbgems/mruby-bin-mruby/bintest/mruby.rb
  • mrbgems/mruby-regexp/mrblib/string_regexp.rb

📝 Walkthrough

Walkthrough

Updated comments for String#split delegation and integer conversion. Executable behavior and public declarations remain unchanged.

Changes

String split documentation

Layer / File(s) Summary
Update String#split comments
mrbgems/mruby-bin-mruby/bintest/mruby.rb, mrbgems/mruby-regexp/mrblib/string_regexp.rb
Comments now describe the local __split alias and Integer.__ensure helper.

Estimated code review effort: 1 (Trivial) | ~2 minutes

Possibly related PRs

  • mruby/mruby#7001: Changes the String#split implementation and adds pattern type validation.
  • mruby/mruby#7006: Modifies String#split and its internal alias-based dispatch.
  • mruby/mruby#7045: Concerns String#split and the documented __split/Integer.__ensure flow.

Suggested reviewers: matz

🚥 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 describes the correction of inaccurate comments for the String#split override.
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.

@matz
matz merged commit cedd9cb into mruby:master Aug 10, 2026
21 checks passed
@takumin
takumin deleted the regexp-split-alias-comment branch August 10, 2026 11:08
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