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

[KSP] Processing crash when two assisted inject constructors are encountered #3992

Closed
ZacSweers opened this issue Aug 3, 2023 · 1 comment

Comments

@ZacSweers
Copy link

ZacSweers commented Aug 3, 2023

The following code snippet

package com.squareup.test

import dagger.assisted.Assisted
import dagger.assisted.AssistedInject

class AssistedService @AssistedInject constructor(
  int: Int,
  @Assisted string: String
) {
  @AssistedInject constructor(@Assisted string: String)
}

will correctly error in apt with this message

Type com.squareup.test.AssistedService may only contain one injected constructor. Found: [@dagger.assisted.AssistedInject com.squareup.test.AssistedService, @dagger.assisted.AssistedInject com.squareup.test.AssistedService]

but will crash in KSP processing with the below trace. Note the message appears to be correct, but the crash is cause and reported after it's logged.

This is with Dagger version 2.47.

e: Error occurred in KSP, check log for detail
e: [ksp] /var/folders/nv/96k28mh96ml0g6y4gxkpjfcw0000gn/T/Kotlin-Compilation5455861261926387550/sources/src/main/java/com/squareup/test/Source0.kt:6: Type com.squareup.test.AssistedService may only contain one injected constructor. Found: [@dagger.assisted.AssistedInject com.squareup.test.AssistedService(int, String), @dagger.assisted.AssistedInject com.squareup.test.AssistedService(String)]
e: [ksp] java.lang.IllegalArgumentException: expected one element but was: <<init>, <init>>
	at com.google.common.collect.Iterators.getOnlyElement(Iterators.java:323)
	at com.google.common.collect.Iterables.getOnlyElement(Iterables.java:263)
	at dagger.internal.codegen.binding.AssistedInjectionAnnotations.assistedInjectAssistedParameters(AssistedInjectionAnnotations.java:257)
	at dagger.internal.codegen.processingstep.AssistedInjectProcessingStep$AssistedInjectValidator.validate(AssistedInjectProcessingStep.java:60)
	at dagger.internal.codegen.processingstep.AssistedInjectProcessingStep.process(AssistedInjectProcessingStep.java:51)
	at dagger.internal.codegen.processingstep.AssistedInjectProcessingStep.process(AssistedInjectProcessingStep.java:35)
	at dagger.internal.codegen.processingstep.TypeCheckingProcessingStep.lambda$process$0(TypeCheckingProcessingStep.java:82)
	at com.google.common.collect.RegularImmutableMap.forEach(RegularImmutableMap.java:196)
	at dagger.internal.codegen.processingstep.TypeCheckingProcessingStep.process(TypeCheckingProcessingStep.java:70)
	at dagger.internal.codegen.processingstep.TypeCheckingProcessingStep.process(TypeCheckingProcessingStep.java:48)
	at dagger.spi.shaded.androidx.room.compiler.processing.XProcessingStep.process(XProcessingStep.kt:59)
	at dagger.spi.shaded.androidx.room.compiler.processing.CommonProcessorDelegate.processRound(XBasicAnnotationProcessor.kt:130)
	at dagger.spi.shaded.androidx.room.compiler.processing.ksp.KspBasicAnnotationProcessor.process(KspBasicAnnotationProcessor.kt:62)
@bcorso
Copy link

bcorso commented Aug 23, 2023

This was fixed by 698f6cb.

The fix will be included in the next release.

@bcorso bcorso closed this as completed Aug 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants