Box/unbox nullable inline class values with null check

When we have a nullable inline class value with non-null underlying
type, corresponding value in unboxed representation is nullable. E.g.:

  inline class Str(val value: String)

  fun test(s: Str?) = listOf(s)

Here 'test(s: Str?)' accepts nullable 'java.lang.String' as a parameter.

When boxing/unboxing nullable values of such inline classes, take care
of nulls.

 #KT-26052 Fixed Target versions 1.3-M2
This commit is contained in:
Dmitry Petrov
2018-08-13 12:28:01 +03:00
parent 56ad091534
commit ebf8ec455d
12 changed files with 360 additions and 1 deletions
@@ -11333,6 +11333,16 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/inlineClasses"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true);
}
@TestMetadata("boxNullableValueOfInlineClassWithNonNullUnderlyingType.kt")
public void testBoxNullableValueOfInlineClassWithNonNullUnderlyingType() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/boxNullableValueOfInlineClassWithNonNullUnderlyingType.kt");
}
@TestMetadata("boxNullableValueOfInlineClassWithPrimitiveUnderlyingType.kt")
public void testBoxNullableValueOfInlineClassWithPrimitiveUnderlyingType() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/boxNullableValueOfInlineClassWithPrimitiveUnderlyingType.kt");
}
@TestMetadata("boxUnboxInlineClassesWithOperatorsGetSet.kt")
public void testBoxUnboxInlineClassesWithOperatorsGetSet() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/boxUnboxInlineClassesWithOperatorsGetSet.kt");
@@ -11468,6 +11478,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
runTest("compiler/testData/codegen/box/inlineClasses/emptyConstructorForInlineClass.kt");
}
@TestMetadata("equalityForBoxesOfNullableValuesOfInlineClass.kt")
public void testEqualityForBoxesOfNullableValuesOfInlineClass() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/equalityForBoxesOfNullableValuesOfInlineClass.kt");
}
@TestMetadata("inlineClassAsLastExpressionInInLambda.kt")
public void testInlineClassAsLastExpressionInInLambda() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/inlineClassAsLastExpressionInInLambda.kt");
@@ -11573,6 +11588,16 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
runTest("compiler/testData/codegen/box/inlineClasses/UIntArraySortExample.kt");
}
@TestMetadata("unboxNullableValueOfInlineClassWithNonNullUnderlyingType.kt")
public void testUnboxNullableValueOfInlineClassWithNonNullUnderlyingType() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/unboxNullableValueOfInlineClassWithNonNullUnderlyingType.kt");
}
@TestMetadata("unboxNullableValueOfInlineClassWithPrimitiveUnderlyingType.kt")
public void testUnboxNullableValueOfInlineClassWithPrimitiveUnderlyingType() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/unboxNullableValueOfInlineClassWithPrimitiveUnderlyingType.kt");
}
@TestMetadata("unboxReceiverOnCallingMethodFromInlineClass.kt")
public void testUnboxReceiverOnCallingMethodFromInlineClass() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/unboxReceiverOnCallingMethodFromInlineClass.kt");