Skip to content

@InjectedParam with a nested generic type causes a compilation errorΒ #314

@Terenfear

Description

@Terenfear

Describe the bug
Using an @InjectedParam with some type that has nested type arguments (e.g. List<List<Int>>) causes incorrect generation of a lambda factory in the containing module. Probably related to #240 and #272 . I guess it's directly caused by this line:

val typeArgs = if (it.type.arguments.isNotEmpty()) it.type.arguments.mapNotNull { it.type?.resolve()?.declaration?.qualifiedName?.asString() }.joinToString(",", prefix = "<", postfix = ">") else ""

To Reproduce
Here's an MRE: https://github.com/Terenfear/koin-bug-reproducible-example. Just run :compileKotlinWasmJs or :compileAndroidMain.

Steps to reproduce the behavior:

  1. Create a class
@Single
class Foo(
    @InjectedParam bar: List<List<String>>
)
  1. Add it to some module using @ComponentScan
  2. Try to compile the app.

Alternatively, instead of writing an annotated class declare a provider function with an injected parameter in a module. The behavior is the same.

Expected behavior
No compilation error. The generated code looks something like this:

public val org_example_project_TestModule : Module get() = module {
	single() { (bar : kotlin.collections.List<kotlin.collections.List<String>>) -> org.example.project.Foo(bar)} 
}

Actual behavior
A compilation error. It generates this code (notice a lack of the type argument of the second List):

public val org_example_project_TestModule : Module get() = module {
	single() { (bar : kotlin.collections.List<kotlin.collections.List>) -> org.example.project.Foo(bar)} 
}

Koin project used and used version (please complete the following information):

  • koin-core version 4.1.1
  • koin-annotations version 2.3.0
  • koin-ksp-compiler version 2.3.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions