inlineClassUtils: Fix handling of inline classes without constructors

Fixes KT-50992

DeclarationDescriptor.isInlineClass misidentifies inline classes without
constructors. This can happen for the ABI of inline classes with private
constructors.
This commit is contained in:
Steven Schäfer
2022-01-27 14:08:43 +01:00
committed by Alexander Udalov
parent aa6ba18c39
commit 78d80181e2
7 changed files with 31 additions and 2 deletions
@@ -22,7 +22,7 @@ val JVM_INLINE_ANNOTATION_CLASS_ID = ClassId.topLevel(JVM_INLINE_ANNOTATION_FQ_N
fun DeclarationDescriptor.isInlineClass(): Boolean = when {
this !is ClassDescriptor -> false
isInline -> true
else -> isValue && unsubstitutedPrimaryConstructor?.valueParameters?.size == 1
else -> isValue && unsubstitutedPrimaryConstructor?.valueParameters?.size?.let { it == 1 } ?: true
}
fun DeclarationDescriptor.isValueClass(): Boolean =
@@ -177,7 +177,7 @@ class DeserializedClassDescriptor(
override fun getInlineClassRepresentation(): InlineClassRepresentation<SimpleType>? = inlineClassRepresentation()
private fun computeInlineClassRepresentation(): InlineClassRepresentation<SimpleType>? {
if (!isInlineClass()) return null
if (!isInlineOrValueClass()) return null
val propertyName = when {
classProto.hasInlineClassUnderlyingPropertyName() ->
@@ -115,6 +115,11 @@ public class CompileAgainstJvmAbiTestGenerated extends AbstractCompileAgainstJvm
runTest("plugins/jvm-abi-gen/testData/compile/privateOnlyConstructors/");
}
@TestMetadata("privateValueClassConstructor")
public void testPrivateValueClassConstructor() throws Exception {
runTest("plugins/jvm-abi-gen/testData/compile/privateValueClassConstructor/");
}
@TestMetadata("topLevel")
public void testTopLevel() throws Exception {
runTest("plugins/jvm-abi-gen/testData/compile/topLevel/");
@@ -115,6 +115,11 @@ public class IrCompileAgainstJvmAbiTestGenerated extends AbstractIrCompileAgains
runTest("plugins/jvm-abi-gen/testData/compile/privateOnlyConstructors/");
}
@TestMetadata("privateValueClassConstructor")
public void testPrivateValueClassConstructor() throws Exception {
runTest("plugins/jvm-abi-gen/testData/compile/privateValueClassConstructor/");
}
@TestMetadata("topLevel")
public void testTopLevel() throws Exception {
runTest("plugins/jvm-abi-gen/testData/compile/topLevel/");
@@ -115,6 +115,11 @@ public class LegacyCompileAgainstJvmAbiTestGenerated extends AbstractLegacyCompi
runTest("plugins/jvm-abi-gen/testData/compile/privateOnlyConstructors/");
}
@TestMetadata("privateValueClassConstructor")
public void testPrivateValueClassConstructor() throws Exception {
runTest("plugins/jvm-abi-gen/testData/compile/privateValueClassConstructor/");
}
@TestMetadata("topLevel")
public void testTopLevel() throws Exception {
runTest("plugins/jvm-abi-gen/testData/compile/topLevel/");
@@ -0,0 +1,7 @@
package app
import lib.*
fun runAppAndReturnOk(): String {
return A.a().b()
}
@@ -0,0 +1,7 @@
package lib
@JvmInline
value class A private constructor(val value: String) {
companion object { fun a() = A("OK") }
inline fun b() = value
}