Skip to content

Route Kernel#readline through ARGF.readline - #9808

Open
zev wants to merge 1 commit into
jruby:jruby-10.0from
zev:kernel-readline-via-argf
Open

zev wants to merge 1 commit into
jruby:jruby-10.0from
zev:kernel-readline-via-argf

Conversation

@zev

@zev zev commented Oct 15, 2026

Copy link
Copy Markdown
Contributor

Follow-up to #9785, as discussed there (headius: "I support both the Kernel.readline => ARGF move and the deprecation cleanups").

MRI's rb_f_readline calls ARGF.readline (argf_readline directly when the receiver is ARGF, otherwise forward). JRuby's Kernel#readline called Kernel#gets and raised EOFError on nil. That differs from MRI in two observable ways, both measured in this comment:

Case CRuby 4.1 jruby-10.0 this PR
StringIO $stdin: readline; readline; [$., ARGF.lineno] [0, 0] [2, 2] [0, 0]
def ARGF.readline(*) = "patched\n"; readline "patched\n" "a\n" "patched\n"
def ARGF.gets(*) = "patched\n"; readline "a\n" "patched\n" "a\n"

The last row is the compatibility risk: code that stubs ARGF.gets to feed a top-level readline stops working, and code that stubs ARGF.readline starts working. That is the CRuby behavior.

Changes

  • RubyKernel.readline mirrors Kernel#gets: RubyArgsFile.readline when recv is ARGF, otherwise a forwarded readline call.
  • KernelSites gets a readline call site next to gets.
  • New spec: Kernel#readline calls ARGF.readline (fails on jruby-10.0 with the mock never receiving readline, passes here).

Testing

mspec ci over core/{kernel,argf,io}: 4503 examples, 2 failures. Those are the same two Kernel#require ... c-extension file exists but loading fails failures as unmodified jruby-10.0.

🤖 Generated with Claude Code

MRI's rb_f_readline calls ARGF.readline (argf_readline directly when
the receiver is ARGF, otherwise forward). Kernel#readline called
Kernel#gets and raised EOFError on nil, so a non-IO $stdin had its
lines counted in ARGF.lineno and ARGF.readline overrides were ignored.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@zev
zev marked this pull request as ready for review October 16, 2026 02:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant