Skip to content

Keep file and line on compiled string range endpoints - #9848

Open
sferik wants to merge 1 commit into
jruby:masterfrom
sferik:string-literal-file
Open

sferik wants to merge 1 commit into
jruby:masterfrom
sferik:string-literal-file

Conversation

@sferik

@sferik sferik commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

Follow-up to @headius's review on #9838.

As far as I can tell, the file on a string literal's FrozenString is always filled in from the scope, and #9838 fixed the one place that wasn't. What's debug-only is the runtime side, which uses the file and line to say where a frozen string was created when you modify it under --debug=frozen-string-literal. That works for string range endpoints in the interpreter, but compiled code dropped the location:

def rng = ("a".."z")
rng.begin << "!"
# interpreter: can't modify frozen String, created at t.rb:1
# JIT and AOT: can't modify frozen String: "a"

The Range operand already has the file and line on both endpoints, so this passes them through ValueCompiler#pushRange to RangeObjectSite for invokedynamic and to newFrozenStringFromRaw for AOT. Each endpoint keeps its own line, in case the range spans lines. Without the debug flag, newFrozenString ignores the file and line, so nothing changes there.

The new spec puts the endpoints on separate lines and checks that both messages include where they were created. It fails in JIT and AOT mode before this change and passes in all four modes after it. The full compiler spec passes with and without invokedynamic.

With --debug=frozen-string-literal, modifying a string range endpoint
in interpreted code reports where the string was created, but compiled
code only says "can't modify frozen String". The IR operands already
carry the file and line; the JIT and AOT range paths just didn't pass
them along.

Follow-up to jruby#9838

@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.

Not a very important case but good to get fixed. We'll let the tests run and see if the couple failures so far are just flaky tests.

@headius headius added this to the JRuby 10.1.3.0 milestone Oct 20, 2026
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.

2 participants