IR: keep local scope with counter maps across LDL invocations

Since LocalDeclarationsLowering is a BodyLoweringPass, local
functions inside one declaration are handled independently of local
functions in the other declaration. This can lead to name clashes, in
case a local function with the same name and signature is declared in
overloads in the same container, which results in a signature clash
error in JVM IR.

The issue became more common with the introduction of adapted function
references, where psi2ir generates a local adapter-function with a
predefined name, which can easily clash with another reference to the
same target in an overload. This led to a compilation error when
bootstrapping Kotlin with JVM IR, for example in GradleIRBuilder.kt
where there are a lot of references to the same function.
This commit is contained in:
Alexander Udalov
2020-05-04 17:39:26 +02:00
parent 50506658c0
commit 91ef053fbc
10 changed files with 166 additions and 23 deletions
@@ -1515,6 +1515,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/manyDefaultsAndVararg.kt");
}
@TestMetadata("noNameClashForReferencesToSameFunction.kt")
public void testNoNameClashForReferencesToSameFunction() throws Exception {
runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/noNameClashForReferencesToSameFunction.kt");
}
@TestMetadata("simpleDefaultArgument.kt")
public void testSimpleDefaultArgument() throws Exception {
runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/simpleDefaultArgument.kt");
@@ -10122,6 +10127,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/functions/localFunctions/nameClash.kt");
}
@TestMetadata("nameClashAcrossDifferentContainers.kt")
public void testNameClashAcrossDifferentContainers() throws Exception {
runTest("compiler/testData/codegen/box/functions/localFunctions/nameClashAcrossDifferentContainers.kt");
}
@TestMetadata("overloadedLocalFunWithoutClosure.kt")
public void testOverloadedLocalFunWithoutClosure() throws Exception {
runTest("compiler/testData/codegen/box/functions/localFunctions/overloadedLocalFunWithoutClosure.kt");
@@ -1515,6 +1515,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/manyDefaultsAndVararg.kt");
}
@TestMetadata("noNameClashForReferencesToSameFunction.kt")
public void testNoNameClashForReferencesToSameFunction() throws Exception {
runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/noNameClashForReferencesToSameFunction.kt");
}
@TestMetadata("simpleDefaultArgument.kt")
public void testSimpleDefaultArgument() throws Exception {
runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/simpleDefaultArgument.kt");
@@ -10122,6 +10127,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/functions/localFunctions/nameClash.kt");
}
@TestMetadata("nameClashAcrossDifferentContainers.kt")
public void testNameClashAcrossDifferentContainers() throws Exception {
runTest("compiler/testData/codegen/box/functions/localFunctions/nameClashAcrossDifferentContainers.kt");
}
@TestMetadata("overloadedLocalFunWithoutClosure.kt")
public void testOverloadedLocalFunWithoutClosure() throws Exception {
runTest("compiler/testData/codegen/box/functions/localFunctions/overloadedLocalFunWithoutClosure.kt");