Skip to content

Fall back to standard case/when for out-of-int-range Fixnum literals (#9320)#9435

Merged
headius merged 1 commit into
jruby:masterfrom
sampokuokkanen:fix-gh-9320-case-when-large-fixnum
May 12, 2026
Merged

Fall back to standard case/when for out-of-int-range Fixnum literals (#9320)#9435
headius merged 1 commit into
jruby:masterfrom
sampokuokkanen:fix-gh-9320-case-when-large-fixnum

Conversation

@sampokuokkanen

@sampokuokkanen sampokuokkanen commented May 11, 2026

Copy link
Copy Markdown
Contributor

The gatherLiteralWhenBodies threw an error(NotCompilableException) when the number was too big for a Java integer. Fixed to do this check before going into the optimized path and taking the default path in case we have a fixnum that is too big or small.

Specs added here: ruby/spec#1357. (I will write a regression spec if they are not accepted)

Fixes #9320

…ruby#9320)

The gatherLiteralWhenBodies threw an error(NotCompilableException) when the number was too big for a Java integer. Fixed to do this check before going into the optimized path and taking the default path in case we have a fixnum that is too big or small.
@headius

headius commented May 11, 2026

Copy link
Copy Markdown
Member

Ahh good catch!

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

One minor change and this can merge.


T expr = (T) whenNode.getExpressionNodes();
long exprLong = caseFunction.apply(expr);
if (exprLong > java.lang.Integer.MAX_VALUE) throw notCompilable("optimized case has long-ranged value", caseNode);

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.

Probably should also confirm MIN_VALUE range for consistency.

Suggested change
if (exprLong > java.lang.Integer.MAX_VALUE) throw notCompilable("optimized case has long-ranged value", caseNode);
if (exprLong > java.lang.Integer.MAX_VALUE || exprLong < java.lang.Integer.MIN_VALUE) {
throw notCompilable("optimized case has long-ranged value", caseNode);
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

https://github.com/jruby/jruby/pull/9435/changes#diff-a6d6eca0958acab67ce1b5d6dc08a5b5ea2db5805251e581d4f0affcae4d32c9R1058

There is a MIN_VALUE range check here.

I removed the throw from here because it's now being checked before we get to buildOptimizedCaseWhen.

@sampokuokkanen
sampokuokkanen requested a review from headius May 11, 2026 23:51
@headius
headius merged commit 7df4498 into jruby:master May 12, 2026
109 of 110 checks passed
@headius headius added this to the JRuby 10.1.1.0 milestone May 12, 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.

Cannot run code that has large Integer in when clause

2 participants