google / ksp

Kotlin Symbol Processing API
https://github.com/google/ksp
Apache License 2.0
2.72k stars 254 forks source link

"KSTypeArgument.type should not have been null, please file a bug. STAR null" with KSP2.0.0-1.0.22 and KSP2 #1957

Open lwasyl opened 3 weeks ago

lwasyl commented 3 weeks ago
 java.lang.IllegalStateException: KSTypeArgument.type should not have been null, please file a bug. STAR null
        at dagger.spi.internal.shaded.androidx.room.compiler.processing.ksp.KSTypeExtKt.requireType(KSTypeExt.kt:128)
        at dagger.spi.internal.shaded.androidx.room.compiler.processing.ksp.KspTypeArgumentType.<init>(KspTypeArgumentType.kt:41)
        at dagger.spi.internal.shaded.androidx.room.compiler.processing.ksp.KspTypeArgumentType.<init>(KspTypeArgumentType.kt:33)
        at dagger.spi.internal.shaded.androidx.room.compiler.processing.ksp.KspProcessingEnv.wrap(KspProcessingEnv.kt:280)
        at dagger.spi.internal.shaded.androidx.room.compiler.processing.ksp.KspType$typeArguments$2.invoke(KspType.kt:202)
        at dagger.spi.internal.shaded.androidx.room.compiler.processing.ksp.KspType$typeArguments$2.invoke(KspType.kt:198)
        at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
        at dagger.spi.internal.shaded.androidx.room.compiler.processing.ksp.KspType.getTypeArguments(KspType.kt:198)
        at dagger.internal.codegen.base.DaggerSuperficialValidation.validateType(DaggerSuperficialValidation.java:337)
        ... 53 more

This happens when processing this file:

import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import javax.inject.Inject
import javax.inject.Provider

class ViewModelFactory @Inject constructor(
    private val creators: Map<Class<*>, @JvmSuppressWildcards Provider<ViewModel>>,
) : ViewModelProvider.Factory {

    @Suppress("UNCHECKED_CAST")
    override fun <T : ViewModel> create(modelClass: Class<T>): T = creators[modelClass]?.get() as T
}

Kotlin 2.0.0 + KSP2.0.0-1.0.22 (ksp.useKSP2=true) + Dagger 2.51.1.

neetopia commented 3 weeks ago

It looks an expected behavior to me, STAR projection should not have a type since it is literally a * at the use site, cc @kuanyingchou should this behavior change be taken care of in XProcessing?

reference: https://github.com/google/ksp/blob/main/docs/ksp2api.md#type-arguments-of-star-projections

kuanyingchou commented 3 weeks ago

Yes, I'm working on a change in XProcessing for this, but please note that Dagger doesn't work with KSP2 yet.