File tree Expand file tree Collapse file tree 2 files changed +35
-0
lines changed
ast/ksp/src/main/kotlin/me/tatarka/kotlin/ast
kotlin-inject-compiler/test/src/test/kotlin/me/tatarka/inject/test Expand file tree Collapse file tree 2 files changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ import com.google.devtools.ksp.symbol.KSFunctionDeclaration
21
21
import com.google.devtools.ksp.symbol.KSPropertyDeclaration
22
22
import com.google.devtools.ksp.symbol.KSType
23
23
import com.google.devtools.ksp.symbol.KSTypeAlias
24
+ import com.google.devtools.ksp.symbol.KSTypeParameter
24
25
import com.google.devtools.ksp.symbol.KSTypeReference
25
26
import com.google.devtools.ksp.symbol.KSValueParameter
26
27
import com.google.devtools.ksp.symbol.Modifier
@@ -530,6 +531,8 @@ private class KSAstType private constructor(
530
531
// we check for error first because KotlinPoet will throw an exception
531
532
return if (type.isError) {
532
533
typeRef.toString()
534
+ } else if (type.declaration is KSTypeParameter ) {
535
+ typeRef.toString()
533
536
} else {
534
537
typeRef.toTypeName().toString()
535
538
}.shortenPackage()
Original file line number Diff line number Diff line change @@ -1273,4 +1273,36 @@ class FailureTest {
1273
1273
contains(" Qualifier: @MyQualifier can only be applied to the outer type" )
1274
1274
}
1275
1275
}
1276
+
1277
+ @ParameterizedTest
1278
+ @EnumSource(Target ::class )
1279
+ fun fails_if_cannot_find_inject_or_provider_and_root_is_a_type_parameter (target : Target ) {
1280
+ val projectCompiler = ProjectCompiler (target, workingDir)
1281
+
1282
+ assertFailure {
1283
+ projectCompiler.source(
1284
+ " MyComponent.kt" ,
1285
+ """
1286
+ import me.tatarka.inject.annotations.Component
1287
+ import me.tatarka.inject.annotations.Inject
1288
+ import me.tatarka.inject.annotations.Provides
1289
+
1290
+ class Foo
1291
+
1292
+ @Inject class Bar(val foo: Foo)
1293
+
1294
+ interface DestinationComponent<C> {
1295
+ val c: C
1296
+ }
1297
+
1298
+ @Inject class CType(val bar: Bar)
1299
+
1300
+ @Component
1301
+ abstract class FooBarComponent : DestinationComponent<CType>
1302
+ """ .trimIndent()
1303
+ ).compile()
1304
+ }.output().all {
1305
+ contains(" e: [ksp] Cannot find an @Inject constructor or provider for: Foo" )
1306
+ }
1307
+ }
1276
1308
}
You can’t perform that action at this time.
0 commit comments