Properly handle @NotNull for arrays

This commit is contained in:
Andrey Breslav
2013-10-30 15:57:30 +04:00
parent 3f3030ff26
commit 31d4993406
8 changed files with 50 additions and 2 deletions
@@ -0,0 +1,8 @@
package test;
import org.jetbrains.annotations.NotNull;
public class NotNullIntArray {
@NotNull
public int[] hi() { return null; }
}
@@ -0,0 +1,5 @@
package test
public open class NotNullIntArray() : java.lang.Object() {
public open fun hi(): IntArray = throw Exception()
}
@@ -0,0 +1,6 @@
package test
public open class NotNullIntArray : java.lang.Object {
public constructor NotNullIntArray()
public open fun hi(): jet.IntArray
}
@@ -0,0 +1,8 @@
package test;
import org.jetbrains.annotations.NotNull;
public class NotNullObjectArray {
@NotNull
public Object[] hi() { return null; }
}
@@ -0,0 +1,5 @@
package test
public open class NotNullObjectArray() : java.lang.Object() {
public open fun hi(): Array<Any> = throw Exception()
}
@@ -0,0 +1,6 @@
package test
public open class NotNullObjectArray : java.lang.Object {
public constructor NotNullObjectArray()
public open fun hi(): jet.Array<jet.Any>
}
@@ -2423,11 +2423,21 @@ public class LazyResolveRecursiveComparingTestGenerated extends AbstractLazyReso
doTestNotCheckingPrimaryConstructors("compiler/testData/loadJava/compiledJavaCompareWithKotlin/notNull/NotNullField.kt");
}
@TestMetadata("NotNullIntArray.kt")
public void testNotNullIntArray() throws Exception {
doTestNotCheckingPrimaryConstructors("compiler/testData/loadJava/compiledJavaCompareWithKotlin/notNull/NotNullIntArray.kt");
}
@TestMetadata("NotNullMethod.kt")
public void testNotNullMethod() throws Exception {
doTestNotCheckingPrimaryConstructors("compiler/testData/loadJava/compiledJavaCompareWithKotlin/notNull/NotNullMethod.kt");
}
@TestMetadata("NotNullObjectArray.kt")
public void testNotNullObjectArray() throws Exception {
doTestNotCheckingPrimaryConstructors("compiler/testData/loadJava/compiledJavaCompareWithKotlin/notNull/NotNullObjectArray.kt");
}
@TestMetadata("NotNullParameter.kt")
public void testNotNullParameter() throws Exception {
doTestNotCheckingPrimaryConstructors("compiler/testData/loadJava/compiledJavaCompareWithKotlin/notNull/NotNullParameter.kt");
@@ -69,14 +69,14 @@ class LazyJavaTypeResolver(
val javaComponentType = arrayType.getComponentType()
if (javaComponentType is JavaPrimitiveType) {
val jetType = JavaToKotlinClassMap.getInstance().mapPrimitiveKotlinClass("[" + javaComponentType.getCanonicalText())
if (jetType != null) return jetType
if (jetType != null) return TypeUtils.makeNullableAsSpecified(jetType, !attr.isMarkedNotNull)
}
val projectionKind = if (attr.howThisTypeIsUsed == MEMBER_SIGNATURE_CONTRAVARIANT && !isVararg) OUT_VARIANCE else INVARIANT
val howArgumentTypeIsUsed = isVararg.iif(MEMBER_SIGNATURE_CONTRAVARIANT, TYPE_ARGUMENT)
val componentType = transformJavaType(javaComponentType, howArgumentTypeIsUsed.toAttributes())
return TypeUtils.makeNullable(KotlinBuiltIns.getInstance().getArrayType(projectionKind, componentType))
return TypeUtils.makeNullableAsSpecified(KotlinBuiltIns.getInstance().getArrayType(projectionKind, componentType), !attr.isMarkedNotNull)
}
private class LazyStarProjection(