Skip to content

fix: Stop using return-type assignability for generic call matching - #989

Merged
dtchepak merged 1 commit into
nsubstitute:mainfrom
zvirja:fix-974-return-type-equivalence
Aug 9, 2026
Merged

fix: Stop using return-type assignability for generic call matching#989
dtchepak merged 1 commit into
nsubstitute:mainfrom
zvirja:fix-974-return-type-equivalence

Conversation

@zvirja

@zvirja zvirja commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Fixes #974
Closes #977

This is the proper fix to the original issue. We have a plenty of scenarios when we have to see if return types are cross-compatible. That makes sense for parameters, but not for the return types. For the return types we don't need to support assignable types and that breaks the scenario in the issue. Fix it by passing an explicit flag and disable equivalency test for return types, while keeping it for parameters.

I will also make a follow up PR to name assignability check more strict (to better cater for in/out and be safer).

@zvirja
zvirja requested a review from dtchepak August 9, 2026 07:24
@dtchepak
dtchepak merged commit b9bac29 into nsubstitute:main Aug 9, 2026
4 checks passed
@zvirja
zvirja deleted the fix-974-return-type-equivalence branch August 9, 2026 19:36
This was referenced Aug 11, 2026
This was referenced Aug 15, 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.

Configuring two returns on the same generic method with inheritance-related type arguments throws InvalidCastException

2 participants