Skip to content

Commit

Permalink
fix NoSuchMethodError
Browse files Browse the repository at this point in the history
  • Loading branch information
hrach committed Jun 23, 2021
1 parent 070ab2d commit d9c09d4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
13 changes: 11 additions & 2 deletions agent/android/src/main/kotlin/io/mockk/ValueClassSupport.kt
Expand Up @@ -30,10 +30,19 @@ fun <T : Any> T.boxedValue(): Any? {
* @return class of boxed value, if this is value class, else just class of itself
*/
fun <T : Any> 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<*>
Expand Down
13 changes: 11 additions & 2 deletions agent/jvm/src/main/kotlin/io/mockk/ValueClassSupport.kt
Expand Up @@ -30,10 +30,19 @@ fun <T : Any> T.boxedValue(): Any? {
* @return class of boxed value, if this is value class, else just class of itself
*/
fun <T : Any> 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<*>
Expand Down

0 comments on commit d9c09d4

Please sign in to comment.