Skip to content

Commit f904ed4

Browse files
author
Fedor Ihnatkevich
committed
Merge pull request #61 from yandex/wp/fix-51
Fix: Tweak alias's equals/hashcode, so they don't include owner.
1 parent b98b208 commit f904ed4

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

core/graph/impl/src/main/kotlin/bindings/AliasBindingImpl.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,12 @@ internal class AliasBindingImpl(
4141

4242
override fun equals(other: Any?): Boolean {
4343
return this === other || (other is AliasBinding &&
44-
source == other.source && target == other.target &&
45-
owner == other.owner)
44+
source == other.source && target == other.target)
4645
}
4746

4847
override fun hashCode(): Int {
4948
var result = target.hashCode()
5049
result = 31 * result + source.hashCode()
51-
result = 31 * result + owner.hashCode()
5250
return result
5351
}
5452

testing/tests/src/test/kotlin/CoreBindingsTest.kt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,5 +1041,33 @@ class CoreBindingsTest(
10411041

10421042
compileRunAndValidate()
10431043
}
1044+
1045+
@Test
1046+
fun `@Binds alias is allowed to be duplicated`() {
1047+
givenKotlinSource("test.TestCase", """
1048+
import com.yandex.yatagan.*
1049+
import javax.inject.*
1050+
1051+
class TestClass @Inject constructor()
1052+
1053+
@Module interface MyModule {
1054+
@Binds fun binds(i: TestClass): Any
1055+
@Binds fun binds2(i: TestClass): Any
1056+
}
1057+
1058+
@Component(modules = [MyModule::class])
1059+
interface TestComponent {
1060+
val obj: Any
1061+
fun createSub(): SubComponent
1062+
}
1063+
1064+
@Component(isRoot = false, modules = [MyModule::class])
1065+
interface SubComponent {
1066+
val obj: Any
1067+
}
1068+
""".trimIndent())
1069+
1070+
compileRunAndValidate()
1071+
}
10441072
}
10451073

0 commit comments

Comments
 (0)