Extensible specificity expressed as a type capability
This commit is contained in:
+6
-14
@@ -25,9 +25,7 @@ import org.jetbrains.jet.lang.resolve.OverrideResolver;
|
||||
import org.jetbrains.jet.lang.resolve.calls.model.MutableResolvedCall;
|
||||
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
|
||||
import org.jetbrains.jet.lang.resolve.calls.model.VariableAsFunctionResolvedCall;
|
||||
import org.jetbrains.jet.lang.types.BoundsSubstitutor;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.TypeUtils;
|
||||
import org.jetbrains.jet.lang.types.*;
|
||||
import org.jetbrains.jet.lang.types.checker.JetTypeChecker;
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||
|
||||
@@ -240,21 +238,15 @@ public class OverloadingConflictResolver {
|
||||
|
||||
private boolean typeMoreSpecific(@NotNull JetType specific, @NotNull JetType general) {
|
||||
boolean isSubtype = JetTypeChecker.DEFAULT.isSubtypeOf(specific, general) ||
|
||||
numericTypeMoreSpecific(specific, general);
|
||||
numericTypeMoreSpecific(specific, general);
|
||||
|
||||
if (!isSubtype) return false;
|
||||
|
||||
boolean specificIsFlexible = specific.isFlexible();
|
||||
boolean generalIsFlexible = general.isFlexible();
|
||||
|
||||
if (specificIsFlexible && !generalIsFlexible) {
|
||||
// Int! lessSpecific Int
|
||||
// Int! >< Int?
|
||||
Specificity.Relation sThanG = TypesPackage.getSpecificityRelationTo(specific, general);
|
||||
Specificity.Relation gThanS = TypesPackage.getSpecificityRelationTo(general, specific);
|
||||
if (sThanG == Specificity.Relation.LESS_SPECIFIC && gThanS != Specificity.Relation.LESS_SPECIFIC) {
|
||||
return false;
|
||||
}
|
||||
else if (!specificIsFlexible && generalIsFlexible) {
|
||||
// Int? >< Int!
|
||||
if (specific.isNullable()) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -9,6 +9,8 @@ public class J {
|
||||
|
||||
public interface B {}
|
||||
public static B foo(Integer s);
|
||||
|
||||
public static Integer getInteger();
|
||||
}
|
||||
|
||||
// FILE: k.kt
|
||||
@@ -25,5 +27,8 @@ fun test(i: Int, ni: Int?) {
|
||||
foo(i) : J.A
|
||||
J.foo(ni) : J.B
|
||||
<!OVERLOAD_RESOLUTION_AMBIGUITY!>foo<!>(ni)
|
||||
|
||||
foo(J.getInteger())
|
||||
J.foo(J.getInteger())
|
||||
}
|
||||
|
||||
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
// FILE: p/Super.java
|
||||
package p;
|
||||
|
||||
public interface Super {}
|
||||
|
||||
// FILE: p/Sub.java
|
||||
package p;
|
||||
|
||||
public interface Sub extends Super {}
|
||||
|
||||
// FILE: p/Util.java
|
||||
|
||||
package p;
|
||||
|
||||
public abstract class Util {
|
||||
public abstract void foo(String s, Super sup)
|
||||
public void foo(String s, Sub sub) {}
|
||||
}
|
||||
|
||||
// FILE: k.kt
|
||||
|
||||
import p.*
|
||||
|
||||
class C: Util() {
|
||||
override fun foo(s: String, sub: Super) {}
|
||||
}
|
||||
|
||||
fun foo(sub: Sub) {
|
||||
C().foo("", sub)
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
package
|
||||
|
||||
internal fun foo(/*0*/ sub: p.Sub): kotlin.Unit
|
||||
|
||||
internal final class C : p.Util {
|
||||
public constructor C()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ fun foo(/*0*/ s: kotlin.String, /*1*/ sub: p.Super): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun foo(/*0*/ s: kotlin.String!, /*1*/ sub: p.Sub!): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
@@ -7863,6 +7863,12 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("overloadingForSubclass.kt")
|
||||
public void testOverloadingForSubclass() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/platformTypes/methodCall/overloadingForSubclass.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("sam.kt")
|
||||
public void testSam() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/platformTypes/methodCall/sam.kt");
|
||||
|
||||
Reference in New Issue
Block a user