Bug #21698
closedShould simple ArgumentError refer to Object?
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:
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?