Skip to content

Note the receiver class in runtime type error messages - #3195

Open
ksss wants to merge 1 commit into
receiver-context-type-checkfrom
type-check-error-owner
Open

ksss wants to merge 1 commit into
receiver-context-type-checkfrom
type-check-error-owner

Conversation

@ksss

@ksss ksss commented Oct 3, 2026 •

Copy link
Copy Markdown
Collaborator

Stacked on #3194. Please review that one first.

With the receiver context from #3194, a method can be checked against a receiver of a different class than the one the error is reported on. For example, rbs test reports Foo.make called on SubFoo as [Foo.make], and nothing in the message tells which receiver it was.

This PR records the receiver class in the errors and appends it to the message when it differs from the class in the tag:

[Foo.make] ReturnTypeError: expected `instance` but returns `#<Foo>` (receiver: SubFoo)
  • RBS::UnitTest::TypeAssertions now reports errors on the testing target, like rbs test does on the hooked class. Before this, the tag used the receiver's class.
  • The overload warning log shows the receiver note once, instead of in every detail.
  • Errors created without the receiver class get the same messages as before.

🤖 Generated with Claude Code

After the receiver context change, the tag of a runtime type error names
the class the method is checked for: the hooked class in `rbs test`.
When the method is called on a subclass or on a class that includes or
extends a module, the message doesn't tell which receiver it was.

Record the receiver class in the error structs as `receiver_class`, and
append it to `Errors.to_string` when it differs from the class in the
tag:

    [Foo.make] ReturnTypeError: expected `instance` but returns `#<Foo>` (receiver: SubFoo)

`RBS::UnitTest::TypeAssertions` passes the `testing` target as `owner:`,
so assertion failures are tagged the same way. The overload warning log
appends the note once rather than to every detail. Anonymous classes are
shown with `inspect` instead of an empty name.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ksss
ksss force-pushed the type-check-error-owner branch from b9af1e3 to 4395772 Compare October 3, 2026 15:54
@ksss ksss changed the title Report runtime type errors on the class that owns the method Note the receiver class in runtime type error messages Oct 3, 2026
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.

1 participant