Skip to content

Commit

Permalink
[ksp] correctly resolve factory parameter types during argument match…
Browse files Browse the repository at this point in the history
…ing phase
  • Loading branch information
IlyaGulya committed Jul 22, 2024
1 parent 3a0c31f commit 32a61dd
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ internal data class GenerationDetails(
)

private fun KSValueParameter.asParameterKey(keyFactory: (KSValueParameter) -> String?): ParameterKey {
return ParameterKey(type.toTypeName(), keyFactory(this))
return ParameterKey(type.resolve().toTypeName(), keyFactory(this))
}

private fun KSValueParameter.assistedValue(): String? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,36 @@ class ContributesAssistedFactoryCodeGeneratorTest(
}
}
}

@Test
fun `should not fail on multiple lambda types`() {
compileAnvil("""
@file:Suppress("UNUSED_PARAMETER")
package com.test
import dagger.assisted.AssistedInject
import dagger.assisted.Assisted
import me.gulya.anvil.assisted.ContributesAssistedFactory
import me.gulya.anvil.assisted.AssistedKey
interface TestApi
interface TestApiFactory {
fun create(
onBackClicked: () -> Unit,
onCategoryClicked: (categoryId: Long) -> Unit,
): TestApi
}
@ContributesAssistedFactory(Any::class, TestApiFactory::class)
class DefaultTestApi @AssistedInject constructor(
@Assisted private val onBackClicked: () -> Unit,
@Assisted private val onCategoryClicked: (categoryId: Long) -> Unit,
) : TestApi
""".trimIndent()) {
assertThat(exitCode).isEqualTo(OK)
}
}
}

inline fun <reified T> AnnotatedElement.annotationOrNull(): T? =
Expand Down

0 comments on commit 32a61dd

Please sign in to comment.