Fix outer DSL qualifier propagation for create(::...) safety hints#48
Fix outer DSL qualifier propagation for create(::...) safety hints#481250422131 wants to merge 1 commit into
create(::...) safety hints#48Conversation
Capture the enclosing DSL qualifier in KoinDSLTransformer and reuse it when
collecting DslDef entries from create(::constructor) and create(::function).
This keeps compile-safety hints aligned with registrations such as
single(qualifier = named("Demo1")) { create(::createDemoRoot) }.
Add a box regression test covering outer qualifier + create(::function).
|
@arnaudgiuliani Can you have a look in this PR ? Seems it fixes our issue |
|
Yep, will look at it! |
|
@arnaudgiuliani Do you plan to do anything for this PR ? |
|
Got heavily delayed ... working on it this week 👍 |
|
Thanks for your attention on this PR. Just to be transparent: I used AI assistance while preparing this change. My goal is to help make the Koin compiler plugin more robust, but I’m aware that AI-assisted code should be reviewed carefully. Please feel free to point out anything that looks wrong, fragile, or not aligned with the project. |
|
Thanks for this @1250422131 🙏 — the outer-DSL-qualifier propagation is exactly the right fix for #41, and we've incorporated it into the upcoming 1.0.2 release (with credit to you in the commit). One thing we adjusted on top while integrating it, so you're aware: the new single(qualifier = named<MyQualifier>()) { create(::createDemoRoot) }
// -> IrGenerationExtensionException: No such value argument slot in IrCallImpl: 0 (total=0)and they're also removed in Kotlin 2.4.0. We swapped all four sites to the plugin's bounds-safe compat shims ( Net: your change ships in 1.0.2. Much appreciated! 🎉 |
The Pull Request
Related to #41.
This PR fixes qualifier collection for
create(::...)registrations when the qualifier is declared on the enclosing DSL call.At first, I thought the issue was that
@Namedon the constructor/class was not being collected correctly. After digging into it, I found that the actual missing piece was the outer DSL qualifier:The runtime registration has a qualifier, but the compiler plugin did not carry that outer qualifier into the collected DSL definition used by compile-safety validation.
I understand that the annotation-first style is already supported and may be the more idiomatic style for the compiler plugin:
However, for users coming from classic Koin DSL, putting the qualifier on the registration site is also a natural style:
I am not fully sure whether supporting this style fits the intended design of the Koin compiler plugin. If this goes against the project direction, please feel free to close the PR.
With this change, both forms are supported:
@Named/@QualifierWhen both are present, the outer DSL qualifier takes priority, matching the actual DSL registration site.
Changes
DslDefentries fromcreate(::constructor)andcreate(::function).single(qualifier = named(...)) { create(::function) }.Verification
./gradlew :koin-compiler-plugin:test --tests org.jetbrains.kotlin.compiler.plugin.template.runners.JvmBoxTestGenerated\$Safety.testDsl_create_function_outer_qualifier