You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Restrict @Dispatcher qualifier to constructor parameters #2001
This change would adds @target(AnnotationTarget.VALUE_PARAMETER) to the @dispatcher qualifier to explicitly limit its usage to constructor/function parameters.
This removes Kotlin’s use-site target warnings, improves clarity.
I believe Kotlin 2.2 uses param by default it makes it more predictable in Hilt.
(Alternatively, we can add @PARAM e.g @PARAM:Dispatcher(IO), but having @target reduces boilerplate)
Any suggestion for writing a test for this?
@Target(AnnotationTarget.PROPERTY_SETTER)
@Qualifier
@Retention(RUNTIME)
annotation class Dispatcher(val niaDispatcher: NiaDispatchers)
enum class NiaDispatchers {
Default,
IO,
}
Since the restriction is enforced through @Target(AnnotationTarget.VALUE_PARAMETER), the Kotlin compiler already prevents the annotation from being used in unsupported locations (such as properties or classes).
Because of that, it may not require a runtime unit test. Any incorrect usage would fail at compile time.
If we still want some coverage, one option could be to keep a simple injection test where @Dispatcher is used on a constructor parameter and verify that Hilt successfully provides the dependency. This would indirectly confirm that the annotation works correctly with Hilt.
Alternatively, compile-time testing using something like kotlin-compile-testing could validate that using @Dispatcher on other targets fails to compile, but that might be heavier than needed for this case.
Activity
amEya911 commentedon Mar 6, 2026
Since the restriction is enforced through
@Target(AnnotationTarget.VALUE_PARAMETER), the Kotlin compiler already prevents the annotation from being used in unsupported locations (such as properties or classes).Because of that, it may not require a runtime unit test. Any incorrect usage would fail at compile time.
If we still want some coverage, one option could be to keep a simple injection test where
@Dispatcheris used on a constructor parameter and verify that Hilt successfully provides the dependency. This would indirectly confirm that the annotation works correctly with Hilt.Alternatively, compile-time testing using something like
kotlin-compile-testingcould validate that using@Dispatcheron other targets fails to compile, but that might be heavier than needed for this case.