From 569b6eaff26fd15566f88cac1fca03c803bb353f Mon Sep 17 00:00:00 2001 From: Mikhail Zarechenskiy Date: Mon, 1 Jun 2020 09:39:52 +0300 Subject: [PATCH] Don't issue compatibility warning for the candidates in the same group --- .../org/jetbrains/kotlin/resolve/calls/tower/TowerResolver.kt | 4 +++- .../sam/compatibilityResolveToOuterScopeForKotlinFunctions.kt | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/tower/TowerResolver.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/tower/TowerResolver.kt index bda1e6b06fa..3045c1a2132 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/tower/TowerResolver.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/tower/TowerResolver.kt @@ -313,6 +313,7 @@ class TowerResolver { override fun getSuccessfulCandidates(): Collection? { if (!isSuccessful) return null var compatibilityCandidate: C? = null + var compatibilityGroup: Collection? = null var firstGroupWithResolved: Collection? = null outer@ for (group in candidateGroups) { for (candidate in group) { @@ -322,13 +323,14 @@ class TowerResolver { } if (compatibilityCandidate == null && isSuccessfulPreserveCompatibility(candidate)) { + compatibilityGroup = group compatibilityCandidate = candidate } } } if (firstGroupWithResolved == null) return null - if (compatibilityCandidate != null) { + if (compatibilityCandidate != null && compatibilityGroup !== firstGroupWithResolved) { firstGroupWithResolved.forEach { it.addCompatibilityWarning(compatibilityCandidate) } } diff --git a/compiler/testData/diagnostics/tests/j+k/sam/compatibilityResolveToOuterScopeForKotlinFunctions.kt b/compiler/testData/diagnostics/tests/j+k/sam/compatibilityResolveToOuterScopeForKotlinFunctions.kt index 088aa864d72..1139b0b20d0 100644 --- a/compiler/testData/diagnostics/tests/j+k/sam/compatibilityResolveToOuterScopeForKotlinFunctions.kt +++ b/compiler/testData/diagnostics/tests/j+k/sam/compatibilityResolveToOuterScopeForKotlinFunctions.kt @@ -40,7 +40,7 @@ object Test3 { fun foo(n: Number, f: () -> Unit): String = "" fun test(f: () -> Unit) { - val result = foo(1, f) + val result = foo(1, f) result } } @@ -52,7 +52,7 @@ object Test4 { fun bar() {} fun test() { - val result = foo(1, ::bar) + val result = foo(1, ::bar) result } }