[ruby-core:123856] [Ruby Bug#21698] Should simple ArgumentError refer to Object?
Issue #21698 has been reported by vo.x (Vit Ondruch). ---------------------------------------- Bug #21698: Should simple ArgumentError refer to Object? https://bugs.ruby-lang.org/issues/21698 * Author: vo.x (Vit Ondruch) * Status: Open * ruby -v: ruby 4.0.0dev (2025-11-18 master 85abc59c32) +PRISM [x86_64-linux] * Backport: 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN ---------------------------------------- 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/7a50eae567260a23d3bbf4d5aaf1a76db43de... and changes like these breaks the compatibility. We already had to apply some [changes for Ruby 3.4](https://src.fedoraproject.org/rpms/rubygem-sass/blob/rawhide/f/rubygem-sass-...) 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?
--
https://bugs.ruby-lang.org/
Issue #21698 has been updated by Eregon (Benoit Daloze). Status changed from Open to Closed It's just #19117 and it's intentional. That feature is missing a NEWS entry though, @mame could you add one? ---------------------------------------- Bug #21698: Should simple ArgumentError refer to Object? https://bugs.ruby-lang.org/issues/21698#change-115255 * Author: vo.x (Vit Ondruch) * Status: Closed * ruby -v: ruby 4.0.0dev (2025-11-18 master 85abc59c32) +PRISM [x86_64-linux] * Backport: 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN ---------------------------------------- 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/7a50eae567260a23d3bbf4d5aaf1a76db43de... and changes like these breaks the compatibility. We already had to apply some [changes for Ruby 3.4](https://src.fedoraproject.org/rpms/rubygem-sass/blob/rawhide/f/rubygem-sass-...) 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?
--
https://bugs.ruby-lang.org/
Issue #21698 has been updated by vo.x (Vit Ondruch). #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. ---------------------------------------- Bug #21698: Should simple ArgumentError refer to Object? https://bugs.ruby-lang.org/issues/21698#change-115256 * Author: vo.x (Vit Ondruch) * Status: Closed * ruby -v: ruby 4.0.0dev (2025-11-18 master 85abc59c32) +PRISM [x86_64-linux] * Backport: 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN ---------------------------------------- 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/7a50eae567260a23d3bbf4d5aaf1a76db43de... and changes like these breaks the compatibility. We already had to apply some [changes for Ruby 3.4](https://src.fedoraproject.org/rpms/rubygem-sass/blob/rawhide/f/rubygem-sass-...) 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?
--
https://bugs.ruby-lang.org/
Issue #21698 has been updated by mame (Yusuke Endoh). 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. ---------------------------------------- Bug #21698: Should simple ArgumentError refer to Object? https://bugs.ruby-lang.org/issues/21698#change-115257 * Author: vo.x (Vit Ondruch) * Status: Closed * ruby -v: ruby 4.0.0dev (2025-11-18 master 85abc59c32) +PRISM [x86_64-linux] * Backport: 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN ---------------------------------------- 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/7a50eae567260a23d3bbf4d5aaf1a76db43de... and changes like these breaks the compatibility. We already had to apply some [changes for Ruby 3.4](https://src.fedoraproject.org/rpms/rubygem-sass/blob/rawhide/f/rubygem-sass-...) 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?
--
https://bugs.ruby-lang.org/
Issue #21698 has been updated by vo.x (Vit Ondruch). Thanks for clarification 👍 ---------------------------------------- Bug #21698: Should simple ArgumentError refer to Object? https://bugs.ruby-lang.org/issues/21698#change-115259 * Author: vo.x (Vit Ondruch) * Status: Closed * ruby -v: ruby 4.0.0dev (2025-11-18 master 85abc59c32) +PRISM [x86_64-linux] * Backport: 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN ---------------------------------------- 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/7a50eae567260a23d3bbf4d5aaf1a76db43de... and changes like these breaks the compatibility. We already had to apply some [changes for Ruby 3.4](https://src.fedoraproject.org/rpms/rubygem-sass/blob/rawhide/f/rubygem-sass-...) 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?
--
https://bugs.ruby-lang.org/
participants (3)
-
Eregon (Benoit Daloze) -
mame (Yusuke Endoh) -
vo.x (Vit Ondruch)