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 bbab2061bc0..2b8acda8dbe 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,6 +5,7 @@ package org.jetbrains.kotlin.fir.backend.generators +import org.jetbrains.kotlin.descriptors.Visibilities import org.jetbrains.kotlin.fir.backend.* import org.jetbrains.kotlin.fir.declarations.* import org.jetbrains.kotlin.fir.expressions.* @@ -20,6 +21,7 @@ import org.jetbrains.kotlin.fir.resolve.inference.isBuiltinFunctionalType import org.jetbrains.kotlin.fir.resolve.toSymbol import org.jetbrains.kotlin.fir.scopes.unsubstitutedScope import org.jetbrains.kotlin.fir.symbols.impl.* +import org.jetbrains.kotlin.fir.typeContext import org.jetbrains.kotlin.fir.types.* import org.jetbrains.kotlin.ir.declarations.* import org.jetbrains.kotlin.ir.expressions.* @@ -29,6 +31,7 @@ import org.jetbrains.kotlin.ir.types.* import org.jetbrains.kotlin.ir.util.* import org.jetbrains.kotlin.psi.KtPropertyDelegate import org.jetbrains.kotlin.psi2ir.generators.hasNoSideEffects +import org.jetbrains.kotlin.types.AbstractTypeApproximator class CallAndReferenceGenerator( private val components: Fir2IrComponents, @@ -36,6 +39,7 @@ class CallAndReferenceGenerator( private val conversionScope: Fir2IrConversionScope ) : Fir2IrComponents by components { + private val approximator = object : AbstractTypeApproximator(session.typeContext) {} private val adapterGenerator = AdapterGenerator(components, conversionScope) private fun FirTypeRef.toIrType(): IrType = with(typeConverter) { toIrType() } @@ -563,7 +567,13 @@ class CallAndReferenceGenerator( if (argumentsCount <= typeArgumentsCount) { apply { for ((index, argument) in access.typeArguments.withIndex()) { - val argumentIrType = (argument as FirTypeProjectionWithVariance).typeRef.toIrType() + val typeParameter = access.findTypeParameter(index) + val argumentFirType = (argument as FirTypeProjectionWithVariance).typeRef + val argumentIrType = if (typeParameter?.isReified == true) { + argumentFirType.approximatedIfNeededOrSelf(approximator, Visibilities.Public).toIrType() + } else { + argumentFirType.toIrType() + } putTypeArgument(index, argumentIrType) } } @@ -587,6 +597,9 @@ class CallAndReferenceGenerator( } } + private fun FirQualifiedAccess.findTypeParameter(index: Int): FirTypeParameter? = + ((calleeReference as? FirResolvedNamedReference)?.resolvedSymbol?.fir as? FirTypeParametersOwner)?.typeParameters?.get(index) + private fun FirQualifiedAccess.findIrDispatchReceiver(explicitReceiverExpression: IrExpression?): IrExpression? = findIrReceiver(explicitReceiverExpression, isDispatch = true) diff --git a/compiler/testData/codegen/box/callableReference/function/genericCallableReferenceArguments.kt b/compiler/testData/codegen/box/callableReference/function/genericCallableReferenceArguments.kt index 27c479cf34c..15d54d48337 100644 --- a/compiler/testData/codegen/box/callableReference/function/genericCallableReferenceArguments.kt +++ b/compiler/testData/codegen/box/callableReference/function/genericCallableReferenceArguments.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR // IGNORE_BACKEND: JS_IR // IGNORE_BACKEND: JS_IR_ES6 // IGNORE_BACKEND: JS, NATIVE diff --git a/compiler/testData/codegen/box/coroutines/featureIntersection/callableReference/function/genericCallableReferenceArguments.kt b/compiler/testData/codegen/box/coroutines/featureIntersection/callableReference/function/genericCallableReferenceArguments.kt index eece96e83df..47da5c4709c 100644 --- a/compiler/testData/codegen/box/coroutines/featureIntersection/callableReference/function/genericCallableReferenceArguments.kt +++ b/compiler/testData/codegen/box/coroutines/featureIntersection/callableReference/function/genericCallableReferenceArguments.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR // TARGET_BACKEND: JVM // WITH_REFLECT // WITH_COROUTINES diff --git a/compiler/testData/ir/irText/types/intersectionType1_NI.fir.txt b/compiler/testData/ir/irText/types/intersectionType1_NI.fir.txt index fe74267ab44..2c8bcfef583 100644 --- a/compiler/testData/ir/irText/types/intersectionType1_NI.fir.txt +++ b/compiler/testData/ir/irText/types/intersectionType1_NI.fir.txt @@ -33,7 +33,7 @@ FILE fqName: fileName:/intersectionType1_NI.kt BLOCK_BODY RETURN type=kotlin.Nothing from='public final fun foo (a: kotlin.Array<.In.foo>>, b: kotlin.Array<.In>): kotlin.Boolean declared in ' CALL 'public final fun ofType (y: kotlin.Any?): kotlin.Boolean [inline] declared in ' type=kotlin.Boolean origin=null - : T of .foo + : kotlin.Any? $receiver: CALL 'public final fun get (index: kotlin.Int): T of kotlin.Array [operator] declared in kotlin.Array' type=.In.foo> origin=null $this: CALL 'public final fun select (x: S of .select, y: S of .select): S of .select declared in ' type=kotlin.Array.In.foo>> origin=null : kotlin.Array.In.foo>> diff --git a/compiler/testData/ir/irText/types/intersectionType1_OI.fir.txt b/compiler/testData/ir/irText/types/intersectionType1_OI.fir.txt index 0c9ecd4f751..1f02f6c692b 100644 --- a/compiler/testData/ir/irText/types/intersectionType1_OI.fir.txt +++ b/compiler/testData/ir/irText/types/intersectionType1_OI.fir.txt @@ -33,7 +33,7 @@ FILE fqName: fileName:/intersectionType1_OI.kt BLOCK_BODY RETURN type=kotlin.Nothing from='public final fun foo (a: kotlin.Array<.In.foo>>, b: kotlin.Array<.In>): kotlin.Boolean declared in ' CALL 'public final fun ofType (y: kotlin.Any?): kotlin.Boolean [inline] declared in ' type=kotlin.Boolean origin=null - : T of .foo + : kotlin.Any? $receiver: CALL 'public final fun get (index: kotlin.Int): T of kotlin.Array [operator] declared in kotlin.Array' type=.In.foo> origin=null $this: CALL 'public final fun select (x: S of .select, y: S of .select): S of .select declared in ' type=kotlin.Array.In.foo>> origin=null : kotlin.Array.In.foo>> diff --git a/compiler/testData/ir/irText/types/intersectionType3_NI.fir.txt b/compiler/testData/ir/irText/types/intersectionType3_NI.fir.txt index 8b71ba0b682..31eb32b5228 100644 --- a/compiler/testData/ir/irText/types/intersectionType3_NI.fir.txt +++ b/compiler/testData/ir/irText/types/intersectionType3_NI.fir.txt @@ -132,7 +132,7 @@ FILE fqName: fileName:/intersectionType3_NI.kt BLOCK_BODY RETURN type=kotlin.Nothing from='public final fun testInIs1 (x: .In<.A>, y: .In<.B>): kotlin.Boolean declared in ' CALL 'public final fun isT (): kotlin.Boolean [inline] declared in ' type=kotlin.Boolean origin=null - : .A + : kotlin.Any $receiver: CALL 'public final fun sel (x: S of .sel, y: S of .sel): S of .sel declared in ' type=.In<.A> origin=null : .In<.A> x: GET_VAR 'x: .In<.A> declared in .testInIs1' type=.In<.A> origin=null @@ -143,7 +143,7 @@ FILE fqName: fileName:/intersectionType3_NI.kt BLOCK_BODY RETURN type=kotlin.Nothing from='public final fun testInIs2 (x: .In<.Z1>, y: .In<.Z2>): kotlin.Boolean declared in ' CALL 'public final fun isT (): kotlin.Boolean [inline] declared in ' type=kotlin.Boolean origin=null - : .Z1 + : kotlin.Any $receiver: CALL 'public final fun sel (x: S of .sel, y: S of .sel): S of .sel declared in ' type=.In<.Z1> origin=null : .In<.Z1> x: GET_VAR 'x: .In<.Z1> declared in .testInIs2' type=.In<.Z1> origin=null @@ -154,7 +154,7 @@ FILE fqName: fileName:/intersectionType3_NI.kt BLOCK_BODY RETURN type=kotlin.Nothing from='public final fun testInIs3 (x: .In<.A1>, y: .In<.A2>): kotlin.Boolean declared in ' CALL 'public final fun isT (): kotlin.Boolean [inline] declared in ' type=kotlin.Boolean origin=null - : .A1 + : .A $receiver: CALL 'public final fun sel (x: S of .sel, y: S of .sel): S of .sel declared in ' type=.In<.A1> origin=null : .In<.A1> x: GET_VAR 'x: .In<.A1> declared in .testInIs3' type=.In<.A1> origin=null @@ -165,7 +165,7 @@ FILE fqName: fileName:/intersectionType3_NI.kt BLOCK_BODY RETURN type=kotlin.Nothing from='public final fun testInAs1 (x: .In<.A>, y: .In<.B>): kotlin.Unit declared in ' CALL 'public final fun asT (): kotlin.Unit [inline] declared in ' type=kotlin.Unit origin=null - : .A + : kotlin.Any $receiver: CALL 'public final fun sel (x: S of .sel, y: S of .sel): S of .sel declared in ' type=.In<.A> origin=null : .In<.A> x: GET_VAR 'x: .In<.A> declared in .testInAs1' type=.In<.A> origin=null @@ -176,7 +176,7 @@ FILE fqName: fileName:/intersectionType3_NI.kt BLOCK_BODY RETURN type=kotlin.Nothing from='public final fun testInAs2 (x: .In<.Z1>, y: .In<.Z2>): kotlin.Unit declared in ' CALL 'public final fun asT (): kotlin.Unit [inline] declared in ' type=kotlin.Unit origin=null - : .Z1 + : kotlin.Any $receiver: CALL 'public final fun sel (x: S of .sel, y: S of .sel): S of .sel declared in ' type=.In<.Z1> origin=null : .In<.Z1> x: GET_VAR 'x: .In<.Z1> declared in .testInAs2' type=.In<.Z1> origin=null @@ -187,7 +187,7 @@ FILE fqName: fileName:/intersectionType3_NI.kt BLOCK_BODY RETURN type=kotlin.Nothing from='public final fun testInAs3 (x: .In<.A1>, y: .In<.A2>): kotlin.Unit declared in ' CALL 'public final fun asT (): kotlin.Unit [inline] declared in ' type=kotlin.Unit origin=null - : .A1 + : .A $receiver: CALL 'public final fun sel (x: S of .sel, y: S of .sel): S of .sel declared in ' type=.In<.A1> origin=null : .In<.A1> x: GET_VAR 'x: .In<.A1> declared in .testInAs3' type=.In<.A1> origin=null diff --git a/compiler/testData/ir/irText/types/intersectionType3_OI.fir.txt b/compiler/testData/ir/irText/types/intersectionType3_OI.fir.txt index 99a49a39bf9..594186b643b 100644 --- a/compiler/testData/ir/irText/types/intersectionType3_OI.fir.txt +++ b/compiler/testData/ir/irText/types/intersectionType3_OI.fir.txt @@ -132,7 +132,7 @@ FILE fqName: fileName:/intersectionType3_OI.kt BLOCK_BODY RETURN type=kotlin.Nothing from='public final fun testInIs1 (x: .In<.A>, y: .In<.B>): kotlin.Boolean declared in ' CALL 'public final fun isT (): kotlin.Boolean [inline] declared in ' type=kotlin.Boolean origin=null - : .A + : kotlin.Any $receiver: CALL 'public final fun sel (x: S of .sel, y: S of .sel): S of .sel declared in ' type=.In<.A> origin=null : .In<.A> x: GET_VAR 'x: .In<.A> declared in .testInIs1' type=.In<.A> origin=null @@ -143,7 +143,7 @@ FILE fqName: fileName:/intersectionType3_OI.kt BLOCK_BODY RETURN type=kotlin.Nothing from='public final fun testInIs2 (x: .In<.Z1>, y: .In<.Z2>): kotlin.Boolean declared in ' CALL 'public final fun isT (): kotlin.Boolean [inline] declared in ' type=kotlin.Boolean origin=null - : .Z1 + : kotlin.Any $receiver: CALL 'public final fun sel (x: S of .sel, y: S of .sel): S of .sel declared in ' type=.In<.Z1> origin=null : .In<.Z1> x: GET_VAR 'x: .In<.Z1> declared in .testInIs2' type=.In<.Z1> origin=null @@ -154,7 +154,7 @@ FILE fqName: fileName:/intersectionType3_OI.kt BLOCK_BODY RETURN type=kotlin.Nothing from='public final fun testInIs3 (x: .In<.A1>, y: .In<.A2>): kotlin.Boolean declared in ' CALL 'public final fun isT (): kotlin.Boolean [inline] declared in ' type=kotlin.Boolean origin=null - : .A1 + : .A $receiver: CALL 'public final fun sel (x: S of .sel, y: S of .sel): S of .sel declared in ' type=.In<.A1> origin=null : .In<.A1> x: GET_VAR 'x: .In<.A1> declared in .testInIs3' type=.In<.A1> origin=null @@ -165,7 +165,7 @@ FILE fqName: fileName:/intersectionType3_OI.kt BLOCK_BODY RETURN type=kotlin.Nothing from='public final fun testInAs1 (x: .In<.A>, y: .In<.B>): kotlin.Unit declared in ' CALL 'public final fun asT (): kotlin.Unit [inline] declared in ' type=kotlin.Unit origin=null - : .A + : kotlin.Any $receiver: CALL 'public final fun sel (x: S of .sel, y: S of .sel): S of .sel declared in ' type=.In<.A> origin=null : .In<.A> x: GET_VAR 'x: .In<.A> declared in .testInAs1' type=.In<.A> origin=null @@ -176,7 +176,7 @@ FILE fqName: fileName:/intersectionType3_OI.kt BLOCK_BODY RETURN type=kotlin.Nothing from='public final fun testInAs2 (x: .In<.Z1>, y: .In<.Z2>): kotlin.Unit declared in ' CALL 'public final fun asT (): kotlin.Unit [inline] declared in ' type=kotlin.Unit origin=null - : .Z1 + : kotlin.Any $receiver: CALL 'public final fun sel (x: S of .sel, y: S of .sel): S of .sel declared in ' type=.In<.Z1> origin=null : .In<.Z1> x: GET_VAR 'x: .In<.Z1> declared in .testInAs2' type=.In<.Z1> origin=null @@ -187,7 +187,7 @@ FILE fqName: fileName:/intersectionType3_OI.kt BLOCK_BODY RETURN type=kotlin.Nothing from='public final fun testInAs3 (x: .In<.A1>, y: .In<.A2>): kotlin.Unit declared in ' CALL 'public final fun asT (): kotlin.Unit [inline] declared in ' type=kotlin.Unit origin=null - : .A1 + : .A $receiver: CALL 'public final fun sel (x: S of .sel, y: S of .sel): S of .sel declared in ' type=.In<.A1> origin=null : .In<.A1> x: GET_VAR 'x: .In<.A1> declared in .testInAs3' type=.In<.A1> origin=null