Fix primitive types mapping

Use boxed version if type was enhaced to not-nullable
This commit is contained in:
Denis Zharkov
2016-02-05 11:17:39 +03:00
parent 68110f5859
commit c879f83037
7 changed files with 21 additions and 5 deletions
@@ -44,6 +44,7 @@ import org.jetbrains.kotlin.load.java.descriptors.JavaCallableMemberDescriptor;
import org.jetbrains.kotlin.load.java.descriptors.JavaClassDescriptor;
import org.jetbrains.kotlin.load.java.lazy.descriptors.LazyJavaPackageFragment;
import org.jetbrains.kotlin.load.java.lazy.descriptors.LazyJavaPackageScope;
import org.jetbrains.kotlin.load.java.typeEnhancement.TypeEnhancementKt;
import org.jetbrains.kotlin.load.kotlin.KotlinJvmBinaryClass;
import org.jetbrains.kotlin.load.kotlin.KotlinJvmBinaryPackageSourceElement;
import org.jetbrains.kotlin.load.kotlin.KotlinJvmBinarySourceElement;
@@ -510,7 +511,8 @@ public class JetTypeMapper {
PrimitiveType primitiveType = KotlinBuiltIns.getPrimitiveTypeByFqName(fqName);
if (primitiveType != null) {
Type asmType = Type.getType(JvmPrimitiveType.get(primitiveType).getDesc());
return TypeUtils.isNullableType(type) ? boxType(asmType) : asmType;
boolean isNullableInJava = TypeUtils.isNullableType(type) || TypeEnhancementKt.hasEnhancedNullability(type);
return isNullableInJava ? boxType(asmType) : asmType;
}
PrimitiveType arrayElementType = KotlinBuiltIns.getPrimitiveTypeByArrayClassFqName(fqName);
@@ -20,6 +20,7 @@ import com.intellij.openapi.util.text.StringUtil
import org.jetbrains.kotlin.descriptors.ReceiverParameterDescriptor
import org.jetbrains.kotlin.load.java.JvmAnnotationNames
import org.jetbrains.kotlin.jvm.bindingContextSlices.RUNTIME_ASSERTION_INFO
import org.jetbrains.kotlin.load.java.typeEnhancement.hasEnhancedNullability
import org.jetbrains.kotlin.psi.KtExpression
import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.calls.checkers.AdditionalTypeChecker
@@ -74,9 +75,6 @@ class RuntimeAssertionInfo(val needNotNullAssertion: Boolean, val message: Strin
else
null
}
private fun KotlinType.hasEnhancedNullability()
= annotations.findAnnotation(JvmAnnotationNames.ENHANCED_NULLABILITY_ANNOTATION) != null
}
}
@@ -3,7 +3,7 @@ fun box(): String {
l.add(1000)
val x = l[0] === 1000
if (!x) return "Fail: $x"
if (x) return "Fail: $x"
val x1 = l[0] === 1
if (x1) return "Fail 1: $x"
val x2 = l[0] === l[0]
@@ -0,0 +1,7 @@
public class J {
// This test checks that although type '@org.jetbrains.annotations.NotNull Integer' is perceived as simple Int,
// it's correctly mapped to 'Lj.l.Integer' by JVM backend
public static String test(@org.jetbrains.annotations.NotNull Integer x) {
return "OK";
}
}
@@ -0,0 +1 @@
fun box() = J.test(1)
@@ -77,6 +77,12 @@ public class BlackBoxWithJavaCodegenTestGenerated extends AbstractBlackBoxCodege
doTestWithJava(fileName);
}
@TestMetadata("enhancedPrimitives")
public void testEnhancedPrimitives() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxWithJava/enhancedPrimitives/");
doTestWithJava(fileName);
}
@TestMetadata("inline")
public void testInline() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxWithJava/inline/");
@@ -42,6 +42,8 @@ import org.jetbrains.kotlin.utils.toReadOnlyList
// For flexible types, both bounds are indexed in the same way: `(A<B>..C<D>)` gives `0 - (A<B>..C<D>), 1 - B and D`.
fun KotlinType.enhance(qualifiers: (Int) -> JavaTypeQualifiers) = this.enhancePossiblyFlexible(qualifiers, 0).typeIfChanged
fun KotlinType.hasEnhancedNullability()
= annotations.findAnnotation(JvmAnnotationNames.ENHANCED_NULLABILITY_ANNOTATION) != null
private enum class TypeComponentPosition {
FLEXIBLE_LOWER,