Do not wrap flexible types into Nullable/NotNull types

This commit is contained in:
Andrey Breslav
2014-08-25 19:09:11 +04:00
parent 141e731f39
commit bdbd469aad
3 changed files with 43 additions and 0 deletions
@@ -0,0 +1,36 @@
// FILE: p/PsiElement.java
package p;
public interface PsiElement {}
// FILE: p/JetExpression.java
package p;
public interface JetExpression extends PsiElement {}
// FILE: p/Util.java
package p;
public class Util {
public static <T extends PsiElement> T getParentOfType(@Nullable PsiElement element, @NotNull Class<T> aClass) {
return null;
}
public static void on(JetExpression e) {}
}
// FILE: k.kt
import p.*
fun test(e: JetExpression) {
Util.on(
Util.getParentOfType(e, javaClass<JetExpression>()) ?: e
)
}
fun <T> javaClass(): Class<T> = null!!
@@ -7717,6 +7717,11 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
doTest(fileName);
}
@TestMetadata("getParentOfType.kt")
public void testGetParentOfType() throws Exception {
doTest("compiler/testData/diagnostics/tests/platformTypes/getParentOfType.kt");
}
@TestMetadata("inference.kt")
public void testInference() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/platformTypes/inference.kt");
@@ -111,6 +111,8 @@ public class TypeUtils {
@NotNull
public static JetType makeNullableAsSpecified(@NotNull JetType type, boolean nullable) {
if (TypesPackage.isFlexible(type)) return type;
// Wrapping serves two purposes here
// 1. It's requires less memory than copying with a changed nullability flag: a copy has many fields, while a wrapper has only one
// 2. It preserves laziness of types