google / dagger

A fast dependency injector for Android and Java.
https://dagger.dev
Apache License 2.0
17.45k stars 2.02k forks source link

[KSP] [KSP2] unexpected jvm signature V when processing in KSP2 #4505

Open ZacSweers opened 6 days ago

ZacSweers commented 6 days ago

We ran into an odd case with KSP2 when assisted injecting an enum class from another module into a class

class Example @AssistedInject constructor(@Assisted database: Database)

// In an upstream module
enum class Database {
  APP,
  // ...
}

This seems like a fairly simple case, I'm not super sure where to look. This is with Kotlin 2.0.21 and KSP 2.0.21-1.0.27. It's unfortunately nearly impossible for me to debug directly because all these APIs are still shaded into dagger.spi.internal.shaded.androidx.room.compiler.processing.javac.kotlin

Trace

Caused by: dagger.internal.codegen.base.DaggerSuperficialValidation$ValidationException$UnexpectedException:    
  Validation trace: 
    => element (CLASS): slack.telemetry.metric.db.LoggableSqliteDriver  
    at dagger.internal.codegen.base.DaggerSuperficialValidation$ValidationException.from(DaggerSuperficialValidation.java:527)  
    at dagger.internal.codegen.base.DaggerSuperficialValidation$ValidationException.access$100(DaggerSuperficialValidation.java:491)    
    at dagger.internal.codegen.base.DaggerSuperficialValidation.validateElement(DaggerSuperficialValidation.java:299)   
    at dagger.internal.codegen.processingstep.SuperficialValidator.validationExceptionsUncached(SuperficialValidator.java:58)   
    at dagger.internal.codegen.processingstep.SuperficialValidator.throwIfNearestEnclosingTypeNotValid(SuperficialValidator.java:47)    
    at dagger.internal.codegen.processingstep.TypeCheckingProcessingStep.lambda$process$0(TypeCheckingProcessingStep.java:92)   
    at com.google.common.collect.RegularImmutableMap.forEach(RegularImmutableMap.java:300)  
    at dagger.internal.codegen.processingstep.TypeCheckingProcessingStep.process(TypeCheckingProcessingStep.java:72)    
    at dagger.internal.codegen.processingstep.TypeCheckingProcessingStep.process(TypeCheckingProcessingStep.java:49)    
    at dagger.spi.internal.shaded.androidx.room.compiler.processing.XProcessingStep.process(XProcessingStep.kt:57)  
    at dagger.spi.internal.shaded.androidx.room.compiler.processing.CommonProcessorDelegate.processRound(XBasicAnnotationProcessor.kt:134)  
    at dagger.spi.internal.shaded.androidx.room.compiler.processing.ksp.KspBasicAnnotationProcessor.process(KspBasicAnnotationProcessor.kt:62)  
    at com.google.devtools.ksp.impl.KotlinSymbolProcessing$execute$1$1.invoke(KotlinSymbolProcessing.kt:552)    
    at com.google.devtools.ksp.impl.KotlinSymbolProcessing$execute$1$1.invoke(KotlinSymbolProcessing.kt:550)    
    at ksp.com.google.devtools.ksp.common.IncrementalContextBase.closeFilesOnException(IncrementalContextBase.kt:409)   
    at com.google.devtools.ksp.impl.KotlinSymbolProcessing.execute(KotlinSymbolProcessing.kt:550)   
    at com.google.devtools.ksp.impl.KSPLoader$Companion.loadAndRunKSP(KSPLoader.kt:37)  
    at com.google.devtools.ksp.impl.KSPLoader.loadAndRunKSP(KSPLoader.kt)

Cause

