diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/CallAndReferenceGenerator.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/CallAndReferenceGenerator.kt index 671e8c62eda..35353eda734 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/CallAndReferenceGenerator.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/CallAndReferenceGenerator.kt @@ -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 } diff --git a/compiler/testData/codegen/box/javaInterop/notNullAssertions/nullabilityAssertionOnInlineFunExtensionReceiver.kt b/compiler/testData/codegen/box/javaInterop/notNullAssertions/nullabilityAssertionOnInlineFunExtensionReceiver.kt index dcdeeb29810..61e9b7eb70c 100644 --- a/compiler/testData/codegen/box/javaInterop/notNullAssertions/nullabilityAssertionOnInlineFunExtensionReceiver.kt +++ b/compiler/testData/codegen/box/javaInterop/notNullAssertions/nullabilityAssertionOnInlineFunExtensionReceiver.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR // TARGET_BACKEND: JVM // WITH_RUNTIME // FILE: test.kt diff --git a/compiler/testData/codegen/box/javaInterop/notNullAssertions/nullabilityAssertionOnPrivateMemberExtensionReceiver.kt b/compiler/testData/codegen/box/javaInterop/notNullAssertions/nullabilityAssertionOnPrivateMemberExtensionReceiver.kt index 194a9c5b8c6..5b1bb29e249 100644 --- a/compiler/testData/codegen/box/javaInterop/notNullAssertions/nullabilityAssertionOnPrivateMemberExtensionReceiver.kt +++ b/compiler/testData/codegen/box/javaInterop/notNullAssertions/nullabilityAssertionOnPrivateMemberExtensionReceiver.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR // TARGET_BACKEND: JVM // WITH_RUNTIME // FILE: test.kt diff --git a/compiler/testData/ir/irText/expressions/implicitNotNullInDestructuringAssignment.fir.kt.txt b/compiler/testData/ir/irText/expressions/implicitNotNullInDestructuringAssignment.fir.kt.txt index e4947d8c8b7..677ce14ca8c 100644 --- a/compiler/testData/ir/irText/expressions/implicitNotNullInDestructuringAssignment.fir.kt.txt +++ b/compiler/testData/ir/irText/expressions/implicitNotNullInDestructuringAssignment.fir.kt.txt @@ -9,5 +9,5 @@ private operator fun J.component2(): Int { fun test() { val : J? = j() val a: Int = .component1() - val b: Int = .component2() + val b: Int = /*!! J */.component2() } diff --git a/compiler/testData/ir/irText/expressions/implicitNotNullInDestructuringAssignment.fir.txt b/compiler/testData/ir/irText/expressions/implicitNotNullInDestructuringAssignment.fir.txt index 2d59e98bfae..69675bd72a9 100644 --- a/compiler/testData/ir/irText/expressions/implicitNotNullInDestructuringAssignment.fir.txt +++ b/compiler/testData/ir/irText/expressions/implicitNotNullInDestructuringAssignment.fir.txt @@ -18,4 +18,5 @@ FILE fqName: fileName:/implicitNotNullInDestructuringAssignment.kt $receiver: GET_VAR 'val tmp_0: .J? [val] declared in .test' type=.J? origin=null VAR name:b type:kotlin.Int [val] CALL 'private final fun component2 (): kotlin.Int [operator] declared in ' type=kotlin.Int origin=null - $receiver: GET_VAR 'val tmp_0: .J? [val] declared in .test' type=.J? origin=null + $receiver: TYPE_OP type=.J origin=IMPLICIT_NOTNULL typeOperand=.J + GET_VAR 'val tmp_0: .J? [val] declared in .test' type=.J? origin=null diff --git a/compiler/testData/ir/irText/types/nullChecks/enhancedNullabilityInDestructuringAssignment.fir.kt.txt b/compiler/testData/ir/irText/types/nullChecks/enhancedNullabilityInDestructuringAssignment.fir.kt.txt index e9c15dc1d1e..6434991f23f 100644 --- a/compiler/testData/ir/irText/types/nullChecks/enhancedNullabilityInDestructuringAssignment.fir.kt.txt +++ b/compiler/testData/ir/irText/types/nullChecks/enhancedNullabilityInDestructuringAssignment.fir.kt.txt @@ -80,7 +80,7 @@ fun test3() { } fun test4() { - val : IndexedValue = listOfNotNull().withIndex().first>() + val : IndexedValue = listOfNotNull() /*!! List */.withIndex().first>() val x: Int = .component1() val y: P? = .component2() use(x = x, y = y /*!! P */) diff --git a/compiler/testData/ir/irText/types/nullChecks/enhancedNullabilityInDestructuringAssignment.fir.txt b/compiler/testData/ir/irText/types/nullChecks/enhancedNullabilityInDestructuringAssignment.fir.txt index 2fb5458168d..71b5565933a 100644 --- a/compiler/testData/ir/irText/types/nullChecks/enhancedNullabilityInDestructuringAssignment.fir.txt +++ b/compiler/testData/ir/irText/types/nullChecks/enhancedNullabilityInDestructuringAssignment.fir.txt @@ -179,7 +179,8 @@ FILE fqName: fileName:/enhancedNullabilityInDestructuringAssignment.kt : kotlin.collections.IndexedValue<.P?> $receiver: CALL 'public final fun withIndex (): kotlin.collections.Iterable> declared in kotlin.collections' type=kotlin.collections.Iterable.P?>> origin=null : .P? - $receiver: CALL 'public open fun listOfNotNull (): kotlin.collections.List<.P?>? declared in .J' type=kotlin.collections.List<.P?>? origin=null + $receiver: TYPE_OP type=kotlin.collections.List<.P?> origin=IMPLICIT_NOTNULL typeOperand=kotlin.collections.List<.P?> + CALL 'public open fun listOfNotNull (): kotlin.collections.List<.P?>? declared in .J' type=kotlin.collections.List<.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<.P?> [val] declared in .test4' type=kotlin.collections.IndexedValue<.P?> origin=null diff --git a/compiler/testData/ir/irText/types/nullChecks/nullabilityAssertionOnExtensionReceiver.fir.kt.txt b/compiler/testData/ir/irText/types/nullChecks/nullabilityAssertionOnExtensionReceiver.fir.kt.txt index df7c948dfc6..13b5113cbc9 100644 --- a/compiler/testData/ir/irText/types/nullChecks/nullabilityAssertionOnExtensionReceiver.fir.kt.txt +++ b/compiler/testData/ir/irText/types/nullChecks/nullabilityAssertionOnExtensionReceiver.fir.kt.txt @@ -14,9 +14,9 @@ class C { } fun testExt() { - s().extension() + s() /*!! String */.extension() } fun C.testMemberExt() { - (, s()).memberExtension() + (, s() /*!! String */).memberExtension() } diff --git a/compiler/testData/ir/irText/types/nullChecks/nullabilityAssertionOnExtensionReceiver.fir.txt b/compiler/testData/ir/irText/types/nullChecks/nullabilityAssertionOnExtensionReceiver.fir.txt index 5606e1b25d3..e9ca8d32ba0 100644 --- a/compiler/testData/ir/irText/types/nullChecks/nullabilityAssertionOnExtensionReceiver.fir.txt +++ b/compiler/testData/ir/irText/types/nullChecks/nullabilityAssertionOnExtensionReceiver.fir.txt @@ -28,10 +28,12 @@ FILE fqName: fileName:/nullabilityAssertionOnExtensionReceiver.kt FUN name:testExt visibility:public modality:FINAL <> () returnType:kotlin.Unit BLOCK_BODY CALL 'public final fun extension (): kotlin.Unit declared in ' type=kotlin.Unit origin=null - $receiver: CALL 'public open fun s (): kotlin.String? declared in .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 .J' type=kotlin.String? origin=null FUN name:testMemberExt visibility:public modality:FINAL <> ($receiver:.C) returnType:kotlin.Unit $receiver: VALUE_PARAMETER name: type:.C BLOCK_BODY CALL 'public final fun memberExtension (): kotlin.Unit declared in .C' type=kotlin.Unit origin=null $this: GET_VAR ': .C declared in .testMemberExt' type=.C origin=null - $receiver: CALL 'public open fun s (): kotlin.String? declared in .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 .J' type=kotlin.String? origin=null