Skip to content

Two parity divergences: Array.new(2**128) raises the wrong class, and expand_path("~") raises where MRI does not #901

Closed

Description

@tannevaled

Both found while measuring message quoting for #900, and neither is about quoting — so they are filed rather than folded into that PR.

Measured with rubydiff against /opt/homebrew/opt/ruby@4.0/bin/ruby (ruby 4.0.7 (2026-09-15 revision 229531a6cf) +PRISM [arm64-darwin25]) on main at 6e86fac3.

1. Array.new(2**128) raises the wrong class

Array.new(2**128)
class message
MRI 4.0.7 RangeError bignum too big to convert into 'long'
rbgo ArgumentError array size too big

A different class, not just a different message, so rescue RangeError does not catch it. The neighbouring conversions agree — [1][2**128] and "x" * (2**128) both give rbgo's RangeError: bignum too big to convert into 'long' — so Array.new is checking its own size bound before the integer conversion that MRI performs first.

MRI reaches the conversion first because rb_ary_new2 takes a long: NUM2LONG runs on the argument before any size test, and ary_new raises ArgumentError, "array size too big" only for a value that converted successfully and is still out of range. Both errors exist upstream; rbgo reaches the second where MRI reaches the first.

2. File.expand_path("~") raises where MRI does not

ENV.delete("HOME")
File.expand_path("~")
result
MRI 4.0.7 no raise
rbgo ArgumentError: couldn't find HOME environment -- expanding '~'

MRI does have that message — file.c:3908 at v4.0.9, which #900 quotes — but it is not reached here, so there is a fallback rbgo does not have. file.c:3889 is the neighbouring couldn't find login name -- expanding '~', which suggests the fallback is a passwd-database lookup for the current user rather than the environment alone.

I have not confirmed which fallback MRI took, only that it did not raise. That is the first thing to establish before changing anything: a fix built on the guess above would be a fix for a cause nobody read.

Note on scope

Neither affects the #799 version move. Both are plain parity defects on main.

🤖 Generated with Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions