[FIR2IR] Re-use receiver application logic in callable ref conversion

This commit is contained in:
Mikhail Glukhikh
2020-03-30 11:21:33 +03:00
parent 1b1902f6ee
commit 697006d782
32 changed files with 14 additions and 40 deletions
@@ -23,6 +23,7 @@ import org.jetbrains.kotlin.fir.symbols.impl.FirCallableSymbol
import org.jetbrains.kotlin.fir.symbols.impl.FirClassSymbol
import org.jetbrains.kotlin.fir.symbols.impl.FirFunctionSymbol
import org.jetbrains.kotlin.fir.types.*
import org.jetbrains.kotlin.ir.declarations.IrFunction
import org.jetbrains.kotlin.ir.expressions.IrErrorCallExpression
import org.jetbrains.kotlin.ir.expressions.IrExpression
import org.jetbrains.kotlin.ir.expressions.IrStatementOrigin
@@ -62,14 +63,8 @@ internal class CallGenerator(
typeArgumentsCount = 0,
reflectionTarget = symbol
).apply {
val firReceiver = callableReferenceAccess.explicitReceiver
if (firReceiver != null && firReceiver !is FirResolvedQualifier) {
val irReceiver = visitor.convertToIrExpression(firReceiver)
if (symbol.owner.dispatchReceiverParameter != null) {
this.dispatchReceiver = irReceiver
} else if (symbol.owner.extensionReceiverParameter != null) {
this.extensionReceiver = irReceiver
}
if (callableReferenceAccess.explicitReceiver !is FirResolvedQualifier) {
applyReceivers(callableReferenceAccess)
}
}
}
@@ -354,12 +349,12 @@ internal class CallGenerator(
private fun IrExpression.applyReceivers(qualifiedAccess: FirQualifiedAccess): IrExpression {
return when (this) {
is IrCallImpl -> {
val ownerFunction = symbol.owner
if (ownerFunction.dispatchReceiverParameter != null) {
is IrCallWithIndexedArgumentsBase -> {
val ownerFunction = symbol.owner as? IrFunction
if (ownerFunction?.dispatchReceiverParameter != null) {
dispatchReceiver = qualifiedAccess.findIrDispatchReceiver()
}
if (ownerFunction.extensionReceiverParameter != null) {
if (ownerFunction?.extensionReceiverParameter != null) {
extensionReceiver = qualifiedAccess.findIrExtensionReceiver()
}
this
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
interface T {
fun foo() = "OK"
}
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
open class Test {
companion object {
fun testStatic(ic: InnerClass): NotInnerClass = NotInnerClass(ic.value)
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
class Outer(val value: String) {
inner class Inner {
@@ -1,5 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
open class A(val s: String) {
open inner class B(val s: String) {
fun testB() = s + this@A.s
@@ -1,5 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
open class A(val s: String) {
val z = s
-1
View File
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
class Outer() {
inner class Inner() {
val outer: Outer get() = this@Outer
-1
View File
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
public class Test {
val content = 1
inner class A {
-1
View File
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
open class Base {
fun doSomething() {
-1
View File
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
class Foo(private val s: String) {
inner class Inner {
private val x = {
@@ -1,5 +1,4 @@
// !LANGUAGE: -NormalizeConstructorCalls
// IGNORE_BACKEND_FIR: JVM_IR
// TARGET_BACKEND: JVM
// WITH_RUNTIME
// FILE: test.kt
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
class A {
inner class B(val a: String = "a", val b: Int = 55, val c: String = "c")
}
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
class A {
inner class B(val a: Double = 1.0, val b: Int = 55, val c: String = "c")
}
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
class A {
inner class B(val a: Int = 1,
val b: Int = 2,
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
class Outer {
class Nested
inner class Inner
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
class Outer {
inner class Inner<T>(val t: T) {
fun box() = t
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
class Outer {
inner class Inner {
fun O() = this@Outer.O
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
class Outer {
inner class Inner {
fun box() = "OK"
-1
View File
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
class Test {
interface Foo { }
-1
View File
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
//KT-3927 Inner class cannot be instantiated with child instance of outer class
abstract class Base {
-2
View File
@@ -1,5 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
fun <T> tableView(init: Table<T>.() -> Unit) {
Table<T>().init()
}
-1
View File
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
// IGNORE_BACKEND: JS_IR
// MODULE: lib
// FILE: lib.kt
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
// See also KT-6299
public open class Outer private constructor(val s: String) {
inner class Inner: Outer("O") {
-1
View File
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
class D {
companion object {
protected val F: String = "OK"
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
open class SuperClass(val arg: () -> String)
object obj {
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
fun box(): String {
A.Nested().nestedA()
A.Nested().Inner().innerA()
@@ -56,6 +56,7 @@ FILE fqName:test fileName:/importedFromObject.kt
FIELD PROPERTY_BACKING_FIELD name:test2 type:kotlin.reflect.KFunction0<kotlin.String> visibility:private [final,static]
EXPRESSION_BODY
FUNCTION_REFERENCE 'public final fun foo (): kotlin.String declared in test.Foo' type=kotlin.reflect.KFunction0<kotlin.String> origin=null reflectionTarget=<same>
$this: GET_OBJECT 'CLASS OBJECT name:Foo modality:FINAL visibility:public superTypes:[kotlin.Any]' type=test.Foo
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-test2> visibility:public modality:FINAL <> () returnType:kotlin.reflect.KFunction0<kotlin.String>
correspondingProperty: PROPERTY name:test2 visibility:public modality:FINAL [val]
BLOCK_BODY
@@ -53,6 +53,7 @@ FILE fqName:<root> fileName:/typeArguments.kt
FIELD PROPERTY_BACKING_FIELD name:test3 type:kotlin.Function1<kotlin.Int, kotlin.Unit> visibility:private [final,static]
EXPRESSION_BODY
FUNCTION_REFERENCE 'public final fun objectMember <T> (x: T of <root>.Host.objectMember): kotlin.Unit [inline] declared in <root>.Host' type=kotlin.reflect.KFunction1<kotlin.Int, kotlin.Unit> origin=null reflectionTarget=<same>
$this: GET_OBJECT 'CLASS OBJECT name:Host modality:FINAL visibility:public superTypes:[kotlin.Any]' type=<root>.Host
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-test3> visibility:public modality:FINAL <> () returnType:kotlin.Function1<kotlin.Int, kotlin.Unit>
correspondingProperty: PROPERTY name:test3 visibility:public modality:FINAL [val]
BLOCK_BODY
@@ -67,3 +67,4 @@ FILE fqName:<root> fileName:/withAdaptedArguments.kt
RETURN type=kotlin.Nothing from='public final fun testImportedObjectMember (): IrErrorType declared in <root>'
ERROR_CALL 'Unresolved reference: <Inapplicable(INAPPLICABLE): [/use]>#' type=IrErrorType
FUNCTION_REFERENCE 'public final fun importedObjectMemberWithVarargs (vararg xs: kotlin.Int): kotlin.String declared in <root>.Host' type=kotlin.reflect.KFunction1<kotlin.IntArray, kotlin.String> origin=null reflectionTarget=<same>
$this: GET_OBJECT 'CLASS OBJECT name:Host modality:FINAL visibility:public superTypes:[kotlin.Any]' type=<root>.Host
@@ -4,6 +4,8 @@ FILE fqName:<root> fileName:/constructorWithOwnTypeParametersCall.kt
RETURN type=kotlin.Nothing from='public final fun testKotlin (): <root>.K1.K2<kotlin.String> declared in <root>'
CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in <root>.K1.K2' type=<root>.K1.K2<kotlin.String> origin=null
<class: T2>: kotlin.String
$outer: CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in <root>.K1' type=<root>.K1<kotlin.Int> origin=null
<class: T1>: kotlin.Int
FUN name:testJava visibility:public modality:FINAL <> () returnType:<root>.J1.J2<kotlin.Double?>
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun testJava (): <root>.J1.J2<kotlin.Double?> declared in <root>'
@@ -14,6 +14,7 @@ FILE fqName:<root> fileName:/javaConstructorWithTypeParameters.kt
RETURN type=kotlin.Nothing from='public final fun test3 (j1: <root>.J1<kotlin.Any>): <root>.J1.J2<kotlin.Int?> declared in <root>'
CONSTRUCTOR_CALL 'public constructor <init> () declared in <root>.J1.J2' type=<root>.J1.J2<kotlin.Int?> origin=null
<class: T2>: kotlin.Int?
$outer: GET_VAR 'j1: <root>.J1<kotlin.Any> declared in <root>.test3' type=<root>.J1<kotlin.Any> origin=null
FUN name:test4 visibility:public modality:FINAL <> (j1:<root>.J1<kotlin.Any>) returnType:<root>.J1.J2<kotlin.Int?>
VALUE_PARAMETER name:j1 index:0 type:<root>.J1<kotlin.Any>
BLOCK_BODY
@@ -9,6 +9,7 @@ FILE fqName:<root> fileName:/javaInnerClass.kt
FIELD PROPERTY_BACKING_FIELD name:test type:<root>.J.JInner visibility:private [final]
EXPRESSION_BODY
CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in <root>.J.JInner' type=<root>.J.JInner origin=null
$outer: GET_VAR '<this>: <root>.Test1 declared in <root>.Test1' type=<root>.Test1 origin=null
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-test> visibility:public modality:FINAL <> ($this:<root>.Test1) returnType:<root>.J.JInner
correspondingProperty: PROPERTY name:test visibility:public modality:FINAL [val]
$this: VALUE_PARAMETER name:<this> type:<root>.Test1