FIR2IR: fix dispatch receiver generation (non-function case)

This commit is contained in:
Mikhail Glukhikh
2020-02-04 13:14:48 +03:00
parent b09b2673bf
commit f7d658b624
4 changed files with 14 additions and 7 deletions
@@ -128,6 +128,18 @@ class Fir2IrVisitor(
return this
}
private fun lastDispatchReceiverParameter(): IrValueParameter? {
val dispatchReceiver = functionStack.lastOrNull()?.dispatchReceiverParameter
return if (dispatchReceiver != null) {
// Use the dispatch receiver of the containing function
dispatchReceiver
} else {
val lastClassSymbol = classStack.lastOrNull()?.symbol
// Use the dispatch receiver of the containing class
lastClassSymbol?.owner?.thisReceiver
}
}
private val subjectVariableStack = mutableListOf<IrVariable>()
private fun <T> IrVariable?.withSubject(f: () -> T): T {
@@ -708,9 +720,8 @@ class Fir2IrVisitor(
return typeRef.convertWithOffsets { startOffset, endOffset ->
if (calleeReference is FirSuperReference) {
if (typeRef !is FirComposedSuperTypeRef) {
val dispatchReceiver = functionStack.lastOrNull()?.dispatchReceiverParameter
val dispatchReceiver = lastDispatchReceiverParameter()
if (dispatchReceiver != null) {
// Use the dispatch receiver of the containing function
return@convertWithOffsets IrGetValueImpl(startOffset, endOffset, dispatchReceiver.type, dispatchReceiver.symbol)
}
}
@@ -912,9 +923,8 @@ class Fir2IrVisitor(
}
}
val dispatchReceiver = this.functionStack.lastOrNull()?.dispatchReceiverParameter
val dispatchReceiver = lastDispatchReceiverParameter()
if (dispatchReceiver != null) {
// Use the dispatch receiver of the containing function
return thisReceiverExpression.convertWithOffsets { startOffset, endOffset ->
IrGetValueImpl(startOffset, endOffset, dispatchReceiver.type, dispatchReceiver.symbol)
}
-1
View File
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
open class A {
open val foo: String = "OK"
}
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
open class A {
internal open val field = "F"
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
open class A {
internal open val field = "F"