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

[KSP2] Modules which have constructors with default args result in UnexpectedException #4497

Open
mcumings opened this issue Oct 30, 2024 · 2 comments

Comments

@mcumings
Copy link

Dagger: 2.52
KSP: 2.0.21-1.0.26

This is a bit of an odd scenario but it makes sense in our actual project.

The failing scenario:

class Decor @Inject constructor() {
    interface Factory {
        fun create(): Decor
    }
}

interface DecorStubSubcomponent {
    @Subcomponent.Builder
    interface Builder

    @Module
    class Install(val configure: Builder.() -> Unit) {
        @Provides
        fun provideDecorComponentFactory(builder: Builder): Decor.Factory = object : Decor.Factory {
            override fun create(): Decor = with(builder) {
                configure()
                Decor()
            }
        }
    }
}

Fails with:

e: [ksp] dagger.internal.codegen.base.DaggerSuperficialValidation$ValidationException$UnexpectedException: 
  Validation trace:
    => element (CLASS): repro.ksp.issue5.InjectedClass

Stack trace:

Caused by: org.gradle.workers.internal.DefaultWorkerExecutor$WorkExecutionException: A failure occurred while executing com.google.devtools.ksp.gradle.KspAAWorkerAction
    [ elided for brevity ]
Caused by: dagger.internal.codegen.base.DaggerSuperficialValidation$ValidationException$UnexpectedException: 
  Validation trace:
    => element (CLASS): repro.ksp.issue5.InjectedClass
	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.SingletonImmutableBiMap.forEach(SingletonImmutableBiMap.java:70)
	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:553)
	at com.google.devtools.ksp.impl.KotlinSymbolProcessing$execute$1$1.invoke(KotlinSymbolProcessing.kt:551)
	at ksp.com.google.devtools.ksp.common.IncrementalContextBase.closeFilesOnException(IncrementalContextBase.kt:409)
	at com.google.devtools.ksp.impl.KotlinSymbolProcessing.execute(KotlinSymbolProcessing.kt:551)
	at com.google.devtools.ksp.impl.KSPLoader$Companion.loadAndRunKSP(KSPLoader.kt:37)
	at com.google.devtools.ksp.impl.KSPLoader.loadAndRunKSP(KSPLoader.kt)
	at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(Unknown Source)
	at com.google.devtools.ksp.gradle.KspAAWorkerAction.execute(KspAATask.kt:525)
	at org.gradle.workers.internal.DefaultWorkerServer.execute(DefaultWorkerServer.java:63)
    [ elided for brevity ]
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:145)
	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)
	... 45 more
@Chang-Eric
Copy link
Member

Hey, thanks for filing this and all the other issues. I just wanted to let you know, for KSP2 we're still working on supporting this. You can see an update about that here: #2349 (comment)

So you're likely to find a lot of different bugs still as so far we've already found a lot of failures via XProcessing's unit tests (the underlying library we use to support KSP) and are just starting to now look at running our own unit tests in Dagger with KSP2 now that those are getting fixed. Also, with that said, I'm not sure when we're going to be able to go through these specific cases you're filing as we're prioritizing getting our tests passing first and I'm hoping a lot of these could be covered by those tests as well.

Anyway, just wanted to let you know and also still say that we appreciate the effort you've put into filing all of these issues!

@mcumings
Copy link
Author

Thanks @Chang-Eric! I figured as much but wanted to get some test cases from our project registered so that they were available as test subjects as work proceeded on your side of the fence. We're very much looking forward to the move to KSP2 so wanted to be proactive to do our part in things.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants