diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrTypeConverter.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrTypeConverter.kt index 272b346a8cd..1830877d9dc 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrTypeConverter.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrTypeConverter.kt @@ -120,7 +120,11 @@ class Fir2IrTypeConverter( if (cached == null) { val irType = lowerType?.toIrType(typeContext) ?: run { capturedTypeCache[this] = errorTypeForCapturedTypeStub - constructor.supertypes!!.first().toIrType(typeContext) + val supertypes = constructor.supertypes!! + val approximation = supertypes.find { + it == (constructor.projection as? ConeKotlinTypeProjection)?.type + } ?: supertypes.first() + approximation.toIrType(typeContext) } capturedTypeCache[this] = irType irType diff --git a/compiler/testData/ir/irText/expressions/sam/genericSamProjectedOut.fir.kt.txt b/compiler/testData/ir/irText/expressions/sam/genericSamProjectedOut.fir.kt.txt index dbc03ed47f0..1fc96f0fbe5 100644 --- a/compiler/testData/ir/irText/expressions/sam/genericSamProjectedOut.fir.kt.txt +++ b/compiler/testData/ir/irText/expressions/sam/genericSamProjectedOut.fir.kt.txt @@ -2,13 +2,13 @@ fun test(a: SomeJavaClass) { a.someFunction(hello = local fun (it: String?) { return Unit } - /*-> Hello? */) + /*-> Hello? */) a.plus(hello = local fun (it: String?) { return Unit } - /*-> Hello? */) + /*-> Hello? */) a.get(hello = local fun (it: String?) { return Unit } - /*-> Hello? */) + /*-> Hello? */) } diff --git a/compiler/testData/ir/irText/expressions/sam/genericSamProjectedOut.fir.txt b/compiler/testData/ir/irText/expressions/sam/genericSamProjectedOut.fir.txt index b5176c83c8f..9f430d1e493 100644 --- a/compiler/testData/ir/irText/expressions/sam/genericSamProjectedOut.fir.txt +++ b/compiler/testData/ir/irText/expressions/sam/genericSamProjectedOut.fir.txt @@ -4,7 +4,7 @@ FILE fqName: fileName:/genericSamProjectedOut.kt BLOCK_BODY CALL 'public open fun someFunction (hello: example.Hello?): kotlin.Unit declared in example.SomeJavaClass' type=kotlin.Unit origin=null $this: GET_VAR 'a: example.SomeJavaClass declared in .test' type=example.SomeJavaClass origin=null - hello: TYPE_OP type=example.Hello? origin=SAM_CONVERSION typeOperand=example.Hello? + hello: TYPE_OP type=example.Hello? origin=SAM_CONVERSION typeOperand=example.Hello? FUN_EXPR type=kotlin.Function1 origin=LAMBDA FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> (it:kotlin.String?) returnType:kotlin.Unit VALUE_PARAMETER name:it index:0 type:kotlin.String? @@ -13,7 +13,7 @@ FILE fqName: fileName:/genericSamProjectedOut.kt GET_OBJECT 'CLASS IR_EXTERNAL_DECLARATION_STUB OBJECT name:Unit modality:FINAL visibility:public superTypes:[kotlin.Any]' type=kotlin.Unit CALL 'public open fun plus (hello: example.Hello?): kotlin.Unit [operator] declared in example.SomeJavaClass' type=kotlin.Unit origin=PLUS $this: GET_VAR 'a: example.SomeJavaClass declared in .test' type=example.SomeJavaClass origin=null - hello: TYPE_OP type=example.Hello? origin=SAM_CONVERSION typeOperand=example.Hello? + hello: TYPE_OP type=example.Hello? origin=SAM_CONVERSION typeOperand=example.Hello? FUN_EXPR type=kotlin.Function1 origin=LAMBDA FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> (it:kotlin.String?) returnType:kotlin.Unit VALUE_PARAMETER name:it index:0 type:kotlin.String? @@ -22,7 +22,7 @@ FILE fqName: fileName:/genericSamProjectedOut.kt GET_OBJECT 'CLASS IR_EXTERNAL_DECLARATION_STUB OBJECT name:Unit modality:FINAL visibility:public superTypes:[kotlin.Any]' type=kotlin.Unit CALL 'public open fun get (hello: example.Hello?): kotlin.Unit [operator] declared in example.SomeJavaClass' type=kotlin.Unit origin=null $this: GET_VAR 'a: example.SomeJavaClass declared in .test' type=example.SomeJavaClass origin=null - hello: TYPE_OP type=example.Hello? origin=SAM_CONVERSION typeOperand=example.Hello? + hello: TYPE_OP type=example.Hello? origin=SAM_CONVERSION typeOperand=example.Hello? FUN_EXPR type=kotlin.Function1 origin=LAMBDA FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> (it:kotlin.String?) returnType:kotlin.Unit VALUE_PARAMETER name:it index:0 type:kotlin.String?