Skip to content

Commit

Permalink
Add a complex type assignment check test to DaggerIssuesDetectorTest (#…
Browse files Browse the repository at this point in the history
…142)

This just bolts down some stuff we were questioning when running this lint internally.
  • Loading branch information
ZacSweers authored Oct 3, 2023
1 parent b1443e5 commit 961a1fe
Showing 1 changed file with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -155,18 +155,31 @@ class DaggerIssuesDetectorTest : BaseSlackLintTest() {
javaxInjectStubs,
daggerStubs,
kotlin(
"src/foo/TestModule.kt",
"""
package foo
import javax.inject.Qualifier
import dagger.Binds
import dagger.Module
sealed interface ItemDetail {
object DetailTypeA : ItemDetail
}
interface ItemMapper<T : ItemDetail>
class DetailTypeAItemMapper : ItemMapper<ItemDetail.DetailTypeA>
@Module
interface MyModule {
@Binds fun validBind(real: Int): Number
@Binds fun validBind(real: Boolean): Comparable<Boolean>
@Binds fun invalidBind(real: Long): String
@Binds fun invalidBind(real: Long): Comparable<Boolean>
@Binds fun validComplexBinding(real: DetailTypeAItemMapper): ItemMapper<out ItemDetail>
@Binds fun validComplexBinding2(real: DetailTypeAItemMapper): ItemMapper<*>
@Binds fun invalidComplexBinding(real: DetailTypeAItemMapper): ItemMapper<ItemDetail>
}
"""
)
Expand All @@ -176,13 +189,16 @@ class DaggerIssuesDetectorTest : BaseSlackLintTest() {
.run()
.expect(
"""
src/foo/MyModule.kt:10: Error: @Binds function parameters must be type-assignable to their return types. [BindsTypeMismatch]
src/foo/TestModule.kt:18: Error: @Binds function parameters must be type-assignable to their return types. [BindsTypeMismatch]
@Binds fun invalidBind(real: Long): String
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/foo/MyModule.kt:11: Error: @Binds function parameters must be type-assignable to their return types. [BindsTypeMismatch]
src/foo/TestModule.kt:19: Error: @Binds function parameters must be type-assignable to their return types. [BindsTypeMismatch]
@Binds fun invalidBind(real: Long): Comparable<Boolean>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2 errors, 0 warnings
src/foo/TestModule.kt:23: Error: @Binds function parameters must be type-assignable to their return types. [BindsTypeMismatch]
@Binds fun invalidComplexBinding(real: DetailTypeAItemMapper): ItemMapper<ItemDetail>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3 errors, 0 warnings
"""
.trimIndent()
)
Expand Down

0 comments on commit 961a1fe

Please sign in to comment.