Some fixes for Scala 3 mock-method metadata#641
Merged
TimvdLippe merged 1 commit intoMar 27, 2026
Conversation
Contributor
Author
|
@TimvdLippe please check this out. Thanks! |
TimvdLippe
approved these changes
Mar 27, 2026
TimvdLippe
left a comment
Contributor
There was a problem hiding this comment.
Nice comments! Despite my minimal Scala knowledge, I was able to understand why these fixes were required.
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.
I was testing these on real projects and figured out some issues for Scala 3 mock-method metadata implementation: overloaded methods conflict, storing primitives in value classes cache. Also added some docs explaining how
mockmethod should be wrapped (if needed) in Scala 3More details
Overload dedup by symbol, not fullName.
In Scala 3, all overloads of a method share the same Symbol.fullName. The old mutable.Set[String] dedup kept only the first overload encountered, silently dropping e.g. a vararg overload that shared a name with plain overloads. Changed to mutable.Set[Symbol] — each overload is a distinct symbol, so all survive.
isPrimitiveType guard in returnsValueClassFor.
Int <:< AnyValis true at Scala's type level, so without an explicit check,returnsValueClassFor(TypeRepr.of[Int])would return true and primitive-returning methods would be wrongly stored as value-class returns. The guard prevents false positives.Only true entries go into the returnsValueClass cache.
The old code stored (method, false) for every method; the new code stores only true entries.
getReturnsValueClassreturning None is the same signal as false — the cache can be smaller and the intent is clearer.ReflectionUtils.returnsValueClass — remove broken fallback
The old fallback classOf[AnyVal].isAssignableFrom(returnType) compiled to classOf[Object].isAssignableFrom(returnType) in Scala 3, returning true for every reference type. With only-true cache entries this fallback is also unnecessary — getOrElse(false) is correct and safe.
MockCreator scaladoc + note in README — inline wrapper requirement explained
plus new tests to verify the fixes