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] Dagger-KSP does not see typealiased dagger annotations #4356

Open
ZacSweers opened this issue Jul 16, 2024 · 3 comments
Open

[KSP] Dagger-KSP does not see typealiased dagger annotations #4356

ZacSweers opened this issue Jul 16, 2024 · 3 comments

Comments

@ZacSweers
Copy link

ZacSweers commented Jul 16, 2024

Edit When I originally wrote this, I thought it was related to the use of expect/actual in multiplatform. Upon further testing, it appears to be just related to the use of a typealiased annotation in any context

I have a multiplatform project where I use Dagger in jvm/android. To accomplish this in a way that still allows for use of standard injection annotations in common sources, I use expect/actual + typealiases to actualize them in jvm/android compilations to the real dagger annotations.

// commonMain
@Target(CONSTRUCTOR, FUNCTION, PROPERTY_SETTER) expect annotation class Inject()

@Target(CONSTRUCTOR) expect annotation class AssistedInject()

@Target(VALUE_PARAMETER) expect annotation class Assisted(val value: String = "")

@Target(CLASS) expect annotation class AssistedFactory()
// androidMain/jvmMain
import dagger.assisted.Assisted
import dagger.assisted.AssistedFactory
import dagger.assisted.AssistedInject
import javax.inject.Inject

actual typealias Inject = Inject

actual typealias AssistedInject = AssistedInject

actual typealias Assisted = Assisted

actual typealias AssistedFactory = AssistedFactory

However, it appears that dagger-ksp then misses these types because it doesn't resolve the aliased type of the annotations. I'm not sure if this is a dagger issue or a KSP issue (i.e. is KSP not correctly resolving that the annotated symbol is actually an alias to the intended type).

Two alternative solutions:

  1. Allow specifying custom annotations to replace dagger's expected ones. This solution is what the kotlin parcelize plugin used to support K2/KMP parceling. That is to say, expose compiler options to remap/add mappings of the annotations dagger looks for, such that I could say "hey my.custom.AssistedFactory should also be treated as @AssistedFactory".
  2. Repackage dagger's annotations into a multiplatform project such that they can be used natively in a KMP project.
@ZacSweers
Copy link
Author

I've searched the KSP issue tracker and found a previous issue that, amusingly, I filed months ago and forgot about google/ksp#1676. I'm going to consolidate this over to that.

My solution in that issue is similar to the first alternative I listed above

@ZacSweers ZacSweers closed this as not planned Won't fix, can't repro, duplicate, stale Jul 16, 2024
@ZacSweers ZacSweers reopened this Jul 17, 2024
@ZacSweers
Copy link
Author

Reopening as, according to the KSP folks, this is actually the responsibility of the symbol processor to resolve the underlying aliased type.

google/ksp#1676 (comment)

ZacSweers added a commit to slackhq/circuit that referenced this issue Jul 17, 2024
After some discussion [here](google/dagger#4356) I learned we should be handling this ourselves
@danysantiago
Copy link
Member

I filled https://issuetracker.google.com/355006385 in XProcessing which is where most type aliases are resolved for Dagger. We already resolve type alias in various places but looks like we never needed to for annotations, so this seems something that just might be fixed with changes in XProcessing.

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