FIR2IR: introduce implicit casts for extension receivers
This commit is contained in:
committed by
TeamCityServer
parent
6e9ac6b333
commit
f7ade2b0b8
+12
-2
@@ -5,7 +5,6 @@
|
||||
|
||||
package org.jetbrains.kotlin.fir.backend.generators
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.Visibilities
|
||||
import org.jetbrains.kotlin.fir.FirFakeSourceElementKind
|
||||
import org.jetbrains.kotlin.fir.backend.*
|
||||
import org.jetbrains.kotlin.fir.declarations.*
|
||||
@@ -720,7 +719,18 @@ class CallAndReferenceGenerator(
|
||||
dispatchReceiver = qualifiedAccess.findIrDispatchReceiver(explicitReceiverExpression)
|
||||
}
|
||||
if (ownerFunction?.extensionReceiverParameter != null) {
|
||||
extensionReceiver = qualifiedAccess.findIrExtensionReceiver(explicitReceiverExpression)
|
||||
extensionReceiver = qualifiedAccess.findIrExtensionReceiver(explicitReceiverExpression)?.let {
|
||||
((qualifiedAccess.calleeReference as FirResolvedNamedReference)
|
||||
.resolvedSymbol.fir as? FirCallableMemberDeclaration)?.receiverTypeRef?.let { receiverType ->
|
||||
with(visitor.implicitCastInserter) {
|
||||
it.cast(
|
||||
qualifiedAccess.extensionReceiver,
|
||||
qualifiedAccess.extensionReceiver.typeRef,
|
||||
receiverType
|
||||
)
|
||||
}
|
||||
} ?: it
|
||||
}
|
||||
}
|
||||
this
|
||||
}
|
||||
|
||||
-1
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
// TARGET_BACKEND: JVM
|
||||
// WITH_RUNTIME
|
||||
// FILE: test.kt
|
||||
|
||||
-1
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
// TARGET_BACKEND: JVM
|
||||
// WITH_RUNTIME
|
||||
// FILE: test.kt
|
||||
|
||||
Vendored
+1
-1
@@ -9,5 +9,5 @@ private operator fun J.component2(): Int {
|
||||
fun test() {
|
||||
val <destruct>: J? = j()
|
||||
val a: Int = <destruct>.component1()
|
||||
val b: Int = <destruct>.component2()
|
||||
val b: Int = <destruct> /*!! J */.component2()
|
||||
}
|
||||
|
||||
+2
-1
@@ -18,4 +18,5 @@ FILE fqName:<root> fileName:/implicitNotNullInDestructuringAssignment.kt
|
||||
$receiver: GET_VAR 'val tmp_0: <root>.J? [val] declared in <root>.test' type=<root>.J? origin=null
|
||||
VAR name:b type:kotlin.Int [val]
|
||||
CALL 'private final fun component2 (): kotlin.Int [operator] declared in <root>' type=kotlin.Int origin=null
|
||||
$receiver: GET_VAR 'val tmp_0: <root>.J? [val] declared in <root>.test' type=<root>.J? origin=null
|
||||
$receiver: TYPE_OP type=<root>.J origin=IMPLICIT_NOTNULL typeOperand=<root>.J
|
||||
GET_VAR 'val tmp_0: <root>.J? [val] declared in <root>.test' type=<root>.J? origin=null
|
||||
|
||||
compiler/testData/ir/irText/types/nullChecks/enhancedNullabilityInDestructuringAssignment.fir.kt.txt
Vendored
+1
-1
@@ -80,7 +80,7 @@ fun test3() {
|
||||
}
|
||||
|
||||
fun test4() {
|
||||
val <destruct>: IndexedValue<P?> = listOfNotNull().withIndex<P?>().first<IndexedValue<P?>>()
|
||||
val <destruct>: IndexedValue<P?> = listOfNotNull() /*!! List<P?> */.withIndex<P?>().first<IndexedValue<P?>>()
|
||||
val x: Int = <destruct>.component1()
|
||||
val y: P? = <destruct>.component2()
|
||||
use(x = x, y = y /*!! P */)
|
||||
|
||||
Vendored
+2
-1
@@ -179,7 +179,8 @@ FILE fqName:<root> fileName:/enhancedNullabilityInDestructuringAssignment.kt
|
||||
<T>: kotlin.collections.IndexedValue<<root>.P?>
|
||||
$receiver: CALL 'public final fun withIndex <T> (): kotlin.collections.Iterable<kotlin.collections.IndexedValue<T of kotlin.collections.withIndex>> declared in kotlin.collections' type=kotlin.collections.Iterable<kotlin.collections.IndexedValue<<root>.P?>> origin=null
|
||||
<T>: <root>.P?
|
||||
$receiver: CALL 'public open fun listOfNotNull (): kotlin.collections.List<<root>.P?>? declared in <root>.J' type=kotlin.collections.List<<root>.P?>? origin=null
|
||||
$receiver: TYPE_OP type=kotlin.collections.List<<root>.P?> origin=IMPLICIT_NOTNULL typeOperand=kotlin.collections.List<<root>.P?>
|
||||
CALL 'public open fun listOfNotNull (): kotlin.collections.List<<root>.P?>? declared in <root>.J' type=kotlin.collections.List<<root>.P?>? origin=null
|
||||
VAR name:x type:kotlin.Int [val]
|
||||
CALL 'public final fun component1 (): kotlin.Int [operator] declared in kotlin.collections.IndexedValue' type=kotlin.Int origin=null
|
||||
$this: GET_VAR 'val tmp_3: kotlin.collections.IndexedValue<<root>.P?> [val] declared in <root>.test4' type=kotlin.collections.IndexedValue<<root>.P?> origin=null
|
||||
|
||||
Vendored
+2
-2
@@ -14,9 +14,9 @@ class C {
|
||||
}
|
||||
|
||||
fun testExt() {
|
||||
s().extension()
|
||||
s() /*!! String */.extension()
|
||||
}
|
||||
|
||||
fun C.testMemberExt() {
|
||||
(<this>, s()).memberExtension()
|
||||
(<this>, s() /*!! String */).memberExtension()
|
||||
}
|
||||
|
||||
Vendored
+4
-2
@@ -28,10 +28,12 @@ FILE fqName:<root> fileName:/nullabilityAssertionOnExtensionReceiver.kt
|
||||
FUN name:testExt visibility:public modality:FINAL <> () returnType:kotlin.Unit
|
||||
BLOCK_BODY
|
||||
CALL 'public final fun extension (): kotlin.Unit declared in <root>' type=kotlin.Unit origin=null
|
||||
$receiver: CALL 'public open fun s (): kotlin.String? declared in <root>.J' type=kotlin.String? origin=null
|
||||
$receiver: TYPE_OP type=kotlin.String origin=IMPLICIT_NOTNULL typeOperand=kotlin.String
|
||||
CALL 'public open fun s (): kotlin.String? declared in <root>.J' type=kotlin.String? origin=null
|
||||
FUN name:testMemberExt visibility:public modality:FINAL <> ($receiver:<root>.C) returnType:kotlin.Unit
|
||||
$receiver: VALUE_PARAMETER name:<this> type:<root>.C
|
||||
BLOCK_BODY
|
||||
CALL 'public final fun memberExtension (): kotlin.Unit declared in <root>.C' type=kotlin.Unit origin=null
|
||||
$this: GET_VAR '<this>: <root>.C declared in <root>.testMemberExt' type=<root>.C origin=null
|
||||
$receiver: CALL 'public open fun s (): kotlin.String? declared in <root>.J' type=kotlin.String? origin=null
|
||||
$receiver: TYPE_OP type=kotlin.String origin=IMPLICIT_NOTNULL typeOperand=kotlin.String
|
||||
CALL 'public open fun s (): kotlin.String? declared in <root>.J' type=kotlin.String? origin=null
|
||||
|
||||
Reference in New Issue
Block a user