Refine type mapping for nullable inline class types

This commit is contained in:
Mikhail Zarechenskiy
2018-01-24 15:19:43 +03:00
parent d5400f11a3
commit d1049e5553
3 changed files with 43 additions and 1 deletions
@@ -0,0 +1,30 @@
// !LANGUAGE: +InlineClasses
inline class InlinePrimitive(val x: Int)
inline class InlineReference(val y: String)
inline class InlineNullablePrimitive(val x: Int?)
inline class InlineNullableReference(val y: String?)
object Test {
fun withPrimitiveAsNullable(a: InlinePrimitive?) {}
fun withReferenceAsNullable(a: InlineReference?) {}
fun withNullablePrimitiveAsNullable(a: InlineNullablePrimitive?) {}
fun withNullableReferenceAsNullable(a: InlineNullableReference?) {}
}
// method: Test::withPrimitiveAsNullable
// jvm signature: (LInlinePrimitive;)V
// generic signature: null
// method: Test::withReferenceAsNullable
// jvm signature: (Ljava/lang/String;)V
// generic signature: null
// method: Test::withNullablePrimitiveAsNullable
// jvm signature: (LInlineNullablePrimitive;)V
// generic signature: null
// method: Test::withNullableReferenceAsNullable
// jvm signature: (LInlineNullableReference;)V
// generic signature: null
@@ -558,6 +558,12 @@ public class WriteSignatureTestGenerated extends AbstractWriteSignatureTest {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/writeSignature/inlineClasses"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true);
}
@TestMetadata("nullableInlineClassType.kt")
public void testNullableInlineClassType() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/writeSignature/inlineClasses/nullableInlineClassType.kt");
doTest(fileName);
}
@TestMetadata("simpleSignatureWithInlineClassTypesAsPrimitive.kt")
public void testSimpleSignatureWithInlineClassTypesAsPrimitive() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/writeSignature/inlineClasses/simpleSignatureWithInlineClassTypesAsPrimitive.kt");
@@ -132,7 +132,13 @@ fun <T : Any> mapType(
if (descriptor.isInline && !mode.needInlineClassWrapping) {
val underlyingType = descriptor.underlyingRepresentation()?.type
if (underlyingType != null) {
return mapType(underlyingType, factory, mode, typeMappingConfiguration, descriptorTypeWriter, writeGenericType)
if (!kotlinType.isMarkedNullable) {
return mapType(underlyingType, factory, mode, typeMappingConfiguration, descriptorTypeWriter, writeGenericType)
}
if (!underlyingType.isMarkedNullable && !KotlinBuiltIns.isPrimitiveType(underlyingType)) {
return mapType(underlyingType, factory, mode, typeMappingConfiguration, descriptorTypeWriter, writeGenericType)
}
}
}