Don't create inconsistent types (with contradictive use site and declaration site variances) for star projections with corresponding contravariant type parameters during substitution
^KT-41388 Fixed
This commit is contained in:
Generated
+5
@@ -3153,6 +3153,11 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
||||
runTest("compiler/testData/codegen/box/casts/castGenericNull.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("dontCreateInconsistentTypeDuringStarProjectionSubstitution.kt")
|
||||
public void testDontCreateInconsistentTypeDuringStarProjectionSubstitution() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/casts/dontCreateInconsistentTypeDuringStarProjectionSubstitution.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("intersectionTypeMultipleBounds.kt")
|
||||
public void testIntersectionTypeMultipleBounds() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/casts/intersectionTypeMultipleBounds.kt");
|
||||
|
||||
Vendored
+15
@@ -0,0 +1,15 @@
|
||||
interface I
|
||||
|
||||
interface Foo<in L : I, in M>
|
||||
|
||||
interface Bar<T> {
|
||||
fun test(x: Foo<*, T>)
|
||||
}
|
||||
|
||||
fun foo(x: Any) {
|
||||
if (x is Bar<*>) {
|
||||
x::test
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String = "OK"
|
||||
+5
@@ -3173,6 +3173,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
runTest("compiler/testData/codegen/box/casts/castGenericNull.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("dontCreateInconsistentTypeDuringStarProjectionSubstitution.kt")
|
||||
public void testDontCreateInconsistentTypeDuringStarProjectionSubstitution() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/casts/dontCreateInconsistentTypeDuringStarProjectionSubstitution.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("intersectionTypeMultipleBounds.kt")
|
||||
public void testIntersectionTypeMultipleBounds() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/casts/intersectionTypeMultipleBounds.kt");
|
||||
|
||||
+5
@@ -3173,6 +3173,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
runTest("compiler/testData/codegen/box/casts/castGenericNull.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("dontCreateInconsistentTypeDuringStarProjectionSubstitution.kt")
|
||||
public void testDontCreateInconsistentTypeDuringStarProjectionSubstitution() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/casts/dontCreateInconsistentTypeDuringStarProjectionSubstitution.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("intersectionTypeMultipleBounds.kt")
|
||||
public void testIntersectionTypeMultipleBounds() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/casts/intersectionTypeMultipleBounds.kt");
|
||||
|
||||
+5
@@ -3153,6 +3153,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
runTest("compiler/testData/codegen/box/casts/castGenericNull.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("dontCreateInconsistentTypeDuringStarProjectionSubstitution.kt")
|
||||
public void testDontCreateInconsistentTypeDuringStarProjectionSubstitution() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/casts/dontCreateInconsistentTypeDuringStarProjectionSubstitution.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("intersectionTypeMultipleBounds.kt")
|
||||
public void testIntersectionTypeMultipleBounds() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/casts/intersectionTypeMultipleBounds.kt");
|
||||
|
||||
@@ -55,7 +55,7 @@ private fun TypeArgument.toTypeProjection(): TypeProjection {
|
||||
}
|
||||
fun removeProjectionIfRedundant(variance: Variance) = if (variance == typeParameter.variance) Variance.INVARIANT else variance
|
||||
return when {
|
||||
inProjection == outProjection -> TypeProjectionImpl(inProjection)
|
||||
inProjection == outProjection || typeParameter.variance == Variance.IN_VARIANCE -> TypeProjectionImpl(inProjection)
|
||||
KotlinBuiltIns.isNothing(inProjection) && typeParameter.variance != Variance.IN_VARIANCE ->
|
||||
TypeProjectionImpl(removeProjectionIfRedundant(Variance.OUT_VARIANCE), outProjection)
|
||||
KotlinBuiltIns.isNullableAny(outProjection) -> TypeProjectionImpl(removeProjectionIfRedundant(Variance.IN_VARIANCE), inProjection)
|
||||
|
||||
Generated
+5
@@ -2498,6 +2498,11 @@ public class IrJsCodegenBoxES6TestGenerated extends AbstractIrJsCodegenBoxES6Tes
|
||||
runTest("compiler/testData/codegen/box/casts/castGenericNull.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("dontCreateInconsistentTypeDuringStarProjectionSubstitution.kt")
|
||||
public void testDontCreateInconsistentTypeDuringStarProjectionSubstitution() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/casts/dontCreateInconsistentTypeDuringStarProjectionSubstitution.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("intersectionTypeMultipleBounds.kt")
|
||||
public void testIntersectionTypeMultipleBounds() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/casts/intersectionTypeMultipleBounds.kt");
|
||||
|
||||
Generated
+5
@@ -2498,6 +2498,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
|
||||
runTest("compiler/testData/codegen/box/casts/castGenericNull.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("dontCreateInconsistentTypeDuringStarProjectionSubstitution.kt")
|
||||
public void testDontCreateInconsistentTypeDuringStarProjectionSubstitution() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/casts/dontCreateInconsistentTypeDuringStarProjectionSubstitution.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("intersectionTypeMultipleBounds.kt")
|
||||
public void testIntersectionTypeMultipleBounds() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/casts/intersectionTypeMultipleBounds.kt");
|
||||
|
||||
+5
@@ -2498,6 +2498,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
||||
runTest("compiler/testData/codegen/box/casts/castGenericNull.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("dontCreateInconsistentTypeDuringStarProjectionSubstitution.kt")
|
||||
public void testDontCreateInconsistentTypeDuringStarProjectionSubstitution() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/casts/dontCreateInconsistentTypeDuringStarProjectionSubstitution.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("intersectionTypeMultipleBounds.kt")
|
||||
public void testIntersectionTypeMultipleBounds() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/casts/intersectionTypeMultipleBounds.kt");
|
||||
|
||||
Reference in New Issue
Block a user