Fix isNullableType() to always consider flexible types, even if they contain type parameters

This commit is contained in:
Andrey Breslav
2014-09-02 18:19:28 +04:00
parent 107480657a
commit 1dbfe5483a
4 changed files with 39 additions and 8 deletions
@@ -0,0 +1,11 @@
import java.util.HashMap
fun <K: Any, V: Any> foo(k: K, v: V) {
val map = HashMap<K, V>()
val old = map.put(k, v)
}
fun box(): String {
foo("", "")
return "OK"
}
@@ -4445,7 +4445,8 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
@TestMetadata("recursive.kt")
public void testRecursive() throws Exception {
doTest("compiler/testData/diagnostics/tests/generics/recursive.kt");
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/generics/recursive.kt");
doTest(fileName);
}
@TestMetadata("RecursiveUpperBoundCheck.kt")
@@ -7776,7 +7777,8 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
@TestMetadata("recursiveGeneric.kt")
public void testRecursiveGeneric() throws Exception {
doTest("compiler/testData/diagnostics/tests/platformTypes/commonSupertype/recursiveGeneric.kt");
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/platformTypes/commonSupertype/recursiveGeneric.kt");
doTest(fileName);
}
@TestMetadata("stringOrNull.kt")
@@ -7797,7 +7799,8 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
@TestMetadata("entrySet.kt")
public void testEntrySet() throws Exception {
doTest("compiler/testData/diagnostics/tests/platformTypes/methodCall/entrySet.kt");
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/platformTypes/methodCall/entrySet.kt");
doTest(fileName);
}
@TestMetadata("int.kt")
@@ -7850,7 +7853,8 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
@TestMetadata("sam.kt")
public void testSam() throws Exception {
doTest("compiler/testData/diagnostics/tests/platformTypes/methodCall/sam.kt");
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/platformTypes/methodCall/sam.kt");
doTest(fileName);
}
@TestMetadata("singleton.kt")
@@ -4018,13 +4018,29 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
@TestMetadata("compiler/testData/codegen/box/javaInterop")
@TestDataPath("$PROJECT_ROOT")
@InnerTestClasses({JavaInterop.ObjectMethods.class})
@InnerTestClasses({JavaInterop.NotNullAssertions.class, JavaInterop.ObjectMethods.class})
@RunWith(org.jetbrains.jet.JUnit3RunnerWithInners.class)
public static class JavaInterop extends AbstractBlackBoxCodegenTest {
public void testAllFilesPresentInJavaInterop() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/javaInterop"), Pattern.compile("^(.+)\\.kt$"), true);
}
@TestMetadata("compiler/testData/codegen/box/javaInterop/notNullAssertions")
@TestDataPath("$PROJECT_ROOT")
@RunWith(org.jetbrains.jet.JUnit3RunnerWithInners.class)
public static class NotNullAssertions extends AbstractBlackBoxCodegenTest {
public void testAllFilesPresentInNotNullAssertions() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/javaInterop/notNullAssertions"), Pattern.compile("^(.+)\\.kt$"), true);
}
@TestMetadata("mapPut.kt")
public void testMapPut() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/javaInterop/notNullAssertions/mapPut.kt");
doTest(fileName);
}
}
@TestMetadata("compiler/testData/codegen/box/javaInterop/objectMethods")
@TestDataPath("$PROJECT_ROOT")
@RunWith(org.jetbrains.jet.JUnit3RunnerWithInners.class)
@@ -424,12 +424,12 @@ public class TypeUtils {
if (type.isNullable()) {
return true;
}
if (type.getConstructor().getDeclarationDescriptor() instanceof TypeParameterDescriptor) {
return hasNullableSuperType(type);
}
if (TypesPackage.isFlexible(type) && isNullableType(((FlexibleType) type).getUpperBound())) {
return true;
}
if (type.getConstructor().getDeclarationDescriptor() instanceof TypeParameterDescriptor) {
return hasNullableSuperType(type);
}
return false;
}