The case of Integer.getInteger("1", 2) fixed (was: OVERLOAD_RESOLUTION_AMBIGUITY)

This commit is contained in:
Andrey Breslav
2014-09-09 21:31:59 +04:00
parent 837353d9fd
commit 0b6a4df4f4
3 changed files with 53 additions and 1 deletions
@@ -28,6 +28,7 @@ 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.TypesPackage;
import org.jetbrains.jet.lang.types.checker.JetTypeChecker;
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
@@ -239,8 +240,24 @@ public class OverloadingConflictResolver {
}
private boolean typeMoreSpecific(@NotNull JetType specific, @NotNull JetType general) {
return JetTypeChecker.DEFAULT.isSubtypeOf(specific, general) ||
boolean isSubtype = JetTypeChecker.DEFAULT.isSubtypeOf(specific, general) ||
numericTypeMoreSpecific(specific, general);
if (!isSubtype) return false;
boolean specificIsFlexible = TypesPackage.isFlexible(specific);
boolean generalIsFlexible = TypesPackage.isFlexible(general);
if (specificIsFlexible && !generalIsFlexible) {
// Int! lessSpecific Int
// Int! >< Int?
return false;
}
else if (!specificIsFlexible && generalIsFlexible) {
// Int? >< Int!
if (specific.isNullable()) return false;
}
return true;
}
private boolean numericTypeMoreSpecific(@NotNull JetType specific, @NotNull JetType general) {
@@ -0,0 +1,29 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
// FILE: p/J.java
package p;
public class J {
public interface A {}
public static A foo(int s);
public interface B {}
public static B foo(Integer s);
}
// FILE: k.kt
import p.*
import p.J.*
class C
fun foo(i: Int?) : C = null!!
fun test(i: Int, ni: Int?) {
foo(2) : J.A
foo(i) : J.A
J.foo(ni) : J.B
<!OVERLOAD_RESOLUTION_AMBIGUITY!>foo<!>(ni)
}
@@ -7743,6 +7743,12 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
doTest(fileName);
}
@TestMetadata("intVsIntegerAmbiguity.kt")
public void testIntVsIntegerAmbiguity() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/platformTypes/intVsIntegerAmbiguity.kt");
doTest(fileName);
}
@TestMetadata("override.kt")
public void testOverride() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/platformTypes/override.kt");