Skip to content

Commit

Permalink
Fix issue with missing suspend modifier in KSTypeReference.toTypeName
Browse files Browse the repository at this point in the history
  • Loading branch information
rickclephas committed Jan 2, 2024
1 parent 43b6850 commit b124f07
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ class TestProcessorTest {
param5: Function1<String, String>,
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,
) {
}
Expand Down Expand Up @@ -298,6 +299,7 @@ class TestProcessorTest {
Int,
) -> Unit,
param7: ((String) -> String)?,
param8: suspend () -> String,
) {
}
Expand Down

0 comments on commit b124f07

Please sign in to comment.