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 } }