From e4409d43cf0cbbab3a2779e915fb86cf8406fb23 Mon Sep 17 00:00:00 2001 From: Johannes Link Date: Tue, 12 Mar 2024 14:50:47 +0100 Subject: [PATCH] Trying a fix for https://github.com/jqwik-team/jqwik/issues/557 --- .../jqwik/kotlin/internal/KotlinReflectionSupport.kt | 3 +++ .../kotlin/internal/SuspendedPropertyMethodsHook.kt | 5 ++++- .../test/java/net/jqwik/kotlin/java/JavaProperty.java | 10 ++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 kotlin/src/test/java/net/jqwik/kotlin/java/JavaProperty.java diff --git a/kotlin/src/main/kotlin/net/jqwik/kotlin/internal/KotlinReflectionSupport.kt b/kotlin/src/main/kotlin/net/jqwik/kotlin/internal/KotlinReflectionSupport.kt index e249b892b..9d90e6cf3 100644 --- a/kotlin/src/main/kotlin/net/jqwik/kotlin/internal/KotlinReflectionSupport.kt +++ b/kotlin/src/main/kotlin/net/jqwik/kotlin/internal/KotlinReflectionSupport.kt @@ -15,6 +15,9 @@ fun Class<*>.isKotlinClass(): Boolean = declaredAnnotations.any { it.annotationC val Parameter.kotlinParameter: KParameter? get() { + if (!this.declaringExecutable.declaringClass.isKotlinClass()) { + return null + } if (isSuspendFunctionContinuationParameter()) { return null } diff --git a/kotlin/src/main/kotlin/net/jqwik/kotlin/internal/SuspendedPropertyMethodsHook.kt b/kotlin/src/main/kotlin/net/jqwik/kotlin/internal/SuspendedPropertyMethodsHook.kt index 6543061b7..c417c0ca3 100644 --- a/kotlin/src/main/kotlin/net/jqwik/kotlin/internal/SuspendedPropertyMethodsHook.kt +++ b/kotlin/src/main/kotlin/net/jqwik/kotlin/internal/SuspendedPropertyMethodsHook.kt @@ -38,7 +38,10 @@ class SuspendedPropertyMethodsHook : ResolveParameterHook, InvokePropertyMethodH } private fun AnnotatedElement.isSuspendFunction() = - this is Method && this.kotlinFunction?.isSuspend ?: false + this is Method + // Added because of https://github.com/jqwik-team/jqwik/issues/557 + && this.declaringClass.isKotlinClass() + && this.kotlinFunction?.isSuspend ?: false override fun resolve( parameterContext: ParameterResolutionContext, diff --git a/kotlin/src/test/java/net/jqwik/kotlin/java/JavaProperty.java b/kotlin/src/test/java/net/jqwik/kotlin/java/JavaProperty.java new file mode 100644 index 000000000..3869067e8 --- /dev/null +++ b/kotlin/src/test/java/net/jqwik/kotlin/java/JavaProperty.java @@ -0,0 +1,10 @@ +package net.jqwik.kotlin.java; + +import net.jqwik.api.*; + +class JavaProperty { + + @Property + void aProperty(@ForAll int anInt) { + } +}