Skip to content

Error messages quote names 'like this', as Ruby 3.4 and 4.0 do (rebased) - #62

Merged
Largo merged 2 commits into
masterfrom
carry/52-error-quotes
Oct 29, 2026
Merged

Largo merged 2 commits into
masterfrom
carry/52-error-quotes

Conversation

@Largo

@Largo Largo commented Oct 29, 2026

Copy link
Copy Markdown
Owner

#52 rebased onto master, which now has #50 and #56. The original PR came from @sholden's branch, which still sits on the pre-rebase #50 and conflicts with master. Commits, authorship kept:

  • 0e70a1b Scott Holden: Error messages quote names 'like this', as Ruby 3.4 and 4.0 do
  • 9c6be9d Scott Holden: `using' a CLR namespace of another runtime: the error quotes it 'like this'

No changes in the rebase.

Checked together with #55, all of them merged onto master 62655f8 (Debug, net8.0, Linux): regen-initializers.sh leaves Initializers.Generated.cs unchanged; 0 build warnings; IronRuby.Tests 0 failures; spec/language 2934 examples, 0 failures; spec/core exception, mutex, conditionvariable, refinement, Module#refine/#using, main.using and Kernel#require all 0 failures; the 101 LINQ samples print exactly 101samples.expected; Util/error-message-matrix.rb, refinement-binding-matrix.rb, jit-matrix.rb and condvar-matrix.rb match CRuby 4.0.6 line for line, and refinement-matrix.rb differs only in object addresses.

The description below is from #52 (sholden's).


Ruby 3.4 changed error messages to quote a name with a straight single quote on both sides, 'foo', instead of a backtick and a single quote, `foo'. IronRuby's backtraces already printed the new way, as in in 'Kernel#require', and so did a few messages. NameError, NoMethodError and most of the others still used the old style:

1.foo                           # undefined method `foo' for an instance of Integer
Target.instance_method(:hello)  # undefined method `hello' for class `Target'

CRuby 4.0 prints undefined method 'foo' for an instance of Integer and undefined method 'hello' for class 'Target'. Before this PR, 20 of the 31 messages in my comparison script, quotes.rb, differed from CRuby's, and so did 9 lines of Util/refinement-matrix.rb. master prints the same old-style messages.

What changed

The messages are spread over 19 C# files and IronRuby's Ruby prelude, ruby4.rb. A grep for `{0}' finds 57 of them. Others are spelled differently, such as `~', `long' or `#{name}', so I went through every string literal with a backtick in IronRuby's C# and Ruby code.

Messages CRuby also prints

Each of these now prints what CRuby 4.0.7 prints. I compared them by running both rubies, and read CRuby's source for the few this machine can't trigger. Most only needed the quotes. These needed more:

  • super with no superclass method names its receiver the way NoMethodError does, and sets NoMethodError#name and #receiver. It reads super: no superclass method 'm' for an instance of C, where it used to stop after the method name. The emitted factory, RubyOps.MakeMissingSuperException, now takes the context and the receiver, which changes its line in ReflectionCache.Generated.cs. I checked that line against the generator's output. Regenerating the whole file would also reorder the hand-inserted entries that Src/ClassInitGenerator/README.md describes, which has nothing to do with this change, so I left the rest of the file alone.
  • singleton_method quotes its receiver: undefined singleton method 'x' for 'Foo'.
  • ruby2_keywords names the class or module: undefined method 'x' for class 'Foo'. It used to say for Foo.
  • remove_class_variable reports a bad name as wrong class variable name x, which is what CRuby says there. class_variable_get and the others keep 'x' is not allowed as a class variable name.
  • An ndigits that doesn't fit an int, for round, floor, ceil and truncate, gets CRuby's NUM2INT wording. A negative one is integer -2147483649 too small to convert to 'int', and one past a C long is bignum too big to convert into 'long'. Both used to say "too big to convert to `int'".
  • When a library's class or module name is already taken, the error reads like rb_define_class's, as in Zlib is not a module (Class) and StringIO is not a class (Integer).
  • File.expand_path("~") and Dir.home with no HOME and no user database entry say couldn't find home for uid '54321' on Unix, as CRuby does there. Windows keeps couldn't find HOME environment -- expanding '~'. I checked both rubies under unshare -U --map-user=54321 with HOME deleted.
  • BasicSocket#shutdown(5) says `how' should be either :SHUT_RD, :SHUT_WR, :SHUT_RDWR instead of "either 0, 1, 2". An integer host past 64 bits says bignum too big to convert into 'unsigned long' instead of `quad long'.

