IR: fix SAM conversion for types with contravariant intersection argument type
In the added test, the problem was that the SAM type as computed by
`SamTypeFactory.createByValueParameter` was `Consumer<{BaseClass &
BaseInterface}>`, which was latter approximated in psi2ir during the
KotlinType->IrType conversion to `Consumer<out Any?>` (here:
https://github.com/JetBrains/kotlin/blob/3034d9d791cf1f9033104e12448e0d262d3bc3ce/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/ArgumentsGenerationUtils.kt#L606),
because intersection type argument is approximated to `out Any?`.
To avoid this, replace intersection type in immediate arguments of a SAM
type with the common supertype of its components at the same place where
we're getting rid of projections.
#KT-45945 Fixed
This commit is contained in:
+30
@@ -12721,6 +12721,21 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
runTest("compiler/testData/codegen/box/funInterface/castFromAny.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("contravariantIntersectionType.kt")
|
||||
public void testContravariantIntersectionType() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/funInterface/contravariantIntersectionType.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("contravariantIntersectionTypeWithNonTrivialCommonSupertype.kt")
|
||||
public void testContravariantIntersectionTypeWithNonTrivialCommonSupertype() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/funInterface/contravariantIntersectionTypeWithNonTrivialCommonSupertype.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("contravariantIntersectionTypeWithNonTrivialCommonSupertype2.kt")
|
||||
public void testContravariantIntersectionTypeWithNonTrivialCommonSupertype2() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/funInterface/contravariantIntersectionTypeWithNonTrivialCommonSupertype2.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("funConversionInVararg.kt")
|
||||
public void testFunConversionInVararg() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/funInterface/funConversionInVararg.kt");
|
||||
@@ -30107,6 +30122,21 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
runTest("compiler/testData/codegen/box/sam/castFromAny.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("contravariantIntersectionType.kt")
|
||||
public void testContravariantIntersectionType() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/sam/contravariantIntersectionType.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("contravariantIntersectionTypeWithNonTrivialCommonSupertype.kt")
|
||||
public void testContravariantIntersectionTypeWithNonTrivialCommonSupertype() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/sam/contravariantIntersectionTypeWithNonTrivialCommonSupertype.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("contravariantIntersectionTypeWithNonTrivialCommonSupertype2.kt")
|
||||
public void testContravariantIntersectionTypeWithNonTrivialCommonSupertype2() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/sam/contravariantIntersectionTypeWithNonTrivialCommonSupertype2.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("differentFqNames.kt")
|
||||
public void testDifferentFqNames() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/sam/differentFqNames.kt");
|
||||
|
||||
Reference in New Issue
Block a user