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?

Updated by Eregon (Benoit Daloze) about 5 hours ago Actions #1 [ruby-core:123857]

  • Status changed from Open to Closed

It's just #19117 and it's intentional.
That feature is missing a NEWS entry though, @mame (Yusuke Endoh) could you add one?

Updated by vo.x (Vit Ondruch) about 4 hours ago Actions #2 [ruby-core:123858]

#19117 was closed more then a year ago, therefore I'd assume it was part of Ruby 3.4. But I am pointing out change between Ruby 3.4 and 4.0discussing. But there are also exceptions such as #20275, so maybe this is the case for another one?

But anyway, it is not big deal for me. So if everybody agrees that Object should be referenced for such simple script, then I'll be happy if NEWS provided some reference.

Updated by mame (Yusuke Endoh) about 3 hours ago Actions #3 [ruby-core:123859]

Displaying the method owner class was decided in #19117. The fact that it was not displayed for "wrong number of arguments" errors was simply a bug due to an oversight.

We were aware at the time of #19117 that this change would be incompatible with tests that inspect error messages, and the decision was made with that in mind. Ideally, we could have introduced the incompatibilities in a single update, so I am sorry for missing the "wrong number of arguments" case.

I will update NEWS accordingly.

Updated by vo.x (Vit Ondruch) about 1 hour ago Actions #4 [ruby-core:123861]

Thanks for clarification 👍

Actions

Also available in: PDF Atom