Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue with missing suspend modifier in KSTypeReference.toTypeName #1793

Merged
merged 1 commit into from
Jan 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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