[NI] Consider CS as nullable if one of the types isn't subtype of Any
Note that this isn't fully correct, consider the following situation: S : T, T : Any? => CS(S, T) = T, but for now it will be T?, which is reliable but not so specific as just T
This commit is contained in:
+4
-7
@@ -19,10 +19,7 @@ package org.jetbrains.kotlin.resolve.calls
|
|||||||
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
|
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||||
import org.jetbrains.kotlin.types.*
|
import org.jetbrains.kotlin.types.*
|
||||||
import org.jetbrains.kotlin.types.checker.NewKotlinTypeChecker
|
import org.jetbrains.kotlin.types.checker.*
|
||||||
import org.jetbrains.kotlin.types.checker.TypeCheckerContext
|
|
||||||
import org.jetbrains.kotlin.types.checker.anySuperTypeConstructor
|
|
||||||
import org.jetbrains.kotlin.types.checker.intersectTypes
|
|
||||||
import org.jetbrains.kotlin.types.typeUtil.asTypeProjection
|
import org.jetbrains.kotlin.types.typeUtil.asTypeProjection
|
||||||
|
|
||||||
object NewCommonSuperTypeCalculator {
|
object NewCommonSuperTypeCalculator {
|
||||||
@@ -56,12 +53,12 @@ object NewCommonSuperTypeCalculator {
|
|||||||
|
|
||||||
private fun commonSuperTypeForSimpleTypes(types: List<SimpleType>): SimpleType {
|
private fun commonSuperTypeForSimpleTypes(types: List<SimpleType>): SimpleType {
|
||||||
// i.e. result type also should be marked nullable
|
// i.e. result type also should be marked nullable
|
||||||
val anyMarkedNullable = types.any { it.isMarkedNullable }
|
val notAllNotNull = types.any { !NullabilityChecker.isSubtypeOfAny(it) }
|
||||||
val notNullTypes = if (anyMarkedNullable) types.map { it.makeNullableAsSpecified(false) } else types
|
val notNullTypes = if (notAllNotNull) types.map { it.makeNullableAsSpecified(false) } else types
|
||||||
|
|
||||||
val commonSuperTypes = commonSuperTypeForNotNullTypes(notNullTypes)
|
val commonSuperTypes = commonSuperTypeForNotNullTypes(notNullTypes)
|
||||||
|
|
||||||
return if (anyMarkedNullable) commonSuperTypes.makeNullableAsSpecified(true) else commonSuperTypes
|
return if (notAllNotNull) commonSuperTypes.makeNullableAsSpecified(true) else commonSuperTypes
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun List<SimpleType>.uniquify(): List<SimpleType> {
|
private fun List<SimpleType>.uniquify(): List<SimpleType> {
|
||||||
|
|||||||
+14
@@ -0,0 +1,14 @@
|
|||||||
|
val targetArgument = id2(star(), star()) // error
|
||||||
|
|
||||||
|
fun <T> id2(x: T, y: T): T = x
|
||||||
|
|
||||||
|
fun star(): Sample<*> {
|
||||||
|
return Sample<Int>()
|
||||||
|
}
|
||||||
|
|
||||||
|
class Sample<out T>
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
targetArgument
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
+6
@@ -16928,6 +16928,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("nullabilityForCommonCapturedSupertypes.kt")
|
||||||
|
public void testNullabilityForCommonCapturedSupertypes() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/regressions/nullabilityForCommonCapturedSupertypes.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("objectCaptureOuterConstructorProperty.kt")
|
@TestMetadata("objectCaptureOuterConstructorProperty.kt")
|
||||||
public void testObjectCaptureOuterConstructorProperty() throws Exception {
|
public void testObjectCaptureOuterConstructorProperty() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/regressions/objectCaptureOuterConstructorProperty.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/regressions/objectCaptureOuterConstructorProperty.kt");
|
||||||
|
|||||||
@@ -16928,6 +16928,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("nullabilityForCommonCapturedSupertypes.kt")
|
||||||
|
public void testNullabilityForCommonCapturedSupertypes() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/regressions/nullabilityForCommonCapturedSupertypes.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("objectCaptureOuterConstructorProperty.kt")
|
@TestMetadata("objectCaptureOuterConstructorProperty.kt")
|
||||||
public void testObjectCaptureOuterConstructorProperty() throws Exception {
|
public void testObjectCaptureOuterConstructorProperty() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/regressions/objectCaptureOuterConstructorProperty.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/regressions/objectCaptureOuterConstructorProperty.kt");
|
||||||
|
|||||||
@@ -16928,6 +16928,12 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("nullabilityForCommonCapturedSupertypes.kt")
|
||||||
|
public void testNullabilityForCommonCapturedSupertypes() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/regressions/nullabilityForCommonCapturedSupertypes.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("objectCaptureOuterConstructorProperty.kt")
|
@TestMetadata("objectCaptureOuterConstructorProperty.kt")
|
||||||
public void testObjectCaptureOuterConstructorProperty() throws Exception {
|
public void testObjectCaptureOuterConstructorProperty() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/regressions/objectCaptureOuterConstructorProperty.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/regressions/objectCaptureOuterConstructorProperty.kt");
|
||||||
|
|||||||
@@ -20702,6 +20702,12 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
|||||||
throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive for that.");
|
throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive for that.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("nullabilityForCommonCapturedSupertypes.kt")
|
||||||
|
public void testNullabilityForCommonCapturedSupertypes() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/regressions/nullabilityForCommonCapturedSupertypes.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("objectCaptureOuterConstructorProperty.kt")
|
@TestMetadata("objectCaptureOuterConstructorProperty.kt")
|
||||||
public void testObjectCaptureOuterConstructorProperty() throws Exception {
|
public void testObjectCaptureOuterConstructorProperty() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/regressions/objectCaptureOuterConstructorProperty.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/regressions/objectCaptureOuterConstructorProperty.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user