[IR BE] Fix inline class lowering
- provide additional type parameters from context when transforming constructor into static function. - fix KT-41771 - add test
This commit is contained in:
Generated
+5
@@ -13532,6 +13532,11 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/genericInlineClassSynthMembers.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("genericVararg2ndConstructor.kt")
|
||||
public void testGenericVararg2ndConstructor() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/genericVararg2ndConstructor.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("inlineClassAsLastExpressionInInLambda.kt")
|
||||
public void testInlineClassAsLastExpressionInInLambda() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/inlineClassAsLastExpressionInInLambda.kt");
|
||||
|
||||
+17
-1
@@ -255,8 +255,24 @@ class InlineClassLowering(val context: CommonBackendContext) {
|
||||
else -> Name.identifier(asString() + INLINE_CLASS_IMPL_SUFFIX)
|
||||
}
|
||||
|
||||
private fun collectTypeParameters(declaration: IrTypeParametersContainer): List<IrTypeParameter> {
|
||||
val result = mutableListOf<IrTypeParameter>()
|
||||
|
||||
fun collectImpl(declaration: IrDeclaration) {
|
||||
if (declaration is IrTypeParametersContainer) result.addAll(declaration.typeParameters)
|
||||
if (declaration is IrClass && declaration.isInner) collectImpl(declaration.parent as IrDeclaration)
|
||||
}
|
||||
|
||||
collectImpl(declaration)
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
private fun createStaticBodilessMethod(function: IrFunction): IrSimpleFunction =
|
||||
context.irFactory.createStaticFunctionWithReceivers(
|
||||
function.parent, function.name.toInlineClassImplementationName(), function
|
||||
function.parent,
|
||||
function.name.toInlineClassImplementationName(),
|
||||
function,
|
||||
typeParametersFromContext = collectTypeParameters(function.parentAsClass)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
// KJS_WITH_FULL_RUNTIME
|
||||
// WITH_RUNTIME
|
||||
// KT-41771
|
||||
|
||||
inline class Polynomial<T : Any>(val coefficients: List<T>) {
|
||||
constructor(vararg coefficients: T) : this(coefficients.toList())
|
||||
}
|
||||
fun box(): String {
|
||||
val p = Polynomial("FAIL1", "OK", "FAIL2")
|
||||
return p.coefficients[1]
|
||||
}
|
||||
+5
@@ -14927,6 +14927,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/genericInlineClassSynthMembers.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("genericVararg2ndConstructor.kt")
|
||||
public void testGenericVararg2ndConstructor() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/genericVararg2ndConstructor.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("inlineClassAsLastExpressionInInLambda.kt")
|
||||
public void testInlineClassAsLastExpressionInInLambda() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/inlineClassAsLastExpressionInInLambda.kt");
|
||||
|
||||
+5
@@ -14937,6 +14937,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/genericInlineClassSynthMembers.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("genericVararg2ndConstructor.kt")
|
||||
public void testGenericVararg2ndConstructor() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/genericVararg2ndConstructor.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("inlineClassAsLastExpressionInInLambda.kt")
|
||||
public void testInlineClassAsLastExpressionInInLambda() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/inlineClassAsLastExpressionInInLambda.kt");
|
||||
|
||||
+5
@@ -13532,6 +13532,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/genericInlineClassSynthMembers.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("genericVararg2ndConstructor.kt")
|
||||
public void testGenericVararg2ndConstructor() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/genericVararg2ndConstructor.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("inlineClassAsLastExpressionInInLambda.kt")
|
||||
public void testInlineClassAsLastExpressionInInLambda() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/inlineClassAsLastExpressionInInLambda.kt");
|
||||
|
||||
Generated
+5
@@ -11642,6 +11642,11 @@ public class IrJsCodegenBoxES6TestGenerated extends AbstractIrJsCodegenBoxES6Tes
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/genericInlineClassSynthMembers.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("genericVararg2ndConstructor.kt")
|
||||
public void testGenericVararg2ndConstructor() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/genericVararg2ndConstructor.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("inlineClassAsLastExpressionInInLambda.kt")
|
||||
public void testInlineClassAsLastExpressionInInLambda() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/inlineClassAsLastExpressionInInLambda.kt");
|
||||
|
||||
Generated
+5
@@ -11642,6 +11642,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/genericInlineClassSynthMembers.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("genericVararg2ndConstructor.kt")
|
||||
public void testGenericVararg2ndConstructor() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/genericVararg2ndConstructor.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("inlineClassAsLastExpressionInInLambda.kt")
|
||||
public void testInlineClassAsLastExpressionInInLambda() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/inlineClassAsLastExpressionInInLambda.kt");
|
||||
|
||||
+5
@@ -11707,6 +11707,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/genericInlineClassSynthMembers.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("genericVararg2ndConstructor.kt")
|
||||
public void testGenericVararg2ndConstructor() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/genericVararg2ndConstructor.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("inlineClassAsLastExpressionInInLambda.kt")
|
||||
public void testInlineClassAsLastExpressionInInLambda() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/inlineClassAsLastExpressionInInLambda.kt");
|
||||
|
||||
Reference in New Issue
Block a user