Skip to content

Port the interop specs that needed C# fixtures; fix the bugs they found - #156

Merged
Largo merged 2 commits into
masterfrom
claude/interop-fixture-specs
Nov 8, 2026
Merged

Largo merged 2 commits into
masterfrom
claude/interop-fixture-specs

Conversation

@Largo

@Largo Largo commented Nov 8, 2026

Copy link
Copy Markdown
Owner

Fixes #144.

Ports the Tests/Interop/net specs that needed C# fixtures. The fixtures are now C# types in the test assembly (IronRubyTests.InteropFixtures in Src/IronRuby.Tests/Runtime/ClrInteropFixtureTests.cs), which the tests load with Runtime.LoadAssembly and include from Ruby.

Test Old spec
ClrInterop_Fields1 / Fields2 fields/access_spec.rb, method/invocation/internal_spec.rb (public/protected; private/internal with PrivateBinding)
ClrInterop_InterfaceImplementation1 interface/implementation_spec.rb, reflection_spec.rb, mapping_spec.rb: overloads, generic interface methods and method_missing called from C#, unimplemented methods
ClrInterop_InterfaceMethods1 interface/methods_spec.rb: a non-public class through its public interface, and an explicit implementation through clr_member
ClrInterop_ExplicitGenericInterfaces1 interface/methods_spec.rb: I3<object>, I3<int>, I3<T>
ClrInterop_AbstractClasses1 class/instantiation/abstract_spec.rb, class/derivation/attribute_spec.rb: super into virtual and abstract methods
ClrInterop_Constructors1 class/fixtures, class/derivation/*, bcl/regressions_spec.rb (CP#2949): [Optional] and defaulted constructors
ClrInterop_Binding*1 (4 tests) method/binding/*_spec.rb, sampled from the cases tagged failing in 2009

Porting them found five bugs, all fixed here:

  1. The failed-member-lookup cache ignored PrivateBinding (RubyClass._clrFailedMemberLookupCache). It is static and shared by all runtimes in the process. A runtime without PrivateBinding cached "privateField is missing", and a later runtime with PrivateBinding got that miss back. The key now includes the setting. Fields2 runs after Fields1 to cover it.
  2. A lambda passed for a bool parameter raised TypeError, while every other object converts by truthiness. The Proc meta-object decided convertibility at narrowing level 0 and returned before the any-to-Boolean rule (Converter.CanConvertFrom).
  3. obj.Event(&nil) subscribed a nil handler (ArgumentNullException) instead of returning the event, as obj.Event does. This broke forwarding with clr_member(I, name).call(*args, &blk). RubyEventInfo now tests the block for nil.
  4. A Ruby subclass of String did not bind to a char parameter where a String does. The DLR looks for op_Explicit/op_Implicit only on the type itself, so MutableString's operators were invisible on MutableString.Subclass. IronRuby's Converter now walks base types, as C# does.
  5. NoMethodError from C# calling an unimplemented abstract method named the class Name@<runtime id>: RubyTypeEmitter.InvokeMethodMissing used RubyContext._Default. It now uses the receiver's context.

Deferred: System::Char passed to double/float goes through to_f (0.0 for 'a'), while decimal gets the code point. That is a design question, filed as #153. The test leaves those rows out and names the issue.

Some 2009 expectations no longer hold, and these are now the asserted behaviour:

  • nil passed to an iterating method gives the C# NullReferenceException, because nil binds as null.
  • CStruct[] does not bind to object[]: CLR array covariance does not cover value types.
  • An object whose singleton class includes Enumerable is not an IEnumerable, because its CLR type is fixed when it is allocated.

Checked:

  • The full IronRuby.Tests suite passes (net10.0).
  • Util/parallel-sweep.sh over ruby/spec core, library, language, command_line and security, this branch against a master build, run from the same tree: identical counts except a known Timeout timing flake and one $LOAD_PATH example. That example only fails because the swept branch binary was built to a separate directory, which moves sitelibdir.

🤖 Generated with Claude Code

The Tests/Interop/net mspec specs deleted in #119 that compiled C# fixtures
from heredocs were never ported: fields by visibility and with PrivateBinding,
Ruby classes implementing .NET interfaces (overloads, generic methods,
method_missing), non-public classes through public interfaces, explicit
generic interface implementations, abstract classes and super, inherited
optional-parameter constructors, CP#2949, and the method binding matrices.

The fixtures are now C# types in IronRuby.Tests (IronRubyTests.InteropFixtures
in Runtime/ClrInteropFixtureTests.cs), and eleven ClrInterop_* tests check the
behaviour. For the binding matrices, the tests sample the inputs the old specs
tagged as failing in 2009. Porting them turned up these bugs:

- RubyClass's cache of failed CLR member lookups is static, shared by every
  runtime in the process, and its key left out PrivateBinding. A runtime
  without it cached "privateField is missing", and a later runtime with
  PrivateBinding got that miss back. The key now includes the setting.
- A Proc or Method passed for a Boolean parameter raised TypeError, while any
  other object is truthy. The Proc's meta-object decided convertibility at
  narrowing level 0 and returned before the any-to-Boolean rule; it now
  answers only for the conversions it supports (delegates).
- obj.Event(&nil) subscribed a nil handler (ArgumentNullException) instead of
  returning the event as obj.Event does. That broke forwarding through
  clr_member(I, name).call(*args, &blk). The rule now tests the block for nil.
- A Ruby subclass of String did not bind to a char parameter where a String
  does. The DLR looks for op_Explicit/op_Implicit only on the type itself, and
  reflection does not inherit statics, so MutableString's operators were not
  found for MutableString.Subclass. IronRuby's Converter now walks the base
  types, as C# does.
- The NoMethodError from C# calling an abstract method that the Ruby class
  does not define named the class "Name@<id>", because it was formatted with
  RubyContext._Default (the first runtime in the process). It now uses the
  receiver's context.

System::Char into double/float (to_f, so 0.0 for 'a') versus decimal (the
code point) is a design question, filed as #153; the test leaves those rows
out and names the issue.

Checked: the full IronRuby.Tests suite (net10.0) passes; ruby/spec core,
library and language were swept against a master build: no new failures
but a known Timeout timing flake and a $LOAD_PATH example that depends on
where the swept binary lives.

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

coderabbitai Bot commented Nov 8, 2026 •

Copy link
Copy Markdown

Explain Change →

Caution

Review failed

The pull request is closed.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

…e-specs

# Conflicts:
#	Src/IronRuby.Tests/RubyTests.cs
@Largo
Largo merged commit 32970ac into master Nov 8, 2026
7 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.

Port the interop specs that need C# fixtures (fields, generic interfaces, abstract super, optional-parameter constructors, binding matrices)

1 participant