IR: avoid name clashes between raised local functions.
This commit is contained in:
+7
-2
@@ -207,6 +207,7 @@ class LocalDeclarationsLowering(
|
|||||||
val localFunctions: MutableMap<IrFunction, LocalFunctionContext> = LinkedHashMap()
|
val localFunctions: MutableMap<IrFunction, LocalFunctionContext> = LinkedHashMap()
|
||||||
val localClasses: MutableMap<IrClass, LocalClassContext> = LinkedHashMap()
|
val localClasses: MutableMap<IrClass, LocalClassContext> = LinkedHashMap()
|
||||||
val localClassConstructors: MutableMap<IrConstructor, LocalClassConstructorContext> = LinkedHashMap()
|
val localClassConstructors: MutableMap<IrConstructor, LocalClassConstructorContext> = LinkedHashMap()
|
||||||
|
val usedLocalFunctionNames: MutableSet<Name> = mutableSetOf()
|
||||||
|
|
||||||
val transformedDeclarations = mutableMapOf<IrSymbolOwner, IrDeclaration>()
|
val transformedDeclarations = mutableMapOf<IrSymbolOwner, IrDeclaration>()
|
||||||
|
|
||||||
@@ -530,8 +531,9 @@ class LocalDeclarationsLowering(
|
|||||||
|
|
||||||
private fun suggestLocalName(declaration: IrDeclarationWithName): String {
|
private fun suggestLocalName(declaration: IrDeclarationWithName): String {
|
||||||
localFunctions[declaration]?.let {
|
localFunctions[declaration]?.let {
|
||||||
|
val baseName = if (declaration.name.isSpecial) "lambda" else declaration.name
|
||||||
if (it.index >= 0)
|
if (it.index >= 0)
|
||||||
return "lambda-${it.index}"
|
return "$baseName-${it.index}"
|
||||||
}
|
}
|
||||||
|
|
||||||
return localNameProvider.localName(declaration)
|
return localNameProvider.localName(declaration)
|
||||||
@@ -827,9 +829,12 @@ class LocalDeclarationsLowering(
|
|||||||
localFunctions[declaration] =
|
localFunctions[declaration] =
|
||||||
LocalFunctionContext(
|
LocalFunctionContext(
|
||||||
declaration,
|
declaration,
|
||||||
if (declaration.name.isSpecial) (scopeWithIr as ScopeWithCounter).counter++ else -1,
|
if (declaration.name.isSpecial || declaration.name in usedLocalFunctionNames)
|
||||||
|
(scopeWithIr as ScopeWithCounter).counter++
|
||||||
|
else -1,
|
||||||
scopeWithIr.irElement as IrDeclarationContainer
|
scopeWithIr.irElement as IrDeclarationContainer
|
||||||
)
|
)
|
||||||
|
usedLocalFunctionNames.add(declaration.name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
// IGNORE_BACKEND_FIR: JVM_IR
|
||||||
|
|
||||||
|
fun test(b: Boolean): String {
|
||||||
|
if (b) {
|
||||||
|
fun result() = "OK"
|
||||||
|
return result()
|
||||||
|
} else {
|
||||||
|
fun result() = "Fail"
|
||||||
|
return result()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fun box(): String = test(true)
|
||||||
+5
@@ -12206,6 +12206,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
|||||||
runTest("compiler/testData/codegen/box/functions/localFunctions/localFunctionVsLocalVariable.kt");
|
runTest("compiler/testData/codegen/box/functions/localFunctions/localFunctionVsLocalVariable.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("nameClash.kt")
|
||||||
|
public void testNameClash() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/functions/localFunctions/nameClash.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("overloadedLocalFunWithoutClosure.kt")
|
@TestMetadata("overloadedLocalFunWithoutClosure.kt")
|
||||||
public void testOverloadedLocalFunWithoutClosure() throws Exception {
|
public void testOverloadedLocalFunWithoutClosure() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/functions/localFunctions/overloadedLocalFunWithoutClosure.kt");
|
runTest("compiler/testData/codegen/box/functions/localFunctions/overloadedLocalFunWithoutClosure.kt");
|
||||||
|
|||||||
+5
@@ -12206,6 +12206,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
|||||||
runTest("compiler/testData/codegen/box/functions/localFunctions/localFunctionVsLocalVariable.kt");
|
runTest("compiler/testData/codegen/box/functions/localFunctions/localFunctionVsLocalVariable.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("nameClash.kt")
|
||||||
|
public void testNameClash() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/functions/localFunctions/nameClash.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("overloadedLocalFunWithoutClosure.kt")
|
@TestMetadata("overloadedLocalFunWithoutClosure.kt")
|
||||||
public void testOverloadedLocalFunWithoutClosure() throws Exception {
|
public void testOverloadedLocalFunWithoutClosure() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/functions/localFunctions/overloadedLocalFunWithoutClosure.kt");
|
runTest("compiler/testData/codegen/box/functions/localFunctions/overloadedLocalFunWithoutClosure.kt");
|
||||||
|
|||||||
+5
@@ -11051,6 +11051,11 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
|||||||
runTest("compiler/testData/codegen/box/functions/localFunctions/localFunctionVsLocalVariable.kt");
|
runTest("compiler/testData/codegen/box/functions/localFunctions/localFunctionVsLocalVariable.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("nameClash.kt")
|
||||||
|
public void testNameClash() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/functions/localFunctions/nameClash.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("overloadedLocalFunWithoutClosure.kt")
|
@TestMetadata("overloadedLocalFunWithoutClosure.kt")
|
||||||
public void testOverloadedLocalFunWithoutClosure() throws Exception {
|
public void testOverloadedLocalFunWithoutClosure() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/functions/localFunctions/overloadedLocalFunWithoutClosure.kt");
|
runTest("compiler/testData/codegen/box/functions/localFunctions/overloadedLocalFunWithoutClosure.kt");
|
||||||
|
|||||||
+5
@@ -11051,6 +11051,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
|||||||
runTest("compiler/testData/codegen/box/functions/localFunctions/localFunctionVsLocalVariable.kt");
|
runTest("compiler/testData/codegen/box/functions/localFunctions/localFunctionVsLocalVariable.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("nameClash.kt")
|
||||||
|
public void testNameClash() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/functions/localFunctions/nameClash.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("overloadedLocalFunWithoutClosure.kt")
|
@TestMetadata("overloadedLocalFunWithoutClosure.kt")
|
||||||
public void testOverloadedLocalFunWithoutClosure() throws Exception {
|
public void testOverloadedLocalFunWithoutClosure() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/functions/localFunctions/overloadedLocalFunWithoutClosure.kt");
|
runTest("compiler/testData/codegen/box/functions/localFunctions/overloadedLocalFunWithoutClosure.kt");
|
||||||
|
|||||||
Generated
+5
@@ -9511,6 +9511,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
|
|||||||
runTest("compiler/testData/codegen/box/functions/localFunctions/localFunctionVsLocalVariable.kt");
|
runTest("compiler/testData/codegen/box/functions/localFunctions/localFunctionVsLocalVariable.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("nameClash.kt")
|
||||||
|
public void testNameClash() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/functions/localFunctions/nameClash.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("overloadedLocalFunWithoutClosure.kt")
|
@TestMetadata("overloadedLocalFunWithoutClosure.kt")
|
||||||
public void testOverloadedLocalFunWithoutClosure() throws Exception {
|
public void testOverloadedLocalFunWithoutClosure() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/functions/localFunctions/overloadedLocalFunWithoutClosure.kt");
|
runTest("compiler/testData/codegen/box/functions/localFunctions/overloadedLocalFunWithoutClosure.kt");
|
||||||
|
|||||||
+5
@@ -10591,6 +10591,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
|||||||
runTest("compiler/testData/codegen/box/functions/localFunctions/localFunctionVsLocalVariable.kt");
|
runTest("compiler/testData/codegen/box/functions/localFunctions/localFunctionVsLocalVariable.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("nameClash.kt")
|
||||||
|
public void testNameClash() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/functions/localFunctions/nameClash.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("overloadedLocalFunWithoutClosure.kt")
|
@TestMetadata("overloadedLocalFunWithoutClosure.kt")
|
||||||
public void testOverloadedLocalFunWithoutClosure() throws Exception {
|
public void testOverloadedLocalFunWithoutClosure() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/functions/localFunctions/overloadedLocalFunWithoutClosure.kt");
|
runTest("compiler/testData/codegen/box/functions/localFunctions/overloadedLocalFunWithoutClosure.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user