Implement script instance capturing in script lowering

for regular classes only. Reimplementing the main behavior of the
old BE and implementing few cases on top of it.
#KT-19423 fixed
This commit is contained in:
Ilya Chernikov
2021-11-24 15:51:02 +01:00
committed by TeamCityServer
parent 87952d63a3
commit cb5e451e05
22 changed files with 659 additions and 94 deletions
@@ -177,7 +177,12 @@ class ClosureAnnotator(irElement: IrElement, declaration: IrDeclaration) {
closureBuilder.declareVariable(this.thisReceiver)
if (this.isInner) {
closureBuilder.declareVariable((this.parent as IrClass).thisReceiver)
val receiver = when (val parent = this.parent) {
is IrClass -> parent.thisReceiver
is IrScript -> parent.thisReceiver
else -> error("unexpected parent $parent")
}
closureBuilder.declareVariable(receiver)
includeInParent(closureBuilder)
}