Repository navigation
Conversation
…ective
using_clr_extensions activates a namespace's extension methods for every call
in the runtime: a gem calling it changes what `list.select' means in every
other file. C# scopes them to the files that say `using System.Linq;', and
Ruby has the same notion for refinements, so `using' now accepts a CLR
namespace and brings its extension methods into the rest of the file, class
body or eval string, exactly where a refinement would be active:
using System::Linq
list.where { it > 1 }.order_by { -it }.to_a
`using System::Linq::Enumerable' brings in one static class's extension
methods, as C#'s `using static' does.
Extension methods come last, as in C#, rather than at the extended type's
place in the ancestors: a call that finds a Ruby method calls it
(list.select is Enumerable#select), one that finds a CLR method group gets them
as more overloads (list.count(pred) next to List#Count; an exact tie still goes
to the instance method), and one that finds nothing gets them alone
(list.where). The CLR-cased name (list.Select) still reaches them.
Built on the refinement machinery: a CLR namespace in a scope's `using' list is
part of its RefinementActivation, so methods defined there record it, call
sites guard on it, and send/public_send/method/respond_to? and irb see it. The
namespace's extension methods are filed with the types they extend (including
those of assemblies loaded later) under their CLR and Ruby names, and those
names join the per-(module, name) index stage one introduced - only calls of
those names on those types take the lexical guard. The group a call sees is
cached per class version, name and activation.
A program that `using's System::Linq pays nothing where it makes no LINQ call;
a hot LINQ call costs ~12% more than through using_clr_extensions, for the
guard. using_clr_extensions keeps working as before and now warns, once per
process, that it is deprecated.
ClrScopedExtensions1-4 cover the lexical scope, extension methods coming last
(Ruby method, merged CLR group, extension alone; Widget/Square/Box fixtures),
`using static', and a call bound before the first `using' of the namespace.
The tests of using_clr_extensions expect its one warning.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
… only lexically
The scoped form put extension methods last, behind every Ruby method, so
`using System::Linq' turned list.select from LINQ's Select (what
using_clr_extensions gives) into Enumerable#select, and code moving from one
form to the other had to rename its calls to their CLR names. The scoped form is
meant to be using_clr_extensions confined to a file, class body or eval string,
so it now resolves the same way.
An extension method sits where a refinement of the type it extends would, and a
class's place also has those of the interfaces it implements, as
using_clr_extensions puts both in the class's own CLR method group:
using System::Linq
list.select { it * 2 }.to_a # LINQ's Select, ahead of Enumerable#select
dictionary.select { ... } # LINQ's too, ahead of the IDictionary one
[3, 1].select { it > 1 } # Array#select: Array's ancestors have no IEnumerable[T]
[3, 1].Select { ... } # NoMethodError, as before
A CLR method group anywhere still gets them as more overloads, the instance member
winning an exact tie (list.count(pred), list.reverse). A Ruby method defined
ahead of them wins, and a site bound to them re-binds when one is defined or
removed. A singleton class sees them, as respond_to? and method did under
using_clr_extensions.
Across 13 receivers (List, Integer[], HashSet, Dictionary, an OfType iterator,
a List with a singleton class, Array, Hash, Range, String, Object, ...) and 30
calls, the two forms now print the same, except that a Ruby class including
IEnumerable[Object] gets LINQ through `using' and doesn't through
using_clr_extensions. 101samples.rb prints the same under both with only its
using line changed.
ClrScopedExtensions2 expects LINQ's select; ClrScopedExtensions5 covers Array,
Dictionary, a singleton, Enumerable#where behind LINQ's on a List and ahead of
nothing on an Array, and a Ruby select defined and removed on List[Integer].
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…sions has them using_clr_extensions adds extension methods to the CLR method groups of classes backed by a CLR type, its own and those of its interfaces, and nowhere else. The scoped form also looked at interface modules themselves, so a Ruby class that includes IEnumerable[Object] got LINQ through `using' and nothing through using_clr_extensions. Now only a CLR class's place counts, when deciding whether extensions shadow a Ruby method and when gathering them into a group. Against master (14d53a5), over 20 receivers - CLR collections, a List with a singleton class, Ruby subclasses of List with and without their own select, class objects, Array, Hash, Range, String, Struct, Set, Enumerator - and 30 calls each: `using System::Linq' prints what master's using_clr_extensions does, and a program that `using's it in one module prints, outside that module, what master prints with no activation. using_clr_extensions and no activation print what they print on master. ClrScopedExtensions5 also checks the Ruby class including IEnumerable[Object]. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Src/Samples/Linq/101samples.rb stopped parsing when Ruby stopped accepting a trailing comma in a nested block parameter, |(c,), p|, and nothing ran it after that. Past the parse error it raised a NameError at FirstOrDefault, which names Fixnum, gone since Ruby 3.2. - |(c,), p| is |(c, _), p|. - Fixnum is Integer, which is System::Int32 in IronRuby. - Min: Projection called sum, copied from Sum: Projection, and printed the total length of the words instead of the shortest. It calls min now, through method(:min).of(Object, Integer) as Min: Grouped does. A Func<Object, int> fits both Min(Func<TSource, int>) and Min<TSource, TResult>(Func<TSource, TResult>), and IronRuby can't choose between them where C# picks the first. - Repeat printed its 7s without a newline, so the next heading ran on. - OfType was commented out as an IronRuby bug. It works now. The file still calls using_clr_extensions. Its output is the reference for moving it to `using'. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The samples were the last code outside the tests that called using_clr_extensions, so they printed its deprecation warning. They say `using System::Linq' now. Inside the scope calls resolve as they did under using_clr_extensions, so every call keeps its name, and the output is the same apart from the warning. to_seq, which turns the samples' arrays into the IEnumerable<T> LINQ extends, was a method added to Object for the whole program. It is a refinement of Object now, active below the `using' like the LINQ methods. Nothing in the file calls it before that point. A probe at each of the 119 call sites with a LINQ method's name saw all of them run: 112 reach a System.Linq.Enumerable method, and the other 7 are Array#join on what to_a returned. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Nothing ran Src/Samples/Linq/101samples.rb, so nobody noticed when it stopped parsing. build-and-test now runs it on each OS and target framework, after the socket check, and diffs its stdout and stderr against Src/Samples/Linq/101samples.expected, which holds this branch's output on Linux and net10.0. A wrong answer, an exception or a warning fails the step. Tried locally by putting using_clr_extensions back, which adds its deprecation warning; by changing count(pred) to where(pred); by raising in the middle; and by dropping `using LinqSampleHelpers', which makes to_seq undefined. The sample takes about 1.6 s. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The samples passed every LINQ delegate as lambda { ... }. A block goes to a
method's trailing delegate parameter, so a call whose last argument was a
lambda now takes a block:
numbers.where { |n| n < 5 }, group_by(->(p) { p.category }) { |c, g| ... },
aggregate(start_balance) { |balance, next_withdrawal| ... }. A lambda that
isn't the last argument, such as a key selector before a result selector,
and the make_pair and identity helpers are -> lambdas now.
Two indexed samples keep a lambda. On .NET 9 and later OfType returns one
of LINQ's private iterator classes, whose own public Where(Func<T, bool>)
and Select(Func<T, R>) IronRuby binds to. A block with two parameters fits
those too, because a proc takes any number of arguments, so
digits.where { |digit, index| ... } got nil for index and
numbers.select { |num, index| ... } was ambiguous. A lambda's arity rules
them out. The indexed select_many, take_while and skip_while have no such
methods to compete with and take blocks. Each of the two has a comment.
The output is unchanged, so 101samples.expected is too. A probe at each of
the 119 call sites with a LINQ method's name still sees all of them reach
the same methods as before.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
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]>
|
Warning Review limit reachedYou'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. View limit details
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. Comment |
This was referenced Oct 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Opened upstream from @sholden's branch
sholden:fix/error-message-quotes, unchanged; this is their fork PR sholden#9. It is stacked on #50, so until that merges this diff also shows its commits. The commits this PR adds:The description below is sholden's. Bare PR numbers that were fork-local now point at sholden/ironruby, or at the upstream PR where one exists.
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 inin 'Kernel#require', and so did a few messages. NameError, NoMethodError and most of the others still used the old style:CRuby 4.0 prints
undefined method 'foo' for an instance of Integerandundefined 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 ofUtil/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:
superwith no superclass method names its receiver the way NoMethodError does, and setsNoMethodError#nameand#receiver. It readssuper: 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 inReflectionCache.Generated.cs. I checked that line against the generator's output. Regenerating the whole file would also reorder the hand-inserted entries thatSrc/ClassInitGenerator/README.mddescribes, which has nothing to do with this change, so I left the rest of the file alone.singleton_methodquotes its receiver:undefined singleton method 'x' for 'Foo'.ruby2_keywordsnames the class or module:undefined method 'x' for class 'Foo'. It used to sayfor Foo.remove_class_variablereports a bad name aswrong class variable name x, which is what CRuby says there.class_variable_getand the others keep'x' is not allowed as a class variable name.ndigitsthat doesn't fit an int, forround,floor,ceilandtruncate, gets CRuby's NUM2INT wording. A negative one isinteger -2147483649 too small to convert to 'int', and one past a C long isbignum too big to convert into 'long'. Both used to say "too big to convert to`int'".rb_define_class's, as inZlib is not a module (Class)andStringIO is not a class (Integer).File.expand_path("~")andDir.homewith no HOME and no user database entry saycouldn't find home for uid '54321'on Unix, as CRuby does there. Windows keepscouldn't find HOME environment -- expanding '~'. I checked both rubies underunshare -U --map-user=54321with HOME deleted.BasicSocket#shutdown(5)says`how' should be either :SHUT_RD, :SHUT_WR, :SHUT_RDWRinstead of "either 0, 1, 2". An integer host past 64 bits saysbignum 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
shutdownmessage above, from CRuby'sext/socket. The other is the msgpack gem'sinteger 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.rbhave no CRuby counterpart. They use straight quotes now too.Left alone
Src/Ruby/Compiler/Errors.csstill has backtick-quoted messages. They belong to the LALR parser that prism replaced, and nothing references them.Src/StdLib/ironrubyand CRuby's library underSrc/StdLib/rubystay as they come.Initializers.Generated.cscontains none of these messages, so there was nothing to regenerate.ruby4.rbthat read backtrace lines already accept both quote styles.ruby4.rbdefinesArray#sampletwice. 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
Error messages quote names 'like this', as Ruby 3.4 and 4.0 dohas 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, andquotes.rband both matrices matched CRuby. It also applies cleanly, with the same patch, to the fork's master, 14d53a5.`using' a CLR namespace of another runtime: the error quotes it 'like this'changes the one messageusing System::Linq: CLR extension methods scoped like C#'s using directive #50 added, inModuleOps.cs. It conflicts on master, so it only applies on top ofusing System::Linq: CLR extension methods scoped like C#'s using directive #50.Tests
#if OBSOLETEor commented out ofRubyTests.cs.ErrorMessages_Wording1coverssuper's receiver,remove_class_variable, the NUM2INT wordings and the library name clash. It fails with master's sources.singleton_methodandruby2_keywordscome from the Ruby prelude, which the test runtime doesn't load, so the matrix below covers them.Util/error-message-matrix.rbprints 89 messages, every messagequotes.rbprints and the others listed above, so the comparison can be rerun from the repo. IronRuby prints exactly what CRuby 4.0.7 prints.quotes.rbandUtil/refinement-matrix.rbmatch CRuby exactly once0x[0-9a-f]*becomes0xon both sides.Debug build, net10.0, on Linux, on #50's current head, 1f7acf0, and with this PR on top of it:
The two errors in spec/core/kernel are the same examples before and after.
loadandrequireof 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.rband 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 inString#[]. 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_methodandModule#instance_methodname a different class than CRuby when the receiver has a singleton class. CRuby names the singleton class, soFoo.method(:nope)givesfor class '#<Class:Foo>'. IronRuby names the plain class,for class 'Class', and maps a metaclass to the class it's attached to, soFoo.singleton_class.instance_method(:nope)givesfor class 'Foo'. CRuby only maps it that way forundef_methodandalias_method, which IronRuby already gets right.superfrom a method defined onBasicObjectitself getssuper: no superclass method 'x' for an instance of BasicObject. BasicObject has no superclass to search, and CRuby saysundefined method 'x' for an instance of BasicObjectthere. IronRuby used thesuperwording there before this PR too.Marshal.loadof a_dumpstring that carries an encoding, which is the usual case, doesn't check for_load. It raisesundefined method '_load' for class Xwhere CRuby raisesTypeError: class X needs to have method '_load'.[1, 2].sample(random: r), wherer.randreturns something that isn't an Integer, raises NoMethodError forto_int. CRuby raisesTypeError: no implicit conversion of String into Integer.Foo.allocate, for aDatasubclass thatData.definedidn't make, raisesundefined method 'members' for class Foo. CRuby raisesTypeError: allocator undefined for Foo.Invalid port number or service name: 'x'.. CRuby raises Socket::ResolutionErrorgetaddrinfo(3): Servname not supported for ai_socktype. An integer host between 2**32 and 2**64 becomes an IPv6 address, where CRuby raisesinteger N too big to convert to 'unsigned int'.ndigitsthat fits a C long but not an int, as in1.round(2.0**40), raisesfloat 1099511627776 out of range of integer. CRuby raisesinteger 1099511627776 too big to convert to 'int'.NoMethodError#argsis nil for a missingsuper. CRuby gives the arguments.irsetsENV['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.Digestin Ruby before its C extension loads, so a clash there readsDigest is not a module. IronRuby's C# library saysDigest is not a module (Class).Socket.gethostbynamedoesn't print CRuby's deprecation warning.superin a top-level method doesn't raise. It returns a Method object for the method itself, and master does the same../ir.shraises as CRuby does, so the matrix covers that case. I didn't look into why.Stack
using_clr_extensionsusing System::Linq: CLR extension methods scoped like C#'s using directive #50 scopes CLR extension methods withusing. Its branch now also has 101 LINQ samples:using System::Linq,to_seqas a refinement, blocks, and CI runs them sholden/ironruby#5's LINQ samples.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 messageusing System::Linq: CLR extension methods scoped like C#'s using directive #50 added.🤖 Generated with Claude Code