Skip to content

Add specs for case/when with out-of-int-range Integer literals#1357

Merged
eregon merged 1 commit into
ruby:masterfrom
sampokuokkanen:case-if-fixnum-bignum-literals
May 18, 2026
Merged

Add specs for case/when with out-of-int-range Integer literals#1357
eregon merged 1 commit into
ruby:masterfrom
sampokuokkanen:case-if-fixnum-bignum-literals

Conversation

@sampokuokkanen
Copy link
Copy Markdown
Contributor

Add specs covering case/when and if with Integer literals outside 32-bit int range (10_000_000_000, -3_000_000_000) and beyond 64-bit long range (1 << 100).

Existing case/when specs only exercised small Integers, so optimized implementations whose codepaths diverge at the int/long boundary were not covered.

Found coverage missing when looking at jruby/jruby#9320.

Comment thread language/case_spec.rb Outdated
it "matches an arbitrary-precision Integer literal" do
huge = 1 << 100
case huge
when 1 << 100; true
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.

This is not a literal though, so I think you need to paste the actual value here to test what you want

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.

Thanks, should be fixed now.

Comment thread language/case_spec.rb Outdated
it "dispatches correctly with mixed small and large Integer literals" do
pick = -> x {
case x
when 1 << 100 then :beyond_long
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.

Same here

Comment thread language/if_spec.rb Outdated
Comment on lines +150 to +174
it "compares against an Integer literal whose value does not fit in a 32-bit int" do
x = 10_000_000_000
if x == 10_000_000_000
:match
else
:miss
end.should == :match

y = -3_000_000_000
if y == -3_000_000_000
:match
else
:miss
end.should == :match
end

it "compares against an arbitrary-precision Integer literal" do
x = 1 << 100
if x == 1 << 100
:match
else
:miss
end.should == :match
end

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.

I would drop these, correct Integer#== should imply those to pass

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.

Dropped this.

Add specs covering case/when with Integer literals outside
32-bit int range (10_000_000_000, -3_000_000_000) and beyond 64-bit
long range (1 << 100).

Existing case/when specs only exercised small Integers, so optimized
implementations whose codepaths diverge at the int/long boundary were
not covered.
@sampokuokkanen sampokuokkanen force-pushed the case-if-fixnum-bignum-literals branch from ab79607 to 6227f8a Compare May 18, 2026 11:29
@sampokuokkanen sampokuokkanen requested a review from eregon May 18, 2026 11:30
@sampokuokkanen sampokuokkanen changed the title Add specs for case/when and if with out-of-int-range Integer literals Add specs for case/when with out-of-int-range Integer literals May 18, 2026
Copy link
Copy Markdown
Member

@eregon eregon left a comment

Choose a reason for hiding this comment

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

Thanks!

@eregon eregon merged commit 9b460cd into ruby:master May 18, 2026
14 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.

2 participants