Two messages keep their backtick, because CRuby 4.0's still has one. One is the shutdown message above, from CRuby's ext/socket. The other is the msgpack gem's integer 200 too big to convert to `signed char', which msgpack 1.8.5's C extension still prints on CRuby.

IronRuby-only messages

CLR interop errors, the assembly loader's warning, command-line option errors, the foreign-runtime errors and Src/Scripts/CodeGenerator.rb have no CRuby counterpart. They use straight quotes now too.

Left alone

  • Src/Ruby/Compiler/Errors.cs still has backtick-quoted messages. They belong to the LALR parser that prism replaced, and nothing references them.
  • I updated the two comments that quote a message the code prints, and left the other comments alone.
  • The vendored puma and ffi gems under Src/StdLib/ironruby and CRuby's library under Src/StdLib/ruby stay as they come.
  • Initializers.Generated.cs contains none of these messages, so there was nothing to regenerate.
  • Nothing in IronRuby's C# or Ruby code parses these messages. The two regexps in ruby4.rb that read backtrace lines already accept both quote styles.
  • ruby4.rb defines Array#sample twice. The second definition, at line 4791, never takes effect, because the one at line 1277 is defined first. Its message at line 4818 can't print, so I only changed its quotes.

Commits

  1. Error messages quote names 'like this', as Ruby 3.4 and 4.0 do has everything except one line, and it applies to master as well. In a scratch worktree I cherry-picked it onto Largo/ironruby's master, d3a7cf9, which the stack now sits on, and it applied cleanly. It built there, all 793 IronRuby.Tests cases passed, and quotes.rb and both matrices matched CRuby. It also applies cleanly, with the same patch, to the fork's master, 14d53a5.
  2. `using' a CLR namespace of another runtime: the error quotes it 'like this' changes the one message using System::Linq: CLR extension methods scoped like C#'s using directive #50 added, in ModuleOps.cs. It conflicts on master, so it only applies on top of using System::Linq: CLR extension methods scoped like C#'s using directive #50.

Tests

  • 55 lines in 13 IronRuby.Tests files expected the old quotes, and now expect the new ones. I left the lines in tests that never run, under #if OBSOLETE or commented out of RubyTests.cs.
  • New ErrorMessages_Wording1 covers super's receiver, remove_class_variable, the NUM2INT wordings and the library name clash. It fails with master's sources. singleton_method and ruby2_keywords come from the Ruby prelude, which the test runtime doesn't load, so the matrix below covers them.
  • New Util/error-message-matrix.rb prints 89 messages, every message quotes.rb prints and the others listed above, so the comparison can be rerun from the repo. IronRuby prints exactly what CRuby 4.0.7 prints.
  • quotes.rb and Util/refinement-matrix.rb match CRuby exactly once 0x[0-9a-f]* becomes 0x on both sides.

Debug build, net10.0, on Linux, on #50's current head, 1f7acf0, and with this PR on top of it:

Suite Before After
IronRuby.Tests 804 cases, 0 failures 805 cases, 0 failures
spec/language 2935 examples, 0 failures, 0 errors 2935 examples, 0 failures, 0 errors
spec/core/exception 250 examples, 0 failures, 0 errors 250 examples, 0 failures, 0 errors
spec/core/kernel 2232 examples, 0 failures, 2 errors 2232 examples, 0 failures, 2 errors
spec/core/module 1050 examples, 0 failures, 0 errors 1050 examples, 0 failures, 0 errors

The two errors in spec/core/kernel are the same examples before and after. load and require of an unreadable file raise Errno::EACCES instead of LoadError.

I also ran the specs for the other messages this changes, before and after: spec/core/{marshal,signal,class,basicobject,data,integer,float,rational,method,unboundmethod}, process/kill_spec.rb, dir/home_spec.rb, file/expand_path_spec.rb, string/multiply_spec.rb, string/element_reference_spec.rb and spec/library/socket/basicsocket. That's 2731 examples, with the same 20 errors before and after: 15 in core/integer, 4 in core/rational and 1 in String#[]. No spec started passing, since these specs accept either quote style.

CI ran on this PR's current head and all 7 jobs passed. IronRuby.Tests had no failures on Ubuntu and Windows, with net8.0 and net10.0, the 101 LINQ samples printed their expected output in all four of those jobs, and spec/language passed all 2935 examples on both frameworks.

Found, not fixed

These came up while I checked messages against CRuby. They're behaviour differences rather than wording, so I left them for separate PRs.

  • Kernel#method, #public_method and Module#instance_method name a different class than CRuby when the receiver has a singleton class. CRuby names the singleton class, so Foo.method(:nope) gives for class '#<Class:Foo>'. IronRuby names the plain class, for class 'Class', and maps a metaclass to the class it's attached to, so Foo.singleton_class.instance_method(:nope) gives for class 'Foo'. CRuby only maps it that way for undef_method and alias_method, which IronRuby already gets right.
  • super from a method defined on BasicObject itself gets super: no superclass method 'x' for an instance of BasicObject. BasicObject has no superclass to search, and CRuby says undefined method 'x' for an instance of BasicObject there. IronRuby used the super wording there before this PR too.
  • Marshal.load of a _dump string that carries an encoding, which is the usual case, doesn't check for _load. It raises undefined method '_load' for class X where CRuby raises TypeError: class X needs to have method '_load'.
  • [1, 2].sample(random: r), where r.rand returns something that isn't an Integer, raises NoMethodError for to_int. CRuby raises TypeError: no implicit conversion of String into Integer.
  • Foo.allocate, for a Data subclass that Data.define didn't make, raises undefined method 'members' for class Foo. CRuby raises TypeError: allocator undefined for Foo.
  • A service name that getaddrinfo doesn't know raises SocketError Invalid port number or service name: 'x'.. CRuby raises Socket::ResolutionError getaddrinfo(3): Servname not supported for ai_socktype. An integer host between 2**32 and 2**64 becomes an IPv6 address, where CRuby raises integer N too big to convert to 'unsigned int'.
  • A Float ndigits that fits a C long but not an int, as in 1.round(2.0**40), raises float 1099511627776 out of range of integer. CRuby raises integer 1099511627776 too big to convert to 'int'.
  • NoMethodError#args is nil for a missing super. CRuby gives the arguments.
  • ir sets ENV['HOME'] at startup when it isn't set, to the working directory if the user database has no entry. So the new ~ message only shows after a script deletes HOME. CRuby leaves HOME unset.
  • CRuby defines Digest in Ruby before its C extension loads, so a clash there reads Digest is not a module. IronRuby's C# library says Digest is not a module (Class).
  • Socket.gethostbyname doesn't print CRuby's deprecation warning.
  • In the hosted runtime IronRuby.Tests uses, super in a top-level method doesn't raise. It returns a Method object for the method itself, and master does the same. ./ir.sh raises as CRuby does, so the matrix covers that case. I didn't look into why.

Stack

  1. CLR extension methods reach a method group used before using_clr_extensions #43, which Largo merged, fixed stale CLR overloads after using_clr_extensions
  2. Refinements: only refined calls pay, and the JIT and OSR keep working #49 makes refinements cost nothing where they can't change a call
  3. using System::Linq: CLR extension methods scoped like C#'s using directive #50 scopes CLR extension methods with using. Its branch now also has 101 LINQ samples: using System::Linq, to_seq as a refinement, blocks, and CI runs them sholden/ironruby#5's LINQ samples.
  4. This PR, stacked on using System::Linq: CLR extension methods scoped like C#'s using directive #50. Its first commit, 33d4264, also applies to master on its own. The second changes a message using System::Linq: CLR extension methods scoped like C#'s using directive #50 added.

🤖 Generated with Claude Code

sholden and others added 2 commits October 29, 2026 19:32
Ruby 3.4 changed its messages to quote a name with a straight quote on both
sides, 'foo', where it used to open with a backtick, `foo'. IronRuby's
backtraces and some of its messages had moved over, but NameError,
NoMethodError and most of the rest still printed the old form:

  1.foo   # undefined method `foo' for an instance of Integer

