fix: normalize value class arguments in EqMatcher for consistent comparison#1440
Merged
Raibaz merged 1 commit intomockk:masterfrom Oct 24, 2025
Merged
fix: normalize value class arguments in EqMatcher for consistent comparison#1440Raibaz merged 1 commit intomockk:masterfrom
Raibaz merged 1 commit intomockk:masterfrom
Conversation
…arison Extract boxed values from value class arguments in EqMatcher to ensure both expected and actual values are compared at the same level of representation (underlying values vs wrapper objects).
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.
The
eq()(andrefEq()) matcher fails when comparing value classes, resulting in "no answer found" errors when MockK cannot match configured answers to actual method calls.Symptom:
Root Cause:
eq()): Created at test time as a value class wrapper, stored in the matcher before JVM erasure occursThis creates a type mismatch where we're comparing:
DummyValuewrapper containing101Intvalue101The comparison fails because
deepEquals(101, DummyValue(101))returnsfalse.Solution:
Extract the boxed (underlying) value from the expected value class when creating the
EqMatcher, ensuring both sides of the comparison use the same representation.Changes:
EqMatcherto call.boxedValueon both the actual arg and comarpsion valueWithout this fix, the newly added tests in
ValueClassTest.ktfail with "no answer found" errors.I'm not 100% certain this is the optimal location for this fix. The fix works but I'd appreciate input on whether this normalization should happen elsewhere in the matching pipeline or if there's a more appropriate architectural approach for handling value class comparisons.
The fix is backward compatible since
boxedValuereturns the original object unchanged when called on non-value classes.