Project

General

Profile

Actions

Bug #21698

closed

Should simple ArgumentError refer to Object?

Bug #21698: Should simple ArgumentError refer to Object?

Added by vo.x (Vit Ondruch) about 5 hours ago. Updated about 1 hour ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 4.0.0dev (2025-11-18 master 85abc59c32) +PRISM [x86_64-linux]
[ruby-core:123856]

Description

Having this simple test file:

$ cat test.rb
def foo(x, y)
end

foo(1)

This is the Ruby 3.4 behavior:

$ ruby --disable-gems test.rb 
test.rb:1:in 'foo': wrong number of arguments (given 1, expected 2) (ArgumentError)
        from test.rb:4:in '<main>'

$ ruby -v
ruby 3.4.7 (2025-10-08 revision 7a5688e2a2) +PRISM [x86_64-linux]

While Ruby 4.0 refers to Object in the backtrace:

$ ruby --disable-gems test.rb
test.rb:1:in 'Object#foo': wrong number of arguments (given 1, expected 2) (ArgumentError)
        from test.rb:4:in '<main>'

$ ruby -v
ruby 4.0.0dev (2025-11-18 master 85abc59c32) +PRISM [x86_64-linux]

While this is certainly correct, I also think it is a bit confusing, because the code does not explicitly refer to Object. This likely comes as a result of #21543, but I think that there the original proposal for such simple case was different.

I am also not convinced that the did_you_mean output really helps:

$ ruby test.rb
test.rb:1:in 'Object#foo': wrong number of arguments (given 1, expected 2) (ArgumentError)

    caller: test.rb:4
    | foo(1)
      ^^^
    callee: test.rb:1
    | def foo(x, y)
          ^^^
        from test.rb:4:in '<main>'

But maybe I should just get used to it 🤷

Just FTR, I have come here trying to fix the following Sass gem test suite error on Fedora:

  1) Failure:
SassScriptTest#test_shallow_argument_error_unwrapped [test/sass/script_test.rb:704]:
--- expected
+++ actual
@@ -1 +1,3 @@
-"wrong number of arguments (1 for 0) for `arg-error'"
+# encoding: ASCII-8BIT
+#    valid: true
+"wrong number of arguments (given 1, expected 0) for `arg-error'"

The problem there is that Sass is trying to parse the backtrace:

https://github.com/sass/ruby-sass/blob/7a50eae567260a23d3bbf4d5aaf1a76db43dec32/lib/sass/script/tree/funcall.rb#L303-L310

and changes like these breaks the compatibility. We already had to apply some changes for Ruby 3.4 and this is yet another breakage. This is the actual difference:

--- ruby-3.4
+++ ruby-4.0
@@ -1,3 +1,3 @@
 > e.backtrace
 => 
-["/builddir/build/BUILD/rubygem-sass-3.7.4-build/sass-3.7.4/usr/share/gems/gems/sass-3.7.4/test/sass/script_test.rb:11:in 'arg_error'",
+["/builddir/build/BUILD/rubygem-sass-3.7.4-build/sass-3.7.4/usr/share/gems/gems/sass-3.7.4/test/sass/script_test.rb:11:in 'Sass::Script::Functions::UserFunctions#arg_error'",

Contrary to my original point, in this case the backtrace might be better. Maybe this needs more polishing?

Actions

Also available in: PDF Atom