[NI] Make return type of !! operator definitely not-null
This commit is contained in:
+15
-3
@@ -30,7 +30,6 @@ import org.jetbrains.kotlin.types.TypeConstructor
|
||||
import org.jetbrains.kotlin.types.UnwrappedType
|
||||
import org.jetbrains.kotlin.types.typeUtil.builtIns
|
||||
import org.jetbrains.kotlin.types.typeUtil.contains
|
||||
import org.jetbrains.kotlin.types.typeUtil.isTypeParameter
|
||||
import org.jetbrains.kotlin.utils.SmartList
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||
|
||||
@@ -45,6 +44,10 @@ class NewConstraintSystemImpl(
|
||||
KotlinConstraintSystemCompleter.Context,
|
||||
PostponedArgumentsAnalyzer.Context
|
||||
{
|
||||
companion object {
|
||||
private val TYPE_PARAMETER_FOR_EXCLXCL = "<TYPE-PARAMETER-FOR-EXCLEXCL-RESOLVE>" // TODO: Get this variable from ResolveConstruct
|
||||
}
|
||||
|
||||
private val storage = MutableConstraintStorage()
|
||||
private var state = State.BUILDING
|
||||
private val typeVariablesTransaction: MutableList<NewTypeVariable> = SmartList()
|
||||
@@ -205,7 +208,7 @@ class NewConstraintSystemImpl(
|
||||
override fun fixVariable(variable: NewTypeVariable, resultType: UnwrappedType) {
|
||||
checkState(State.BUILDING, State.COMPLETION)
|
||||
|
||||
val actualResultType = eliminateSpecialIntersectionType(resultType) ?: resultType
|
||||
val actualResultType = eliminateSpecialIntersectionType(variable, resultType) ?: resultType
|
||||
constraintInjector.addInitialEqualityConstraint(this, variable.defaultType, actualResultType, FixVariableConstraintPosition(variable))
|
||||
notFixedTypeVariables.remove(variable.freshTypeConstructor)
|
||||
|
||||
@@ -218,7 +221,9 @@ class NewConstraintSystemImpl(
|
||||
storage.fixedTypeVariables[variable.freshTypeConstructor] = actualResultType
|
||||
}
|
||||
|
||||
private fun eliminateSpecialIntersectionType(type: UnwrappedType): UnwrappedType? {
|
||||
private fun eliminateSpecialIntersectionType(variable: NewTypeVariable, type: UnwrappedType): UnwrappedType? {
|
||||
if (variable.shouldBeDefinitelyNotNull()) return null
|
||||
|
||||
val constructor = type.constructor.safeAs<IntersectionTypeConstructor>() ?: return null
|
||||
|
||||
if (constructor.supertypes.size != 2) return null
|
||||
@@ -227,6 +232,13 @@ class NewConstraintSystemImpl(
|
||||
return actualType?.unwrap()
|
||||
}
|
||||
|
||||
private fun NewTypeVariable.shouldBeDefinitelyNotNull(): Boolean {
|
||||
return when (this) {
|
||||
is TypeVariableFromCallableDescriptor -> originalTypeParameter.name.asString() == TYPE_PARAMETER_FOR_EXCLXCL
|
||||
is TypeVariableForLambdaReturnType -> false
|
||||
}
|
||||
}
|
||||
|
||||
// KotlinConstraintSystemCompleter.Context, PostponedArgumentsAnalyzer.Context
|
||||
override fun canBeProper(type: UnwrappedType): Boolean {
|
||||
checkState(State.BUILDING, State.COMPLETION)
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
interface Sample {
|
||||
val callMe: Int
|
||||
}
|
||||
|
||||
class Caller<out M : Sample?>(val member: M) {
|
||||
fun test() {
|
||||
member!!.callMe
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
return "OK"
|
||||
}
|
||||
+6
@@ -17042,6 +17042,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("nullableAfterExclExcl.kt")
|
||||
public void testNullableAfterExclExcl() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/regressions/nullableAfterExclExcl.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("objectCaptureOuterConstructorProperty.kt")
|
||||
public void testObjectCaptureOuterConstructorProperty() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/regressions/objectCaptureOuterConstructorProperty.kt");
|
||||
|
||||
@@ -17042,6 +17042,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("nullableAfterExclExcl.kt")
|
||||
public void testNullableAfterExclExcl() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/regressions/nullableAfterExclExcl.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("objectCaptureOuterConstructorProperty.kt")
|
||||
public void testObjectCaptureOuterConstructorProperty() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/regressions/objectCaptureOuterConstructorProperty.kt");
|
||||
|
||||
@@ -17042,6 +17042,12 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("nullableAfterExclExcl.kt")
|
||||
public void testNullableAfterExclExcl() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/regressions/nullableAfterExclExcl.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("objectCaptureOuterConstructorProperty.kt")
|
||||
public void testObjectCaptureOuterConstructorProperty() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/regressions/objectCaptureOuterConstructorProperty.kt");
|
||||
|
||||
@@ -20828,6 +20828,12 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("nullableAfterExclExcl.kt")
|
||||
public void testNullableAfterExclExcl() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/regressions/nullableAfterExclExcl.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("objectCaptureOuterConstructorProperty.kt")
|
||||
public void testObjectCaptureOuterConstructorProperty() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/regressions/objectCaptureOuterConstructorProperty.kt");
|
||||
|
||||
Reference in New Issue
Block a user