Skip to content

Give string range endpoints the scope's file name - #9838

Merged
headius merged 1 commit into
jruby:masterfrom
sferik:ir-range-string-file
Oct 20, 2026
Merged

headius merged 1 commit into
jruby:masterfrom
sferik:ir-range-string-file

Conversation

@sferik

@sferik sferik commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

Fixes #9822.

IRBuilder#buildRange turns a string literal endpoint into a FrozenString, but it took the file name from the StrNode, and Node#getFile always returns null. When both endpoints are literals the file never gets used, so "a".."z" was fine. But with a non-literal endpoint, as in "a"..x, or with an endless or beginless range like ("a"..), the FrozenString gets compiled on its own and passes the file to invokedynamic as a bootstrap argument, which ASM rejects with IllegalArgumentException: value null.

This uses scope.getFile(), which is what every other FrozenString in the builder uses.

Endless and beginless string ranges also go through the AOT fallback in NormalValueCompiler#pushRange, which called a RubyRange.newRange overload that doesn't exist. That's the same fix as in #9833, and since the change is identical, the two merge cleanly in either order.

The new spec covers "a"..x, x..."e", ("a"..) and (.."b"). It fails in JIT and AOT mode before this change and passes in all four modes after it.

buildRange turned a string literal endpoint into a FrozenString with
the StrNode's file name, but Node#getFile always returns null. When
both endpoints were literals the file was never used, but a range like
"a"..x or ("a"..) visits the FrozenString on its own, which passes the
file to invokedynamic as a bootstrap argument, and ASM rejects null.
Those methods couldn't be JIT-compiled.

Use scope.getFile(), as every other FrozenString in the builder does.

Endless and beginless string ranges also go through the AOT fallback in
NormalValueCompiler#pushRange, which called a RubyRange.newRange
overload that doesn't exist. This includes the same fix for that as
jruby#9833, so the two merge cleanly in
either order.

Fixes jruby#9822

@headius headius left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Surprising this didn't come up during the initial implementation. I believe that file is only populated during debug runs, to error or warn about modifying a frozen or chilled string. Getting it from the scope is fine, but we may want to revisit that and populate the file since the field is already there and the filename String object would be the same one.

Simple fix, looks good.

@headius headius added this to the JRuby 10.1.3.0 milestone Oct 20, 2026
@headius
headius merged commit c21f032 into jruby:master Oct 20, 2026
135 checks passed
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.

JIT can’t compile a range with one string literal endpoint and one non-literal endpoint (IllegalArgumentException: value null)

2 participants