FIR: resolve local class in anonymous initializer.

This commit is contained in:
Jinseong Jeon
2020-05-19 22:42:26 -07:00
committed by Mikhail Glukhikh
parent 2ff5b253ae
commit 0d3301b695
8 changed files with 11 additions and 8 deletions
@@ -53,12 +53,18 @@ abstract class BaseFirBuilder<T>(val baseSession: FirSession, val context: Conte
abstract val T?.selectorExpression: T?
/**** Class name utils ****/
inline fun <T> withChildClassName(name: Name, l: () -> T): T {
inline fun <T> withChildClassName(
name: Name,
isLocal: Boolean = context.firFunctionTargets.isNotEmpty(),
l: () -> T
): T {
context.className = context.className.child(name)
context.localBits.add(isLocal)
return try {
l()
} finally {
context.className = context.className.parent()
context.localBits.removeLast()
}
}
@@ -18,7 +18,8 @@ import org.jetbrains.kotlin.name.Name
class Context<T> {
lateinit var packageFqName: FqName
var className: FqName = FqName.ROOT
val currentClassId get() = ClassId(packageFqName, className, firFunctionTargets.isNotEmpty())
val localBits: MutableList<Boolean> = mutableListOf()
val currentClassId get() = ClassId(packageFqName, className, localBits.lastOrNull() ?: false)
val firFunctionTargets = mutableListOf<FirFunctionTarget>()
val calleeNamesForLambda = mutableListOf<Name>()
@@ -370,7 +370,7 @@ class DeclarationsConverter(
val className = identifier.nameAsSafeName(if (modifiers.isCompanion()) "Companion" else "")
val isLocal = isClassLocal(classNode) { getParent() }
return withChildClassName(className) {
return withChildClassName(className, isLocal) {
withCapturedTypeParameters {
val status = FirDeclarationStatusImpl(
if (isLocal) Visibilities.LOCAL else modifiers.getVisibility(),
@@ -661,7 +661,7 @@ class RawFirBuilder(
}
override fun visitClassOrObject(classOrObject: KtClassOrObject, data: Unit): FirElement {
return withChildClassName(classOrObject.nameAsSafeName) {
return withChildClassName(classOrObject.nameAsSafeName, classOrObject.isLocal) {
val classKind = when (classOrObject) {
is KtObjectDeclaration -> ClassKind.OBJECT