From: "vo.x (Vit Ondruch) via ruby-core" Date: 2025-11-19T13:16:58+00:00 Subject: [ruby-core:123858] [Ruby Bug#21698] Should simple ArgumentError refer to Object? 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 '
' $ 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 '
' $ 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 '
' ~~~ 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](https://src.fedoraproject.org/rpms/rubygem-sass/blob/rawhide/f/rubygem-sass-3.7.4-Support-caller-format-change-in-ruby3.4.patch) 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/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/