Skip to content

Forward-port Bug #21864#74

Merged
hsbt merged 1 commit intomasterfrom
pick-ruby-core
Feb 24, 2026
Merged

Forward-port Bug #21864#74
hsbt merged 1 commit intomasterfrom
pick-ruby-core

Conversation

@hsbt
Copy link
Member

@hsbt hsbt commented Feb 24, 2026

Pick ruby/ruby@d066b9e

[Bug #21864] Refactor type error to be more consistent

[Bug #21864]

Co-Authored-By:  Benoit Daloze <eregontp@gmail.com>
Copilot AI review requested due to automatic review settings February 24, 2026 06:31
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR forwards a bug fix from the main Ruby repository (Bug #21864) that refactors TypeError messages to be more consistent, specifically changing error message format from "from X to Y" to "of X into Y" for implicit conversion errors involving nil and integer.

Changes:

  • Added version-conditional constant OF_NIL_INTO_INTEGER to handle different error message formats across Ruby versions
  • Updated three test cases (test_args_CALL_2, test_args_ATTRASGN_2, test_args_OP_ASGN1_aref_1) to use this constant for version-appropriate error message validation

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

end
end

OF_NIL_INTO_INTEGER = RUBY_VERSION < "4.1." ? "from nil to integer" : "of nil into Integer"
Copy link

Copilot AI Feb 24, 2026

Choose a reason for hiding this comment

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

The version comparison string "4.1." is malformed - it ends with a period but lacks a patch version. This will cause the string comparison to behave unexpectedly. It should likely be "4.1" (without the trailing dot) or "4.1.0" (with a complete version). String comparison with Ruby versions requires proper formatting to work correctly.

Suggested change
OF_NIL_INTO_INTEGER = RUBY_VERSION < "4.1." ? "from nil to integer" : "of nil into Integer"
OF_NIL_INTO_INTEGER = RUBY_VERSION < "4.1.0" ? "from nil to integer" : "of nil into Integer"

Copilot uses AI. Check for mistakes.
end
end

OF_NIL_INTO_INTEGER = RUBY_VERSION < "4.1." ? "from nil to integer" : "of nil into Integer"
Copy link

Copilot AI Feb 24, 2026

Choose a reason for hiding this comment

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

The version check logic appears to be inverted. According to the PR description, this forward-ports a bug fix that makes error messages more consistent by changing "from X to Y" to "of X into Y". However, the condition states that versions less than "4.1." (presumably older versions) will use "from nil to integer" and newer versions will use "of nil into Integer". This seems backward - typically older Ruby versions would have the old message format, and newer versions (after the fix) would have the new format. The condition should likely be checking for versions greater than or equal to a threshold, not less than.

Copilot uses AI. Check for mistakes.
end
end

OF_NIL_INTO_INTEGER = RUBY_VERSION < "4.1." ? "from nil to integer" : "of nil into Integer"
Copy link

Copilot AI Feb 24, 2026

Choose a reason for hiding this comment

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

This constant uses RUBY_VERSION string comparison, which differs from the pattern used elsewhere in this test file. Lines 68-77 define NEW_MESSAGE_FORMAT using a runtime behavior check (attempting an operation and examining the error message). This approach is more reliable because it directly tests the actual behavior. Consider using a similar runtime check for OF_NIL_INTO_INTEGER, such as attempting to index an array with nil and examining the resulting error message format.

Suggested change
OF_NIL_INTO_INTEGER = RUBY_VERSION < "4.1." ? "from nil to integer" : "of nil into Integer"
OF_NIL_INTO_INTEGER = begin
[].fetch(nil)
rescue TypeError => e
if e.message.include?("of nil into Integer")
"of nil into Integer"
else
"from nil to integer"
end
end

Copilot uses AI. Check for mistakes.
@hsbt hsbt merged commit 367c907 into master Feb 24, 2026
11 checks passed
@hsbt hsbt deleted the pick-ruby-core branch February 24, 2026 06:52
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.

3 participants