Caused by: java.lang.IllegalStateException: unexpected jvm signature V  
    at dagger.spi.internal.shaded.androidx.room.compiler.processing.javac.kotlin.JvmDescriptorUtilsKt.typeNameFromJvmSignature(JvmDescriptorUtils.kt:106)   
    at dagger.spi.internal.shaded.androidx.room.compiler.processing.ksp.KSTypeJavaPoetExtKt.asJTypeName(KSTypeJavaPoetExt.kt:99)    
    at dagger.spi.internal.shaded.androidx.room.compiler.processing.ksp.KSTypeJavaPoetExtKt.asJTypeName(KSTypeJavaPoetExt.kt:182)   
    at dagger.spi.internal.shaded.androidx.room.compiler.processing.ksp.KSTypeJavaPoetExtKt.asJTypeName(KSTypeJavaPoetExt.kt:64)    
    at dagger.spi.internal.shaded.androidx.room.compiler.processing.ksp.KSTypeJavaPoetExtKt.asJTypeName$resolveTypeName(KSTypeJavaPoetExt.kt:143)   
    at dagger.spi.internal.shaded.androidx.room.compiler.processing.ksp.KSTypeJavaPoetExtKt.asJTypeName(KSTypeJavaPoetExt.kt:148)   
    at dagger.spi.internal.shaded.androidx.room.compiler.processing.ksp.KSTypeJavaPoetExtKt.asJTypeName(KSTypeJavaPoetExt.kt:172)   
    at dagger.spi.internal.shaded.androidx.room.compiler.processing.ksp.KSTypeJavaPoetExtKt.asJTypeName(KSTypeJavaPoetExt.kt:154)   
    at dagger.spi.internal.shaded.androidx.room.compiler.processing.ksp.DefaultKspType.resolveJTypeName(DefaultKspType.kt:43)   
    at dagger.spi.internal.shaded.androidx.room.compiler.processing.ksp.KspType$xTypeName$2.invoke(KspType.kt:90)   
    at dagger.spi.internal.shaded.androidx.room.compiler.processing.ksp.KspType$xTypeName$2.invoke(KspType.kt:69)   
    at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)  
    at dagger.spi.internal.shaded.androidx.room.compiler.processing.ksp.KspType.getXTypeName(KspType.kt:69) 
    at dagger.spi.internal.shaded.androidx.room.compiler.processing.ksp.KspType.access$getXTypeName(KspType.kt:49)  
    at dagger.spi.internal.shaded.androidx.room.compiler.processing.ksp.KspType$typeName$2.invoke(KspType.kt:61)    
    at dagger.spi.internal.shaded.androidx.room.compiler.processing.ksp.KspType$typeName$2.invoke(KspType.kt:61)    
    at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)  
    at dagger.spi.internal.shaded.androidx.room.compiler.processing.ksp.KspType.getTypeName(KspType.kt:61)  
    at dagger.internal.codegen.xprocessing.XTypes.toStableString(XTypes.java:496)   
    at dagger.internal.codegen.xprocessing.XElements.toStableString(XElements.java:346) 
    at dagger.internal.codegen.base.DaggerSuperficialValidation$ValidationException.getMessageForElement(DaggerSuperficialValidation.java:637)  
    at dagger.internal.codegen.base.DaggerSuperficialValidation$ValidationException.append(DaggerSuperficialValidation.java:547)    
    at dagger.internal.codegen.base.DaggerSuperficialValidation$ValidationException.access$200(DaggerSuperficialValidation.java:491)    
    at dagger.internal.codegen.base.DaggerSuperficialValidation.validateElement(DaggerSuperficialValidation.java:299)   
    at dagger.internal.codegen.base.DaggerSuperficialValidation.validateElements(DaggerSuperficialValidation.java:250)  
    at dagger.internal.codegen.base.DaggerSuperficialValidation.validateElement(DaggerSuperficialValidation.java:285)   
    at dagger.internal.codegen.processingstep.SuperficialValidator.validationExceptionsUncached(SuperficialValidator.java:58)   
    at dagger.internal.codegen.processingstep.SuperficialValidator.throwIfNearestEnclosingTypeNotValid(SuperficialValidator.java:47)    
    at dagger.internal.codegen.processingstep.TypeCheckingProcessingStep.lambda$process$0(TypeCheckingProcessingStep.java:92)   
    at com.google.common.collect.RegularImmutableMap.forEach(RegularImmutableMap.java:300)  
    at dagger.internal.codegen.processingstep.TypeCheckingProcessingStep.process(TypeCheckingProcessingStep.java:72)    
    at dagger.internal.codegen.processingstep.TypeCheckingProcessingStep.process(TypeCheckingProcessingStep.java:49)    
    at dagger.spi.internal.shaded.androidx.room.compiler.processing.XProcessingStep.process(XProcessingStep.kt:57)  
    at dagger.spi.internal.shaded.androidx.room.compiler.processing.CommonProcessorDelegate.processRound(XBasicAnnotationProcessor.kt:134)  
    at dagger.spi.internal.shaded.androidx.room.compiler.processing.ksp.KspBasicAnnotationProcessor.process(KspBasicAnnotationProcessor.kt:62)
kuanyingchou commented 5 days ago

Hi, @ZacSweers , this should have been fixed with https://android-review.googlesource.com/c/platform/frameworks/support/+/3314733. A future Dagger release should include the fix.

ZacSweers commented 5 days ago

Great! Between this and supporting Kotlin 2.1.0 (which is in RC but dagger apt is currently incompatible), it would be quite helpful if y'all would consider getting another release out. Sounds like dagger at HEAD would be fully compatible with K2 kapt and KSP

ZacSweers commented 5 days ago

I don't believe this is fixed on HEAD. Just tested the latest snapshot and the same issue occurs

ZacSweers commented 5 days ago

Or is the link above in androidx but not yet consumed in dagger?

kuanyingchou commented 5 days ago

Yes, sorry about the confusion and the internal link. It still needs to be consumed in Dagger. I've updated the link.

Chang-Eric commented 5 days ago

@ZacSweers

Great! Between this and supporting Kotlin 2.1.0 (which is in RC but dagger apt is currently incompatible), it would be quite helpful if y'all would consider getting another release out. Sounds like dagger at HEAD would be fully compatible with K2 kapt and KSP

Actually the story is unfortunately more complicated. We actually don't support KSP2 right now. See https://github.com/google/dagger/issues/2349#issuecomment-2329852274 for details, but we're right now still dealing with known issues with KSP2 and trying to make sure our own tests pass with KSP2. We're hoping to make more progress soon (several KSP2 issues have recently been fixed) but we still aren't in a spot where you should expect things to work. I know this is not what you probably want to hear, but a lot of it hasn't been in our control. It is however our top priority to get KSP2 working.