Repository navigation
CLR extension methods reach a method group used before using_clr_extensions - #43
Conversation
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Method-group cache invalidation Src/Ruby/Builtins/RubyClass.cs |
PrepareExtensionMethodsUpdate now invalidates subclass method groups using each extension method’s CLR name and, when available, its Ruby-mangled name. |
Extension lookup fixtures and tests Src/IronRuby.Tests/Runtime/ClrTests_Globals.cs, Src/IronRuby.Tests/Runtime/ClrTests.cs, Src/IronRuby.Tests/RubyTests.cs |
Added extension fixtures and registered tests for class, inherited, interface, generic, and LINQ method groups, including behavior before and after extension activation. |
Priority:
Estimated code review effort: 3 (Moderate) | ~20 minutes
Change: Bug fix
Possibly related PRs
- Largo/ironruby#22: Adds method-lookup caches and version guards; both changes address extension-aware method cache invalidation.
Suggested reviewers: largo
Merge Risk: 
Minimal · up to afdef
-
No actionable merge-blocking risk was established. The reported property-getter issue remains outside this change.
Pre-merge checks: 
5
-
Full details: Title check
-
Explanation
The title names the main change: CLR extension methods reaching a method group that was already used before using_clr_extensions. The objectives describe a stale-cache fix in PrepareExtensionMethodsUpdate that clears CLR method groups under both the Ruby name and the CLR name, so the title matches the changeset. The title is specific and identifies the bug area without listing files.
Full details: Docstring Coverage
-
Explanation
Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 1 functions across 4 files.
-
Finishing Touches
-
🧪 Generate unit tests (beta)
-
- Create a new PR
-
- 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.
Comment @coderabbitai help to get the list of available commands.
…nsions
A CLR method group is stored in the method table under the name it was looked
up by: w.describe stores Widget's Describe overloads under "describe". When
using_clr_extensions activated more Describe overloads, the groups were
invalidated under the extension's CLR name, "Describe", so the group under
"describe" survived and kept serving the old overloads. A call that resolved
describe before the activation made describe("x") a TypeError (no conversion
of String into Integer) afterwards, and method(:describe) returned the same
stale group. This affected extensions on a class, on an interface, and on a
generic definition (List[Integer]#count before System::Linq lost
Enumerable.Count's overloads).
The invalidation now covers the mangled name as well as the CLR name.
ClrExtensionMethods6-8 cover a class, its CLR and Ruby subclasses and
method(:describe); an interface and a generic type definition; and
List#count with System::Linq.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2c21b91 to
afdefbf
Compare
A CLR method called before
using_clr_extensionsnever saw the extension overloads the activation added.Without the first
w.describe, the last line returns the extension's result.Cause
IronRuby caches a CLR method group in the class's method table under the name it was looked up by, so
w.describefiles Widget'sDescribeoverloads underdescribe. Whenusing_clr_extensionsadded moreDescribeoverloads,RubyClass.PrepareExtensionMethodsUpdatecleared the cached groups under the CLR nameDescribeand nothing else. The group underdescribesurvived and kept serving the old overloads, andmethod(:describe)returned it too. Callingw.Describeworked, which is what gave the cause away.Extensions on interfaces and generic type definitions went stale the same way. After one
List[Integer]#countcall,using_clr_extensions System::Linqcould no longer addEnumerable.Count's overloads, solist.count(->(x) { x > 1 })raised an ArgumentError.Fix
PrepareExtensionMethodsUpdatenow clears the cached groups under the Ruby name as well as the CLR name, once per distinct name. An exact signature tie still goes to the instance method.Tests
The fixture is a new
IronRubyTests::ExtensionMethods3namespace inClrTests_Globals.cs. Its methods are PascalCase so the Ruby and CLR names differ. The older extension tests all use a lowercasef, which is why none of them caught this.ClrExtensionMethods6covers a class, its C# and Ruby subclasses, the exact tie, theDescribespelling andmethod(:describe).ClrExtensionMethods7covers an interface and a generic class.ClrExtensionMethods8coversList[Integer]#countwithSystem::Linq.All three fail with the fix reverted. The full IronRuby.Tests suite passes on net10.0.
Found, not fixed
A classic extension method named like a property getter, such as
get_Weight(this Widget w), makesw.weightthrow a NullReferenceException once it's activated. The code that builds a property's method group seems to size its array before it drops the methods that aren't compiler-generated accessors, which leaves a null in it.Stack
This is the first of a stack. The next two are open in my fork for now and come here once this merges:
using System::Linq: CLR extension methods scoped like C#'s using directive sholden/ironruby#3 scopes CLR extension methods withusing🤖 Generated with Claude Code
Summary by CodeRabbit
countcalls.