Skip to content

fix: encode only validated requirements in cross-module DSL hints - #116

Closed
shreknitin89 wants to merge 1 commit into
InsertKoinIO:mainfrom
shreknitin89:fix/dsl-hint-skip-flags
Closed

shreknitin89 wants to merge 1 commit into
InsertKoinIO:mainfrom
shreknitin89:fix/dsl-hint-skip-flags

Conversation

@shreknitin89

Copy link
Copy Markdown
Contributor

Fixes #115.

Problem

buildRequirementParams encodes each requirement as req<i>_<name>, with only its type and qualifier. On the consuming side, discoverDslDefinitionsFromHints rebuilds each requirement with isInjectedParam, hasDefault, isNullable and isList hard-coded to false. So a DSL definition in another Gradle module that has an @InjectedParam, defaulted, nullable or List<T> constructor parameter always produces a false KOIN-D001 at the startKoin entry point.

Change

Filter on Requirement.requiresValidation() at the producer, where those flags are still known, before encoding. Requirements that don't need a provider never reach the hint, so the consumer's hard-coded flags no longer matter for them. The producer applies its own skipDefaultValues setting, which is the setting that also decided the generated code.

Testing

I haven't run the test suite locally. My environment blocked building the plugin, so I'm relying on CI here. The diagnosis comes from the source plus 74 false positives in a real multi-module app, every one of them one of these four parameter kinds (see #115). A box test with a library module that exposes a DSL viewModel<T>() taking an @InjectedParam param and a defaulted param would pin this. I'm happy to add one if you point me at the preferred cross-module fixture.

Possible follow-up (not in this change)

isLazy is also rebuilt as false. Lazy<T> requirements still need validation (on T), so they are still encoded, but a cycle check that relies on isLazy to break Lazy edges could see a false KOIN-D004 across modules. Encoding a lazy marker, like the req<i>qn_ qualifier companions, would close that.

The req$i hint encoding carries only type and qualifier, and
discoverDslDefinitionsFromHints rebuilds each requirement with
isInjectedParam, hasDefault, isNullable and isList hard-coded false.
Every @InjectedParam, defaulted, nullable or List<T> parameter of a DSL
definition in another module therefore surfaced as a false KOIN-D001 at
the startKoin entry point. Filter on requiresValidation() at the
producer, where those flags are still known.

Fixes InsertKoinIO#115

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@arnaudgiuliani

Copy link
Copy Markdown
Member

Your fix is re-embedded in #134. I will credit you on that part. Thanks for your work 🙏

arnaudgiuliani added a commit that referenced this pull request Oct 29, 2026
…004 (#115) (#134)

A DSL definition validated from another module (e.g. an app consuming a
feature module, or a module's own test compilation) was rebuilt from its
hint with every per-parameter flag false. Parameters that need no provider
became hard requirements → false KOIN-D001 on defaulted, nullable, List<T>,
@InjectedParam, @Property, @provided and @Scopeid parameters; and a
Lazy<T> edge became a hard cycle edge → false KOIN-D004 (DSL and
annotation function-provider hints alike).

- DSL hints carry Unit markers req<i>f_<flag> (+ req<i>sid_<name>) and the
  consumer decodes them. Hints from an older producer have none and decode
  as before; old consumers ignore the new markers.
- The @Property key is not carried: KOIN-P001 is a same-module check, the
  consumer can't see the producer's @Propertyvalue declarations.
- Annotation funcreqs hints carry an adjacent `lz` marker for Lazy<T>.

Tests: 9 cross-module RED→GREEN tests (one per flag + Lazy cycle on both
hint paths) and a guard that a missing Lazy<T> provider still reports D001.
Golden diffs: only the new req0f_* hint parameters.

Verified on nowinandroid: :app no longer reports false D001 for
TopicViewModel(@InjectedParam topicId) / InterestsViewModel(@InjectedParam key).

Supersedes #116 — thanks to Nitin Dasari for the original report and fix.

Co-authored-by: Nitin Dasari <16711885+shreknitin89@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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

Successfully merging this pull request may close these issues.

1.2.x: false KOIN-D001 for cross-module DSL definitions with @InjectedParam, defaulted, nullable or List<T> params

2 participants