If fun interface methods are already mangled, do not mangle them twice

There are two possible scenarios, when fun interface method with inline
class parameter can be compiled.

First is when we compile fun interface itself before SAM adapter. In
that case, fun interface is lowered before we lower SAM adapter. Thus,
its method is mangled and mangling in the second time is an error.

Second is when we compile SAM adapter before the fun interface. In that
case, fun interface is not lowered, and we have to mangle the method.

The only way to distinguish there two cases I can think of is to check
whether the overridden method is already mangled, in other words, check,
whether the overridden method's suffix is doubled.

 #KT-48499: Fixed
This commit is contained in:
Ilmir Usmanov
2021-12-27 10:07:39 +01:00
parent 71732afae0
commit 549ea1a3b9
11 changed files with 165 additions and 0 deletions
@@ -20205,6 +20205,30 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
runTest("compiler/testData/codegen/box/inlineClasses/fieldNameClash.kt", TransformersFunctions.getRemoveOptionalJvmInlineAnnotation());
}
@Test
@TestMetadata("funInterfaceDoubleSuffux.kt")
public void testFunInterfaceDoubleSuffux() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/funInterfaceDoubleSuffux.kt", TransformersFunctions.getReplaceOptionalJvmInlineAnnotationWithReal());
}
@Test
@TestMetadata("funInterfaceDoubleSuffux2.kt")
public void testFunInterfaceDoubleSuffux2() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/funInterfaceDoubleSuffux2.kt", TransformersFunctions.getReplaceOptionalJvmInlineAnnotationWithReal());
}
@Test
@TestMetadata("funInterfaceDoubleSuffux2.kt")
public void testFunInterfaceDoubleSuffux2_valueClasses() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/funInterfaceDoubleSuffux2.kt", TransformersFunctions.getRemoveOptionalJvmInlineAnnotation());
}
@Test
@TestMetadata("funInterfaceDoubleSuffux.kt")
public void testFunInterfaceDoubleSuffux_valueClasses() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/funInterfaceDoubleSuffux.kt", TransformersFunctions.getRemoveOptionalJvmInlineAnnotation());
}
@Test
@TestMetadata("functionExpression.kt")
public void testFunctionExpression() throws Exception {
@@ -120,6 +120,11 @@ private class JvmInlineClassLowering(private val context: JvmBackendContext) : F
return null
}
// If fun interface methods are already mangled, do not mangle them twice.
if (function is IrSimpleFunction && function.overriddenSymbols.any { it.owner.parentAsClass.isFun } &&
function.name.asString().substringAfterLast('-') == replacement.name.asString().substringAfterLast('-')
) return null
addBindingsFor(function, replacement)
return when (function) {
is IrSimpleFunction -> transformSimpleFunctionFlat(function, replacement)
@@ -0,0 +1,20 @@
// WITH_STDLIB
// WORKS_WHEN_VALUE_CLASS
// LANGUAGE: +ValueClasses
// FILE: Kt15AbstractMethodError2.kt
OPTIONAL_JVM_INLINE_ANNOTATION
value class MyValueClazz(val base: Long)
fun interface MyInterface {
fun myMethod(x: MyValueClazz)
}
// FILE: Kt15AbstractMethodErrorRepro.kt
fun box(): String {
val foo = MyInterface { _ -> }
foo.myMethod(MyValueClazz(0L))
return "OK"
}
@@ -0,0 +1,20 @@
// WITH_STDLIB
// WORKS_WHEN_VALUE_CLASS
// LANGUAGE: +ValueClasses
// FILE: Kt15AbstractMethodErrorRepro.kt
fun box(): String {
val foo = MyInterface { _ -> }
foo.myMethod(MyValueClazz(0L))
return "OK"
}
// FILE: Kt15AbstractMethodError2.kt
OPTIONAL_JVM_INLINE_ANNOTATION
value class MyValueClazz(val base: Long)
fun interface MyInterface {
fun myMethod(x: MyValueClazz)
}
@@ -19407,6 +19407,18 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
runTest("compiler/testData/codegen/box/inlineClasses/fieldNameClash.kt", TransformersFunctions.getReplaceOptionalJvmInlineAnnotationWithReal());
}
@Test
@TestMetadata("funInterfaceDoubleSuffux.kt")
public void testFunInterfaceDoubleSuffux() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/funInterfaceDoubleSuffux.kt", TransformersFunctions.getReplaceOptionalJvmInlineAnnotationWithReal());
}
@Test
@TestMetadata("funInterfaceDoubleSuffux2.kt")
public void testFunInterfaceDoubleSuffux2() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/funInterfaceDoubleSuffux2.kt", TransformersFunctions.getReplaceOptionalJvmInlineAnnotationWithReal());
}
@Test
@TestMetadata("functionExpression.kt")
public void testFunctionExpression() throws Exception {
@@ -20205,6 +20205,30 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
runTest("compiler/testData/codegen/box/inlineClasses/fieldNameClash.kt", TransformersFunctions.getRemoveOptionalJvmInlineAnnotation());
}
@Test
@TestMetadata("funInterfaceDoubleSuffux.kt")
public void testFunInterfaceDoubleSuffux() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/funInterfaceDoubleSuffux.kt", TransformersFunctions.getReplaceOptionalJvmInlineAnnotationWithReal());
}
@Test
@TestMetadata("funInterfaceDoubleSuffux2.kt")
public void testFunInterfaceDoubleSuffux2() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/funInterfaceDoubleSuffux2.kt", TransformersFunctions.getReplaceOptionalJvmInlineAnnotationWithReal());
}
@Test
@TestMetadata("funInterfaceDoubleSuffux2.kt")
public void testFunInterfaceDoubleSuffux2_valueClasses() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/funInterfaceDoubleSuffux2.kt", TransformersFunctions.getRemoveOptionalJvmInlineAnnotation());
}
@Test
@TestMetadata("funInterfaceDoubleSuffux.kt")
public void testFunInterfaceDoubleSuffux_valueClasses() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/funInterfaceDoubleSuffux.kt", TransformersFunctions.getRemoveOptionalJvmInlineAnnotation());
}
@Test
@TestMetadata("functionExpression.kt")
public void testFunctionExpression() throws Exception {
@@ -16197,6 +16197,16 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
runTest("compiler/testData/codegen/box/inlineClasses/fieldNameClash.kt", TransformersFunctions.getReplaceOptionalJvmInlineAnnotationWithReal());
}
@TestMetadata("funInterfaceDoubleSuffux.kt")
public void testFunInterfaceDoubleSuffux() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/funInterfaceDoubleSuffux.kt", TransformersFunctions.getReplaceOptionalJvmInlineAnnotationWithReal());
}
@TestMetadata("funInterfaceDoubleSuffux2.kt")
public void testFunInterfaceDoubleSuffux2() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/funInterfaceDoubleSuffux2.kt", TransformersFunctions.getReplaceOptionalJvmInlineAnnotationWithReal());
}
@TestMetadata("functionExpression.kt")
public void testFunctionExpression() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/functionExpression.kt", TransformersFunctions.getReplaceOptionalJvmInlineAnnotationWithReal());
@@ -15263,6 +15263,18 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/inlineClasses/fieldNameClash.kt", TransformersFunctions.getRemoveOptionalJvmInlineAnnotation());
}
@Test
@TestMetadata("funInterfaceDoubleSuffux.kt")
public void testFunInterfaceDoubleSuffux() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/funInterfaceDoubleSuffux.kt", TransformersFunctions.getRemoveOptionalJvmInlineAnnotation());
}
@Test
@TestMetadata("funInterfaceDoubleSuffux2.kt")
public void testFunInterfaceDoubleSuffux2() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/funInterfaceDoubleSuffux2.kt", TransformersFunctions.getRemoveOptionalJvmInlineAnnotation());
}
@Test
@TestMetadata("functionExpression.kt")
public void testFunctionExpression() throws Exception {
@@ -15227,6 +15227,18 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/inlineClasses/fieldNameClash.kt", TransformersFunctions.getRemoveOptionalJvmInlineAnnotation());
}
@Test
@TestMetadata("funInterfaceDoubleSuffux.kt")
public void testFunInterfaceDoubleSuffux() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/funInterfaceDoubleSuffux.kt", TransformersFunctions.getRemoveOptionalJvmInlineAnnotation());
}
@Test
@TestMetadata("funInterfaceDoubleSuffux2.kt")
public void testFunInterfaceDoubleSuffux2() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/funInterfaceDoubleSuffux2.kt", TransformersFunctions.getRemoveOptionalJvmInlineAnnotation());
}
@Test
@TestMetadata("functionExpression.kt")
public void testFunctionExpression() throws Exception {
@@ -12829,6 +12829,16 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest
runTest("compiler/testData/codegen/box/inlineClasses/fieldNameClash.kt", TransformersFunctions.getRemoveOptionalJvmInlineAnnotation());
}
@TestMetadata("funInterfaceDoubleSuffux.kt")
public void testFunInterfaceDoubleSuffux() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/funInterfaceDoubleSuffux.kt", TransformersFunctions.getRemoveOptionalJvmInlineAnnotation());
}
@TestMetadata("funInterfaceDoubleSuffux2.kt")
public void testFunInterfaceDoubleSuffux2() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/funInterfaceDoubleSuffux2.kt", TransformersFunctions.getRemoveOptionalJvmInlineAnnotation());
}
@TestMetadata("functionExpression.kt")
public void testFunctionExpression() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/functionExpression.kt", TransformersFunctions.getRemoveOptionalJvmInlineAnnotation());
@@ -15993,6 +15993,8 @@ public class ExternalTestGenerated extends AbstractExternalNativeBlackBoxTest {
register("compiler/testData/codegen/box/inlineClasses/extLambdaInInlineClassFun.kt", TransformersFunctions.getRemoveOptionalJvmInlineAnnotation());
register("compiler/testData/codegen/box/inlineClasses/extLambdaInInlineClassFun2.kt", TransformersFunctions.getRemoveOptionalJvmInlineAnnotation());
register("compiler/testData/codegen/box/inlineClasses/fieldNameClash.kt", TransformersFunctions.getRemoveOptionalJvmInlineAnnotation());
register("compiler/testData/codegen/box/inlineClasses/funInterfaceDoubleSuffux.kt", TransformersFunctions.getRemoveOptionalJvmInlineAnnotation());
register("compiler/testData/codegen/box/inlineClasses/funInterfaceDoubleSuffux2.kt", TransformersFunctions.getRemoveOptionalJvmInlineAnnotation());
register("compiler/testData/codegen/box/inlineClasses/functionExpression.kt", TransformersFunctions.getRemoveOptionalJvmInlineAnnotation());
register("compiler/testData/codegen/box/inlineClasses/genericInlineClassSynthMembers.kt", TransformersFunctions.getRemoveOptionalJvmInlineAnnotation());
register("compiler/testData/codegen/box/inlineClasses/genericVararg2ndConstructor.kt", TransformersFunctions.getRemoveOptionalJvmInlineAnnotation());
@@ -16549,6 +16551,20 @@ public class ExternalTestGenerated extends AbstractExternalNativeBlackBoxTest {
runTest("compiler/testData/codegen/box/inlineClasses/fieldNameClash.kt");
}
@Test
@TestMetadata("funInterfaceDoubleSuffux.kt")
public void testFunInterfaceDoubleSuffux() throws Exception {
// There is a registered source transformer for the testcase: TransformersFunctions.getRemoveOptionalJvmInlineAnnotation()
runTest("compiler/testData/codegen/box/inlineClasses/funInterfaceDoubleSuffux.kt");
}
@Test
@TestMetadata("funInterfaceDoubleSuffux2.kt")
public void testFunInterfaceDoubleSuffux2() throws Exception {
// There is a registered source transformer for the testcase: TransformersFunctions.getRemoveOptionalJvmInlineAnnotation()
runTest("compiler/testData/codegen/box/inlineClasses/funInterfaceDoubleSuffux2.kt");
}
@Test
@TestMetadata("functionExpression.kt")
public void testFunctionExpression() throws Exception {