Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions test/test_error_highlight.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1085,10 +1085,11 @@ def test_args_CALL_1
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.
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.
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.
def test_args_CALL_2
v = []
assert_error_message(TypeError, <<~END) do
no implicit conversion from nil to integer (TypeError)
no implicit conversion #{OF_NIL_INTO_INTEGER} (TypeError)

v[nil]
^^^
Expand All @@ -1115,7 +1116,7 @@ def test_args_ATTRASGN_1
def test_args_ATTRASGN_2
v = []
assert_error_message(TypeError, <<~END) do
no implicit conversion from nil to integer (TypeError)
no implicit conversion #{OF_NIL_INTO_INTEGER} (TypeError)

v [nil] = 1
^^^^^^^^
Expand Down Expand Up @@ -1177,7 +1178,7 @@ def test_args_OP_ASGN1_aref_1
v = []

assert_error_message(TypeError, <<~END) do
no implicit conversion from nil to integer (TypeError)
no implicit conversion #{OF_NIL_INTO_INTEGER} (TypeError)

v [nil] += 42
^^^^^^^^^^
Expand Down