diff --git a/interop/ksp/src/main/kotlin/com/squareup/kotlinpoet/ksp/KsTypes.kt b/interop/ksp/src/main/kotlin/com/squareup/kotlinpoet/ksp/KsTypes.kt index d1379383e2..3c57aad046 100644 --- a/interop/ksp/src/main/kotlin/com/squareup/kotlinpoet/ksp/KsTypes.kt +++ b/interop/ksp/src/main/kotlin/com/squareup/kotlinpoet/ksp/KsTypes.kt @@ -182,14 +182,15 @@ public fun KSTypeArgument.toTypeName( public fun KSTypeReference.toTypeName( typeParamResolver: TypeParameterResolver = TypeParameterResolver.EMPTY, ): TypeName { + val type = resolve() return when (val elem = element) { is KSCallableReference -> { LambdaTypeName.get( receiver = elem.receiverType?.toTypeName(typeParamResolver), parameters = elem.functionParameters.map { ParameterSpec.unnamed(it.type.toTypeName(typeParamResolver)) }, returnType = elem.returnType.toTypeName(typeParamResolver), - ).copy(nullable = resolve().isMarkedNullable) + ).copy(nullable = type.isMarkedNullable, suspending = type.isSuspendFunctionType) } - else -> resolve().toTypeName(typeParamResolver, element?.typeArguments.orEmpty()) + else -> type.toTypeName(typeParamResolver, element?.typeArguments.orEmpty()) } } diff --git a/interop/ksp/test-processor/src/main/kotlin/com/squareup/kotlinpoet/ksp/test/processor/TestProcessor.kt b/interop/ksp/test-processor/src/main/kotlin/com/squareup/kotlinpoet/ksp/test/processor/TestProcessor.kt index 3d9db1e1cf..fb0a5f014c 100644 --- a/interop/ksp/test-processor/src/main/kotlin/com/squareup/kotlinpoet/ksp/test/processor/TestProcessor.kt +++ b/interop/ksp/test-processor/src/main/kotlin/com/squareup/kotlinpoet/ksp/test/processor/TestProcessor.kt @@ -173,7 +173,7 @@ class TestProcessor(private val env: SymbolProcessorEnvironment) : SymbolProcess function.parameters.map { parameter -> // Function references can't be obtained from a resolved KSType because it resolves to FunctionN<> which // loses the necessary context, skip validation in these cases as we know they won't match. - val typeName = if (parameter.type.resolve().isFunctionType) { + val typeName = if (parameter.type.resolve().run { isFunctionType || isSuspendFunctionType }) { parameter.type.toTypeName(functionTypeParams) } else { parameter.type.toValidatedTypeName(functionTypeParams) diff --git a/interop/ksp/test-processor/src/test/kotlin/com/squareup/kotlinpoet/ksp/test/processor/TestProcessorTest.kt b/interop/ksp/test-processor/src/test/kotlin/com/squareup/kotlinpoet/ksp/test/processor/TestProcessorTest.kt index c54c1e22da..06bf588d9d 100644 --- a/interop/ksp/test-processor/src/test/kotlin/com/squareup/kotlinpoet/ksp/test/processor/TestProcessorTest.kt +++ b/interop/ksp/test-processor/src/test/kotlin/com/squareup/kotlinpoet/ksp/test/processor/TestProcessorTest.kt @@ -134,6 +134,7 @@ class TestProcessorTest { param5: Function1, param6: (Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int) -> Unit, param7: ((String) -> String)?, + param8: suspend () -> String, ) { } @@ -298,6 +299,7 @@ class TestProcessorTest { Int, ) -> Unit, param7: ((String) -> String)?, + param8: suspend () -> String, ) { }