FIR: introduce separate companion object resolve context

Before this commit, during the resolve of companion objects we used
the same context than for any nested class. However, during companion
object resolve we should not have companion object receiver itself
accessible in any case (in particular, it should not be accessible
in constructor). So in this commit we introduced separate context
for this purpose.
This commit is contained in:
Mikhail Glukhikh
2021-01-14 18:23:05 +03:00
parent f282c3e547
commit f85fc47383
10 changed files with 72 additions and 33 deletions
@@ -0,0 +1,36 @@
FILE: selfReferenceToCompanionObject.kt
public abstract class Base : R|kotlin/Any| {
public constructor(fn: R|() -> kotlin/String|): R|Base| {
super<R|kotlin/Any|>()
}
public final val fn: R|() -> kotlin/String| = R|<local>/fn|
public get(): R|() -> kotlin/String|
}
public final class Host : R|kotlin/Any| {
public constructor(): R|Host| {
super<R|kotlin/Any|>()
}
public final companion object Companion : R|Base| {
private constructor(): R|Host.Companion| {
super<R|Base|>(R|kotlin/run|<R|() -> kotlin/String|>(<L> = run@fun <anonymous>(): R|() -> kotlin/String| <kind=EXACTLY_ONCE> {
^ run@fun <anonymous>(): R|kotlin/String| {
^ Q|Host|.R|/Host.Companion.ok|()
}
}
))
}
public final fun ok(): R|kotlin/String| {
^ok String(OK)
}
}
}
public final fun box(): R|kotlin/String| {
^box Q|Host.Companion|.R|/Base.fn|.R|SubstitutionOverride<kotlin/Function0.invoke: R|kotlin/String|>|()
}
@@ -0,0 +1,9 @@
abstract class Base(val fn: () -> String)
class Host {
companion object : Base(run { { Host.ok() } }) {
fun ok() = "OK"
}
}
fun box() = Host.Companion.fn()