From d9c09d4b4ee7e6c4ee47f9f9ea2dcb409af03207 Mon Sep 17 00:00:00 2001 From: Jan Skrasek Date: Wed, 23 Jun 2021 10:37:02 +0200 Subject: [PATCH] fix NoSuchMethodError --- .../src/main/kotlin/io/mockk/ValueClassSupport.kt | 13 +++++++++++-- .../src/main/kotlin/io/mockk/ValueClassSupport.kt | 13 +++++++++++-- 2 files changed, 22 insertions(+), 4 deletions(-) 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<*>