Every message with a CRuby counterpart now prints what CRuby 4.0 prints. I
checked each one against ruby 4.0.7, and against its source for the few this
machine can't reach. The IronRuby-only messages, for CLR interop, the loader
and command-line options, quote the same way. Some messages said more or less
than CRuby's beyond the quotes, and now match it:

- `super' with no superclass method names its receiver as NoMethodError
  does, and sets NoMethodError#name and #receiver:
  "super: no superclass method 'm' for an instance of C". The emitted
  factory now takes the context and the receiver, which changes its
  ReflectionCache entry; the new line is the one the generator writes.
- singleton_method quotes the receiver, "for 'Foo'", and ruby2_keywords
  names the class or module, "for class 'Foo'".
- remove_class_variable reports a bad name as "wrong class variable name x".
- An ndigits that doesn't fit an int reads as NUM2INT's does: "too small"
  when negative, "bignum too big to convert into 'long'" past a C long.
- A library's class or module whose name is taken reads as
  rb_define_class's "Zlib is not a module (Class)".
- "~" with no HOME and no user database entry names the uid, on Unix.
- BasicSocket#shutdown's range error and an integer host past 64 bits use
  CRuby's wording.

Two keep a backtick because CRuby's still has one: BasicSocket#shutdown's
"`how' should be either :SHUT_RD, :SHUT_WR, :SHUT_RDWR", and the msgpack
gem's "too big to convert to `signed char'".

