Fix false-positive resolution ambiguity when using akka

com.typesafe.akka:akka-cluster-sharding_2.12:2.5
akka.cluster.sharding.ClusterSharding  has the following methods:

    public static ClusterSharding get(ActorSystem var0) {
        return ClusterSharding$.MODULE$.get(var0);
    }

    public static Extension get(ActorSystem var0) {
        return ClusterSharding$.MODULE$.get(var0);
    }

NB: ClusterSharding  <: Extension
None of these methods is synthetic or something, but javac allows
calls like ClusterSharding.get(null)  and they get resolved
to the first method returning ClusterSharding

It seems that both javac and IntelliJ resolution algorithms filter out
such clashing declarations choosing the one that has the most
specific return type, the same idea is applied in the change

 #KT-17560 Fixed
This commit is contained in:
Denis Zharkov
2017-04-24 11:43:52 +03:00
parent 40e1d5bc23
commit 62a55b7b00
5 changed files with 45 additions and 0 deletions
@@ -0,0 +1,16 @@
// !CHECK_TYPE
// FILE: A.java
public class A {
public String foo() {}
public CharSequence foo() {}
public static String bar() {}
public static CharSequence bar() {}
}
// FILE: main.kt
fun foo(a: A) {
a.foo() checkType { _<String>() }
A.bar() checkType { _<String>() }
}
@@ -0,0 +1,14 @@
package
public fun foo(/*0*/ a: A): kotlin.Unit
public open class A {
public constructor A()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open fun foo(): kotlin.String!
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
// Static members
public open fun bar(): kotlin.String!
}
@@ -12100,6 +12100,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
doTest(fileName);
}
@TestMetadata("selectMoreSpecific.kt")
public void testSelectMoreSpecific() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/j+k/selectMoreSpecific.kt");
doTest(fileName);
}
@TestMetadata("serializable.kt")
public void testSerializable() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/j+k/serializable.kt");
@@ -36,6 +36,7 @@ import org.jetbrains.kotlin.load.java.structure.JavaValueParameter
import org.jetbrains.kotlin.load.java.typeEnhancement.enhanceSignatures
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.resolve.DescriptorUtils
import org.jetbrains.kotlin.resolve.retainMostSpecificInEachOverridableGroup
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindExclude.NonExtensions
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
import org.jetbrains.kotlin.resolve.scopes.MemberScope
@@ -86,6 +87,8 @@ abstract class LazyJavaScope(protected val c: LazyJavaResolverContext) : MemberS
}
}
result.retainMostSpecificInEachOverridableGroup()
computeNonDeclaredFunctions(result, name)
enhanceSignatures(result).toList()
@@ -81,3 +81,9 @@ fun <H : Any> Collection<H>.selectMostSpecificInEachOverridableGroup(
}
return result
}
fun <D : CallableDescriptor> MutableCollection<D>.retainMostSpecificInEachOverridableGroup() {
val newResult = selectMostSpecificInEachOverridableGroup { this }
if (size == newResult.size) return
retainAll(newResult)
}