Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
8 changes: 7 additions & 1 deletion ast/ksp/src/main/kotlin/me/tatarka/kotlin/ast/KSAst.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import com.google.devtools.ksp.symbol.KSFunctionDeclaration
import com.google.devtools.ksp.symbol.KSPropertyDeclaration
import com.google.devtools.ksp.symbol.KSType
import com.google.devtools.ksp.symbol.KSTypeAlias
import com.google.devtools.ksp.symbol.KSTypeParameter
import com.google.devtools.ksp.symbol.KSTypeReference
import com.google.devtools.ksp.symbol.KSValueParameter
import com.google.devtools.ksp.symbol.Modifier
Expand Down Expand Up @@ -531,7 +532,12 @@ private class KSAstType private constructor(
return if (type.isError) {
typeRef.toString()
} else {
typeRef.toTypeName().toString()
try {
typeRef.toTypeName().toString()
}
catch (_: Throwable) {
typeRef.toString()
}
}.shortenPackage()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1273,4 +1273,37 @@ class FailureTest {
contains("Qualifier: @MyQualifier can only be applied to the outer type")
}
}

@ParameterizedTest
@EnumSource(Target::class)
fun fails_if_cannot_find_inject_or_provider_and_root_is_a_type_parameter(target: Target) {
val projectCompiler = ProjectCompiler(target, workingDir)

assertFailure {
projectCompiler.source(
"MyComponent.kt",
"""
import me.tatarka.inject.annotations.Component
import me.tatarka.inject.annotations.Inject
import me.tatarka.inject.annotations.Provides

class Foo

@Inject class Bar(val foo: Foo)

interface DestinationComponent<C> {
val c: C
val cProvider: () -> C
}

@Inject class CType(val bar: Bar)

@Component
abstract class FooBarComponent : DestinationComponent<CType>
""".trimIndent()
).compile()
}.output().all {
contains("e: [ksp] Cannot find an @Inject constructor or provider for: Foo")
}
}
}