[FIR] Allow more than one function with some name in local scope

This commit is contained in:
Mikhail Glukhikh
2020-01-27 16:36:47 +03:00
parent 0725a336fc
commit ce1f746c5e
3 changed files with 9 additions and 9 deletions
@@ -14,13 +14,15 @@ import org.jetbrains.kotlin.name.Name
class FirLocalScope : FirScope() { class FirLocalScope : FirScope() {
val properties = mutableMapOf<Name, FirVariableSymbol<*>>() val properties = mutableMapOf<Name, FirVariableSymbol<*>>()
val functions = mutableMapOf<Name, FirFunctionSymbol<*>>() val functions = mutableMapOf<Name, MutableList<FirFunctionSymbol<*>>>()
val classes = mutableMapOf<Name, FirRegularClassSymbol>() val classes = mutableMapOf<Name, FirRegularClassSymbol>()
fun storeDeclaration(declaration: FirNamedDeclaration) { fun storeDeclaration(declaration: FirNamedDeclaration) {
when (declaration) { when (declaration) {
is FirVariable<*> -> properties[declaration.name] = declaration.symbol is FirVariable<*> -> properties[declaration.name] = declaration.symbol
is FirSimpleFunction -> functions[declaration.name] = declaration.symbol as FirNamedFunctionSymbol is FirSimpleFunction -> functions.getOrPut(declaration.name) {
mutableListOf()
}.add(declaration.symbol as FirNamedFunctionSymbol)
is FirRegularClass -> classes[declaration.name] = declaration.symbol is FirRegularClass -> classes[declaration.name] = declaration.symbol
} }
} }
@@ -30,11 +32,9 @@ class FirLocalScope : FirScope() {
} }
override fun processFunctionsByName(name: Name, processor: (FirFunctionSymbol<*>) -> Unit) { override fun processFunctionsByName(name: Name, processor: (FirFunctionSymbol<*>) -> Unit) {
val function = functions[name] for (function in functions[name].orEmpty()) {
if (function != null) {
processor(function) processor(function)
} }
} }
override fun processPropertiesByName(name: Name, processor: (FirCallableSymbol<*>) -> Unit) { override fun processPropertiesByName(name: Name, processor: (FirCallableSymbol<*>) -> Unit) {
@@ -5,11 +5,11 @@ interface A {
fun test_1() { fun test_1() {
fun Int.transform(): Int = 1 fun Int.transform(): Int = 1
fun A.transform(): Int { fun A.transform(): Int {
return x.<!INAPPLICABLE_CANDIDATE!>transform<!>() return x.transform()
} }
val y = 1 val y = 1
y.<!INAPPLICABLE_CANDIDATE!>transform<!>() y.transform()
} }
fun test_2() { fun test_2() {
@@ -10,11 +10,11 @@ FILE: localFunctionsHiding.kt
} }
local final fun R|A|.transform(): R|kotlin/Int| { local final fun R|A|.transform(): R|kotlin/Int| {
^transform this@R|<local>/transform|.R|/A.x|.<Inapplicable(WRONG_RECEIVER): [<local>/transform]>#() ^transform this@R|<local>/transform|.R|/A.x|.R|<local>/transform|()
} }
lval y: R|kotlin/Int| = Int(1) lval y: R|kotlin/Int| = Int(1)
R|<local>/y|.<Inapplicable(WRONG_RECEIVER): [<local>/transform]>#() R|<local>/y|.R|<local>/transform|()
} }
public final fun test_2(): R|kotlin/Unit| { public final fun test_2(): R|kotlin/Unit| {
local final fun R|kotlin/Int|.transform(): R|kotlin/Int| { local final fun R|kotlin/Int|.transform(): R|kotlin/Int| {