diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/IrTypeSystemContext.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/IrTypeSystemContext.kt index cbf4a2ad688..eb37436c026 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/IrTypeSystemContext.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/IrTypeSystemContext.kt @@ -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? { diff --git a/compiler/testData/writeSignature/inlineClasses/genericInlineClassWithNotNullTypeParameter.kt b/compiler/testData/writeSignature/inlineClasses/genericInlineClassWithNotNullTypeParameter.kt index 74c9621afe4..a8a2b736bd7 100644 --- a/compiler/testData/writeSignature/inlineClasses/genericInlineClassWithNotNullTypeParameter.kt +++ b/compiler/testData/writeSignature/inlineClasses/genericInlineClassWithNotNullTypeParameter.kt @@ -1,5 +1,4 @@ // !LANGUAGE: +InlineClasses -// IGNORE_BACKEND: JVM_IR @Suppress("INLINE_CLASS_HAS_INAPPLICABLE_PARAMETER_TYPE") inline class NonNull(val x: T) @@ -29,4 +28,4 @@ object Test { // method: Test::asNullableForNullableValue-wXDnar0 // jvm signature: (LNullableValue;)V -// generic signature: (LNullableValue;)V \ No newline at end of file +// generic signature: (LNullableValue;)V