[FIR2IR] Re-use receiver application logic in callable ref conversion
This commit is contained in:
+7
-12
@@ -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.FirClassSymbol
|
||||||
import org.jetbrains.kotlin.fir.symbols.impl.FirFunctionSymbol
|
import org.jetbrains.kotlin.fir.symbols.impl.FirFunctionSymbol
|
||||||
import org.jetbrains.kotlin.fir.types.*
|
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.IrErrorCallExpression
|
||||||
import org.jetbrains.kotlin.ir.expressions.IrExpression
|
import org.jetbrains.kotlin.ir.expressions.IrExpression
|
||||||
import org.jetbrains.kotlin.ir.expressions.IrStatementOrigin
|
import org.jetbrains.kotlin.ir.expressions.IrStatementOrigin
|
||||||
@@ -62,14 +63,8 @@ internal class CallGenerator(
|
|||||||
typeArgumentsCount = 0,
|
typeArgumentsCount = 0,
|
||||||
reflectionTarget = symbol
|
reflectionTarget = symbol
|
||||||
).apply {
|
).apply {
|
||||||
val firReceiver = callableReferenceAccess.explicitReceiver
|
if (callableReferenceAccess.explicitReceiver !is FirResolvedQualifier) {
|
||||||
if (firReceiver != null && firReceiver !is FirResolvedQualifier) {
|
applyReceivers(callableReferenceAccess)
|
||||||
val irReceiver = visitor.convertToIrExpression(firReceiver)
|
|
||||||
if (symbol.owner.dispatchReceiverParameter != null) {
|
|
||||||
this.dispatchReceiver = irReceiver
|
|
||||||
} else if (symbol.owner.extensionReceiverParameter != null) {
|
|
||||||
this.extensionReceiver = irReceiver
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -354,12 +349,12 @@ internal class CallGenerator(
|
|||||||
|
|
||||||
private fun IrExpression.applyReceivers(qualifiedAccess: FirQualifiedAccess): IrExpression {
|
private fun IrExpression.applyReceivers(qualifiedAccess: FirQualifiedAccess): IrExpression {
|
||||||
return when (this) {
|
return when (this) {
|
||||||
is IrCallImpl -> {
|
is IrCallWithIndexedArgumentsBase -> {
|
||||||
val ownerFunction = symbol.owner
|
val ownerFunction = symbol.owner as? IrFunction
|
||||||
if (ownerFunction.dispatchReceiverParameter != null) {
|
if (ownerFunction?.dispatchReceiverParameter != null) {
|
||||||
dispatchReceiver = qualifiedAccess.findIrDispatchReceiver()
|
dispatchReceiver = qualifiedAccess.findIrDispatchReceiver()
|
||||||
}
|
}
|
||||||
if (ownerFunction.extensionReceiverParameter != null) {
|
if (ownerFunction?.extensionReceiverParameter != null) {
|
||||||
extensionReceiver = qualifiedAccess.findIrExtensionReceiver()
|
extensionReceiver = qualifiedAccess.findIrExtensionReceiver()
|
||||||
}
|
}
|
||||||
this
|
this
|
||||||
|
|||||||
Vendored
-1
@@ -1,4 +1,3 @@
|
|||||||
// IGNORE_BACKEND_FIR: JVM_IR
|
|
||||||
interface T {
|
interface T {
|
||||||
fun foo() = "OK"
|
fun foo() = "OK"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
// IGNORE_BACKEND_FIR: JVM_IR
|
|
||||||
open class Test {
|
open class Test {
|
||||||
companion object {
|
companion object {
|
||||||
fun testStatic(ic: InnerClass): NotInnerClass = NotInnerClass(ic.value)
|
fun testStatic(ic: InnerClass): NotInnerClass = NotInnerClass(ic.value)
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
// IGNORE_BACKEND_FIR: JVM_IR
|
|
||||||
class Outer(val value: String) {
|
class Outer(val value: String) {
|
||||||
|
|
||||||
inner class Inner {
|
inner class Inner {
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
// IGNORE_BACKEND_FIR: JVM_IR
|
|
||||||
|
|
||||||
open class A(val s: String) {
|
open class A(val s: String) {
|
||||||
open inner class B(val s: String) {
|
open inner class B(val s: String) {
|
||||||
fun testB() = s + this@A.s
|
fun testB() = s + this@A.s
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
// IGNORE_BACKEND_FIR: JVM_IR
|
|
||||||
|
|
||||||
open class A(val s: String) {
|
open class A(val s: String) {
|
||||||
|
|
||||||
val z = s
|
val z = s
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
// IGNORE_BACKEND_FIR: JVM_IR
|
|
||||||
class Outer() {
|
class Outer() {
|
||||||
inner class Inner() {
|
inner class Inner() {
|
||||||
val outer: Outer get() = this@Outer
|
val outer: Outer get() = this@Outer
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
// IGNORE_BACKEND_FIR: JVM_IR
|
|
||||||
public class Test {
|
public class Test {
|
||||||
val content = 1
|
val content = 1
|
||||||
inner class A {
|
inner class A {
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
// IGNORE_BACKEND_FIR: JVM_IR
|
|
||||||
open class Base {
|
open class Base {
|
||||||
fun doSomething() {
|
fun doSomething() {
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
// IGNORE_BACKEND_FIR: JVM_IR
|
|
||||||
class Foo(private val s: String) {
|
class Foo(private val s: String) {
|
||||||
inner class Inner {
|
inner class Inner {
|
||||||
private val x = {
|
private val x = {
|
||||||
|
|||||||
-1
@@ -1,5 +1,4 @@
|
|||||||
// !LANGUAGE: -NormalizeConstructorCalls
|
// !LANGUAGE: -NormalizeConstructorCalls
|
||||||
// IGNORE_BACKEND_FIR: JVM_IR
|
|
||||||
// TARGET_BACKEND: JVM
|
// TARGET_BACKEND: JVM
|
||||||
// WITH_RUNTIME
|
// WITH_RUNTIME
|
||||||
// FILE: test.kt
|
// FILE: test.kt
|
||||||
|
|||||||
-1
@@ -1,4 +1,3 @@
|
|||||||
// IGNORE_BACKEND_FIR: JVM_IR
|
|
||||||
class A {
|
class A {
|
||||||
inner class B(val a: String = "a", val b: Int = 55, val c: String = "c")
|
inner class B(val a: String = "a", val b: Int = 55, val c: String = "c")
|
||||||
}
|
}
|
||||||
|
|||||||
-1
@@ -1,4 +1,3 @@
|
|||||||
// IGNORE_BACKEND_FIR: JVM_IR
|
|
||||||
class A {
|
class A {
|
||||||
inner class B(val a: Double = 1.0, val b: Int = 55, val c: String = "c")
|
inner class B(val a: Double = 1.0, val b: Int = 55, val c: String = "c")
|
||||||
}
|
}
|
||||||
|
|||||||
-1
@@ -1,4 +1,3 @@
|
|||||||
// IGNORE_BACKEND_FIR: JVM_IR
|
|
||||||
class A {
|
class A {
|
||||||
inner class B(val a: Int = 1,
|
inner class B(val a: Int = 1,
|
||||||
val b: Int = 2,
|
val b: Int = 2,
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
// IGNORE_BACKEND_FIR: JVM_IR
|
|
||||||
class Outer {
|
class Outer {
|
||||||
class Nested
|
class Nested
|
||||||
inner class Inner
|
inner class Inner
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
// IGNORE_BACKEND_FIR: JVM_IR
|
|
||||||
class Outer {
|
class Outer {
|
||||||
inner class Inner<T>(val t: T) {
|
inner class Inner<T>(val t: T) {
|
||||||
fun box() = t
|
fun box() = t
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
// IGNORE_BACKEND_FIR: JVM_IR
|
|
||||||
class Outer {
|
class Outer {
|
||||||
inner class Inner {
|
inner class Inner {
|
||||||
fun O() = this@Outer.O
|
fun O() = this@Outer.O
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
// IGNORE_BACKEND_FIR: JVM_IR
|
|
||||||
class Outer {
|
class Outer {
|
||||||
inner class Inner {
|
inner class Inner {
|
||||||
fun box() = "OK"
|
fun box() = "OK"
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
// IGNORE_BACKEND_FIR: JVM_IR
|
|
||||||
class Test {
|
class Test {
|
||||||
interface Foo { }
|
interface Foo { }
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
// IGNORE_BACKEND_FIR: JVM_IR
|
|
||||||
//KT-3927 Inner class cannot be instantiated with child instance of outer class
|
//KT-3927 Inner class cannot be instantiated with child instance of outer class
|
||||||
|
|
||||||
abstract class Base {
|
abstract class Base {
|
||||||
|
|||||||
-2
@@ -1,5 +1,3 @@
|
|||||||
// IGNORE_BACKEND_FIR: JVM_IR
|
|
||||||
|
|
||||||
fun <T> tableView(init: Table<T>.() -> Unit) {
|
fun <T> tableView(init: Table<T>.() -> Unit) {
|
||||||
Table<T>().init()
|
Table<T>().init()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
// IGNORE_BACKEND_FIR: JVM_IR
|
|
||||||
// IGNORE_BACKEND: JS_IR
|
// IGNORE_BACKEND: JS_IR
|
||||||
// MODULE: lib
|
// MODULE: lib
|
||||||
// FILE: lib.kt
|
// FILE: lib.kt
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
// IGNORE_BACKEND_FIR: JVM_IR
|
|
||||||
// See also KT-6299
|
// See also KT-6299
|
||||||
public open class Outer private constructor(val s: String) {
|
public open class Outer private constructor(val s: String) {
|
||||||
inner class Inner: Outer("O") {
|
inner class Inner: Outer("O") {
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
// IGNORE_BACKEND_FIR: JVM_IR
|
|
||||||
class D {
|
class D {
|
||||||
companion object {
|
companion object {
|
||||||
protected val F: String = "OK"
|
protected val F: String = "OK"
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
// IGNORE_BACKEND_FIR: JVM_IR
|
|
||||||
open class SuperClass(val arg: () -> String)
|
open class SuperClass(val arg: () -> String)
|
||||||
|
|
||||||
object obj {
|
object obj {
|
||||||
|
|||||||
-1
@@ -1,4 +1,3 @@
|
|||||||
// IGNORE_BACKEND_FIR: JVM_IR
|
|
||||||
fun box(): String {
|
fun box(): String {
|
||||||
A.Nested().nestedA()
|
A.Nested().nestedA()
|
||||||
A.Nested().Inner().innerA()
|
A.Nested().Inner().innerA()
|
||||||
|
|||||||
+1
@@ -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]
|
FIELD PROPERTY_BACKING_FIELD name:test2 type:kotlin.reflect.KFunction0<kotlin.String> visibility:private [final,static]
|
||||||
EXPRESSION_BODY
|
EXPRESSION_BODY
|
||||||
FUNCTION_REFERENCE 'public final fun foo (): kotlin.String declared in test.Foo' type=kotlin.reflect.KFunction0<kotlin.String> origin=null reflectionTarget=<same>
|
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>
|
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]
|
correspondingProperty: PROPERTY name:test2 visibility:public modality:FINAL [val]
|
||||||
BLOCK_BODY
|
BLOCK_BODY
|
||||||
|
|||||||
+1
@@ -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]
|
FIELD PROPERTY_BACKING_FIELD name:test3 type:kotlin.Function1<kotlin.Int, kotlin.Unit> visibility:private [final,static]
|
||||||
EXPRESSION_BODY
|
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>
|
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>
|
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]
|
correspondingProperty: PROPERTY name:test3 visibility:public modality:FINAL [val]
|
||||||
BLOCK_BODY
|
BLOCK_BODY
|
||||||
|
|||||||
+1
@@ -67,3 +67,4 @@ FILE fqName:<root> fileName:/withAdaptedArguments.kt
|
|||||||
RETURN type=kotlin.Nothing from='public final fun testImportedObjectMember (): IrErrorType declared in <root>'
|
RETURN type=kotlin.Nothing from='public final fun testImportedObjectMember (): IrErrorType declared in <root>'
|
||||||
ERROR_CALL 'Unresolved reference: <Inapplicable(INAPPLICABLE): [/use]>#' type=IrErrorType
|
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>
|
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
|
||||||
|
|||||||
+2
@@ -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>'
|
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
|
CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in <root>.K1.K2' type=<root>.K1.K2<kotlin.String> origin=null
|
||||||
<class: T2>: kotlin.String
|
<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?>
|
FUN name:testJava visibility:public modality:FINAL <> () returnType:<root>.J1.J2<kotlin.Double?>
|
||||||
BLOCK_BODY
|
BLOCK_BODY
|
||||||
RETURN type=kotlin.Nothing from='public final fun testJava (): <root>.J1.J2<kotlin.Double?> declared in <root>'
|
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>'
|
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
|
CONSTRUCTOR_CALL 'public constructor <init> () declared in <root>.J1.J2' type=<root>.J1.J2<kotlin.Int?> origin=null
|
||||||
<class: T2>: kotlin.Int?
|
<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?>
|
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>
|
VALUE_PARAMETER name:j1 index:0 type:<root>.J1<kotlin.Any>
|
||||||
BLOCK_BODY
|
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]
|
FIELD PROPERTY_BACKING_FIELD name:test type:<root>.J.JInner visibility:private [final]
|
||||||
EXPRESSION_BODY
|
EXPRESSION_BODY
|
||||||
CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in <root>.J.JInner' type=<root>.J.JInner origin=null
|
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
|
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]
|
correspondingProperty: PROPERTY name:test visibility:public modality:FINAL [val]
|
||||||
$this: VALUE_PARAMETER name:<this> type:<root>.Test1
|
$this: VALUE_PARAMETER name:<this> type:<root>.Test1
|
||||||
|
|||||||
Reference in New Issue
Block a user