Repository navigation
A method declared for one instantiation is refused on another; it was accepted and read the receiver at the wrong type (#3508) - #3509
Merged
Conversation
… accepted and read the receiver at the wrong type (#3508)
This was referenced Nov 21, 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.
Closes #3508.
The defect. Methods are found by the type's name. A method declared in
impl Box[str]was therefore accepted on aBox[isize], and its body read the receiver's payload at the wrong type: an integer as text, in safe code with nounsafe.The fix. Where a method call has resolved its method (beside the visibility check),
check_method_declared_forcompares the receiver with the instantiation the method'simplnames. When they differ the call is refused:An
impl[T]block, and an impl whose target names a bare type parameter, are unaffected.Routes tried against the wrong instantiation, all refused: a direct call, the method as a value (
Box[isize].shout,Box[str].shoutapplied to the wrong value), the type-qualified call, a call on an indexed element, a pipeline stage.Tests:
err_3508_method_of_another_instantiation(shown failing on the installed compiler first) andbehav_3508_method_of_its_own_instantiation(a call, through a borrow, as a method value, and animpl[T]method on another instantiation).No spec words: §9 already says a method belongs to the type its
implnames.Battery green;
:release-checksgreen.