Skip to content

Fix Scala 3 shouldReturn/mustReturn inference for polymorphic methods#652

Merged
TimvdLippe merged 1 commit into
mockito:release/2.xfrom
jozic:fix/scala3-polymorphic-shouldreturn
Apr 9, 2026
Merged

Fix Scala 3 shouldReturn/mustReturn inference for polymorphic methods#652
TimvdLippe merged 1 commit into
mockito:release/2.xfrom
jozic:fix/scala3-polymorphic-shouldreturn

Conversation

@jozic

@jozic jozic commented Apr 9, 2026

Copy link
Copy Markdown
Contributor

Discovered this during testing on some projects
Scala 3 types the mocked call before it sees the value passed to shouldReturn/mustReturn. For polymorphic methods that can widen the inferred return type too much, so this adds direct single-value overloads that let inference use both sides of the stub.
I added a shared test that runs for all scala versions

@jozic jozic marked this pull request as ready for review April 9, 2026 11:51
@jozic

jozic commented Apr 9, 2026

Copy link
Copy Markdown
Contributor Author

@TimvdLippe please take a look, small fix, not critical, but good for parity
no rush
thank you!

@TimvdLippe TimvdLippe left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some real type system shenanigans going on here, but seems fair to me.

@TimvdLippe TimvdLippe merged commit 9f3755e into mockito:release/2.x Apr 9, 2026
5 checks passed
@jozic jozic deleted the fix/scala3-polymorphic-shouldreturn branch April 9, 2026 12:03
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.

2 participants