diff --git a/agent/android/src/main/kotlin/io/mockk/ValueClassSupport.kt b/agent/android/src/main/kotlin/io/mockk/ValueClassSupport.kt index 77e432048..d53bf152c 100644 --- a/agent/android/src/main/kotlin/io/mockk/ValueClassSupport.kt +++ b/agent/android/src/main/kotlin/io/mockk/ValueClassSupport.kt @@ -30,10 +30,19 @@ fun T.boxedValue(): Any? { * @return class of boxed value, if this is value class, else just class of itself */ fun T.boxedClass(): KClass<*> { - if (!this::class.isValueClass()) return this::class + return this::class.boxedClass() +} + +/** + * Get the KClass of boxed value if this is a value class. + * + * @return class of boxed value, if this is value class, else just class of itself + */ +fun KClass<*>.boxedClass(): KClass<*> { + if (!this.isValueClass()) return this // get backing field - val backingField = this::class.valueField() + val backingField = this.valueField() // get boxed value return backingField.returnType.classifier as KClass<*> diff --git a/agent/jvm/src/main/kotlin/io/mockk/ValueClassSupport.kt b/agent/jvm/src/main/kotlin/io/mockk/ValueClassSupport.kt index 77e432048..d53bf152c 100644 --- a/agent/jvm/src/main/kotlin/io/mockk/ValueClassSupport.kt +++ b/agent/jvm/src/main/kotlin/io/mockk/ValueClassSupport.kt @@ -30,10 +30,19 @@ fun T.boxedValue(): Any? { * @return class of boxed value, if this is value class, else just class of itself */ fun T.boxedClass(): KClass<*> { - if (!this::class.isValueClass()) return this::class + return this::class.boxedClass() +} + +/** + * Get the KClass of boxed value if this is a value class. + * + * @return class of boxed value, if this is value class, else just class of itself + */ +fun KClass<*>.boxedClass(): KClass<*> { + if (!this.isValueClass()) return this // get backing field - val backingField = this::class.valueField() + val backingField = this.valueField() // get boxed value return backingField.returnType.classifier as KClass<*>