The 55 lines of IronRuby.Tests that expected the old quotes now expect the
new ones. ErrorMessages_Wording1 covers the wordings above that the test
runtime reaches, and Util/error-message-matrix.rb prints 89 messages,
including those raised by the Ruby prelude, identically under CRuby 4.0 and
./ir.sh.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… this'

Scoped extension methods added the TypeError that `using' raises for a CLR
namespace belonging to another runtime. The previous commit also applies to
master, where that message doesn't exist, so it leaves the message out.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@coderabbitai

coderabbitai Bot commented Oct 29, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 59 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 1623d4a2-100b-42a2-9a3d-70199ebe12ae
Commits

Reviewing files that changed from the base of the PR and between 62655f8 and 9c6be9d.

Files ignored due to path filters: 1
  • Src/Ruby/Compiler/ReflectionCache.Generated.cs is excluded by !**/*.generated.*
Files selected for processing: 38
  • Src/IronRuby.Tests/RubyTests.cs
  • Src/IronRuby.Tests/Runtime/AliasTests.cs
  • Src/IronRuby.Tests/Runtime/BlockTests.cs
  • Src/IronRuby.Tests/Runtime/ClrProtocolTests.cs
  • Src/IronRuby.Tests/Runtime/ClrTests.cs
  • Src/IronRuby.Tests/Runtime/DlrInteropTests.cs
  • Src/IronRuby.Tests/Runtime/EvalTests.cs
  • Src/IronRuby.Tests/Runtime/HostingTests.cs
  • Src/IronRuby.Tests/Runtime/InitializerTests.cs
  • Src/IronRuby.Tests/Runtime/MethodTests.cs
  • Src/IronRuby.Tests/Runtime/MiscTests.cs
  • Src/IronRuby.Tests/Runtime/SingletonTests.cs
  • Src/IronRuby.Tests/Runtime/SuperTests.cs
  • Src/IronRuby.Tests/Runtime/UndefTests.cs
  • Src/Libraries/Builtins/ClassOps.cs
  • Src/Libraries/Builtins/FileOps.cs
  • Src/Libraries/Builtins/KernelOps.cs
  • Src/Libraries/Builtins/Marshal.cs
  • Src/Libraries/Builtins/MethodOps.cs
  • Src/Libraries/Builtins/ModuleOps.cs
  • Src/Libraries/Builtins/MutableStringOps.cs
  • Src/Libraries/Builtins/PosixSignals.cs
  • Src/Libraries/Extensions/ClrStringOps.cs
  • Src/Libraries/Extensions/NumericRounding.cs
  • Src/Libraries/Extensions/TypeGroupOps.cs
  • Src/Libraries/Socket/BasicSocket.cs
  • Src/Ruby/Builtins/RubyClass.cs
  • Src/Ruby/Builtins/RubyModule.cs
  • Src/Ruby/Hosting/RubyOptionsParser.cs
  • Src/Ruby/Runtime/Calls/RubyCallAction.cs
  • Src/Ruby/Runtime/Loader.cs
  • Src/Ruby/Runtime/RubyContext.cs
  • Src/Ruby/Runtime/RubyExceptions.cs
  • Src/Ruby/Runtime/RubyOps.cs
  • Src/Ruby/Runtime/RubyUtils.cs
  • Src/Scripts/CodeGenerator.rb
  • Src/StdLib/ironruby/ruby4.rb
  • Util/error-message-matrix.rb
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Largo
Largo merged commit 64d632d into master Oct 29, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants