google / dagger

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

[KSP] KSP mode does not check for `@Provides` on interface methods #4346

Open ZacSweers opened 2 months ago

ZacSweers commented 2 months ago

This is a slight behavior change from apt to KSP. The following snippet is an error in apt but has no error in KSP

@Module
interface DaggerModule1 {
  @Provides fun provideString(): String = ""
}

It may be intentional if the intention is to support the default value, but I can't find any docs that confirm this.

bcorso commented 1 month ago

Thanks for reporting! No, this was not intentional.

In KAPT, this would turn into an abstract method + static DefaultImpls implementation in the Java stub, so I think things just happened to fail since we don't allow @Provides on an abstract method. My guess is that KSP represents this case more accurately and the method isn't considered abstract due to the default implementation.

In any case, I think the "fix" for this to make it behave the same as KAPT (i.e. fail the build).