JVM IR: perform substitution in IrTypeSystemContext.getSubstitutedUnderlyingType

This commit is contained in:
Alexander Udalov
2019-07-19 13:50:45 +02:00
parent 908498a560
commit cfd3d974d1
2 changed files with 13 additions and 5 deletions
@@ -288,9 +288,18 @@ interface IrTypeSystemContext : TypeSystemContext, TypeSystemCommonSuperTypesCon
} ?: owner.superTypes.first()
override fun KotlinTypeMarker.getSubstitutedUnderlyingType(): KotlinTypeMarker? {
// Code in inlineClassesUtils.kt loads the property with the same name and takes its type. This should have the same effect.
val irClass = (this as? IrType)?.classOrNull?.owner ?: return null
return irClass.primaryConstructor?.valueParameters?.singleOrNull()?.type
// Code in inlineClassesUtils.kt loads the property with the same name from the scope of the substituted type and takes its type.
// This code below should have the same effect.
val irClass = (this as? IrType)?.classOrNull?.owner?.takeIf { it.isInline } ?: return null
val inlineClassParameter = irClass.primaryConstructor?.valueParameters?.singleOrNull()
return inlineClassParameter?.let { parameter ->
// Taking only the type parameters of the class (and not its outer classes) is OK since inner classes are always top level
IrTypeSubstitutor(
irClass.typeParameters.map { it.symbol },
(this as? IrSimpleType)?.arguments.orEmpty(),
irBuiltIns
).substitute(parameter.type)
}
}
override fun TypeConstructorMarker.getPrimitiveType(): PrimitiveType? {
@@ -1,5 +1,4 @@
// !LANGUAGE: +InlineClasses
// IGNORE_BACKEND: JVM_IR
@Suppress("INLINE_CLASS_HAS_INAPPLICABLE_PARAMETER_TYPE")
inline class NonNull<T : Any>(val x: T)
@@ -29,4 +28,4 @@ object Test {
// method: Test::asNullableForNullableValue-wXDnar0
// jvm signature: (LNullableValue;)V
// generic signature: (LNullableValue<Ljava/lang/Integer;>;)V
// generic signature: (LNullableValue<Ljava/lang/Integer;>;)V