[JVM_IR] Avoid using special names in static inline class replacements.

Fixes KT-46952
This commit is contained in:
Mads Ager
2021-05-27 15:55:39 +02:00
committed by Alexander Udalov
parent b1ab597616
commit f846dd8ea2
12 changed files with 64 additions and 7 deletions
@@ -15288,6 +15288,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
runTest("compiler/testData/codegen/box/extensionProperties/inClassWithSetter.kt");
}
@Test
@TestMetadata("kt46952.kt")
public void testKt46952() throws Exception {
runTest("compiler/testData/codegen/box/extensionProperties/kt46952.kt");
}
@Test
@TestMetadata("kt9897.kt")
public void testKt9897() throws Exception {
@@ -785,9 +785,6 @@ class LocalDeclarationsLowering(
}
}
private fun Name.stripSpecialMarkers(): String =
if (isSpecial) asString().substring(1, asString().length - 1) else asString()
private fun suggestNameForCapturedValue(declaration: IrValueDeclaration, usedNames: MutableSet<String>, isExplicitLocalFunction: Boolean = false): Name {
if (declaration is IrValueParameter) {
if (declaration.name.asString() == "<this>" && declaration.isDispatchReceiver()) {
@@ -808,7 +805,7 @@ class LocalDeclarationsLowering(
}
val base = if (declaration.name.isSpecial) {
declaration.name.stripSpecialMarkers()
declaration.name.asStringStripSpecialMarkers()
} else {
declaration.name.asString()
}
@@ -859,9 +856,9 @@ class LocalDeclarationsLowering(
val correspondingProperty = parentFun.safeAs<IrSimpleFunction>()?.correspondingPropertySymbol?.owner
return when {
correspondingProperty != null ->
correspondingProperty.name.stripSpecialMarkers()
correspondingProperty.name.asStringStripSpecialMarkers()
else ->
parentFun.name.stripSpecialMarkers()
parentFun.name.asStringStripSpecialMarkers()
}
}
@@ -206,8 +206,11 @@ class MemoizedInlineClassReplacements(
)
}
function.extensionReceiverParameter?.let {
val baseName =
(function as? IrSimpleFunction)?.correspondingPropertySymbol?.owner?.name?.asStringStripSpecialMarkers()
?: function.name
newValueParameters += it.copyTo(
this, index = newValueParameters.size, name = Name.identifier("\$this\$${function.name}"),
this, index = newValueParameters.size, name = Name.identifier("\$this\$$baseName"),
origin = IrDeclarationOrigin.MOVED_EXTENSION_RECEIVER
)
}
@@ -0,0 +1,8 @@
inline class C(val s: String)
fun f(g: () -> C): C = g()
val C.foo: C
get() = f { this }
fun box() = C("OK").foo.s
@@ -15288,6 +15288,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
runTest("compiler/testData/codegen/box/extensionProperties/inClassWithSetter.kt");
}
@Test
@TestMetadata("kt46952.kt")
public void testKt46952() throws Exception {
runTest("compiler/testData/codegen/box/extensionProperties/kt46952.kt");
}
@Test
@TestMetadata("kt9897.kt")
public void testKt9897() throws Exception {
@@ -15288,6 +15288,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
runTest("compiler/testData/codegen/box/extensionProperties/inClassWithSetter.kt");
}
@Test
@TestMetadata("kt46952.kt")
public void testKt46952() throws Exception {
runTest("compiler/testData/codegen/box/extensionProperties/kt46952.kt");
}
@Test
@TestMetadata("kt9897.kt")
public void testKt9897() throws Exception {
@@ -12552,6 +12552,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
runTest("compiler/testData/codegen/box/extensionProperties/inClassWithSetter.kt");
}
@TestMetadata("kt46952.kt")
public void testKt46952() throws Exception {
runTest("compiler/testData/codegen/box/extensionProperties/kt46952.kt");
}
@TestMetadata("kt9897.kt")
public void testKt9897() throws Exception {
runTest("compiler/testData/codegen/box/extensionProperties/kt9897.kt");
@@ -46,6 +46,12 @@ public final class Name implements Comparable<Name> {
return special;
}
@NotNull
public String asStringStripSpecialMarkers() {
if (isSpecial()) return asString().substring(1, asString().length() - 1);
return asString();
}
@Override
public int compareTo(Name that) {
return this.name.compareTo(that.name);
@@ -11141,6 +11141,11 @@ public class IrJsCodegenBoxES6TestGenerated extends AbstractIrJsCodegenBoxES6Tes
runTest("compiler/testData/codegen/box/extensionProperties/inClassWithSetter.kt");
}
@TestMetadata("kt46952.kt")
public void testKt46952() throws Exception {
runTest("compiler/testData/codegen/box/extensionProperties/kt46952.kt");
}
@TestMetadata("kt9897.kt")
public void testKt9897() throws Exception {
runTest("compiler/testData/codegen/box/extensionProperties/kt9897.kt");
@@ -10547,6 +10547,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/extensionProperties/inClassWithSetter.kt");
}
@TestMetadata("kt46952.kt")
public void testKt46952() throws Exception {
runTest("compiler/testData/codegen/box/extensionProperties/kt46952.kt");
}
@TestMetadata("kt9897.kt")
public void testKt9897() throws Exception {
runTest("compiler/testData/codegen/box/extensionProperties/kt9897.kt");
@@ -10547,6 +10547,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/extensionProperties/inClassWithSetter.kt");
}
@TestMetadata("kt46952.kt")
public void testKt46952() throws Exception {
runTest("compiler/testData/codegen/box/extensionProperties/kt46952.kt");
}
@TestMetadata("kt9897.kt")
public void testKt9897() throws Exception {
runTest("compiler/testData/codegen/box/extensionProperties/kt9897.kt");
@@ -5340,6 +5340,11 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest
runTest("compiler/testData/codegen/box/extensionProperties/inClassWithSetter.kt");
}
@TestMetadata("kt46952.kt")
public void testKt46952() throws Exception {
runTest("compiler/testData/codegen/box/extensionProperties/kt46952.kt");
}
@TestMetadata("kt9897.kt")
public void testKt9897() throws Exception {
runTest("compiler/testData/codegen/box/extensionProperties/kt9897.kt");