Fix: constraint T? >: Int! should transform to T >: Int

This commit is contained in:
Svetlana Isakova
2015-01-28 18:51:55 +03:00
parent f5fb3246ae
commit a2f03f2d52
4 changed files with 45 additions and 3 deletions
@@ -0,0 +1,20 @@
// !CHECK_TYPE
// FILE: A.java
public class A {
public static String foo() {
return "";
}
}
// FILE: b.kt
fun <T: Any> exclExcl(t: T?): T = t!!
fun test11() {
// not 'String!'
exclExcl(A.foo()) checkType { it : _<String> }
exclExcl(A.foo()) checkType { <!TYPE_MISMATCH!>it<!> : _<String?> }
// not 'String!'
A.foo()!! checkType { it : _<String> }
A.foo()!! checkType { <!TYPE_MISMATCH!>it<!> : _<String?> }
}
@@ -0,0 +1,14 @@
package
internal fun </*0*/ T : kotlin.Any> exclExcl(/*0*/ t: T?): T
internal fun test11(): kotlin.Unit
public open class A {
public constructor A()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
// Static members
public open fun foo(): kotlin.String!
}
@@ -2022,6 +2022,12 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
doTest(fileName);
}
@TestMetadata("typeInferenceForExclExcl.kt")
public void testTypeInferenceForExclExcl() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/controlStructures/typeInferenceForExclExcl.kt");
doTest(fileName);
}
@TestMetadata("valVarCatchParameter.kt")
public void testValVarCatchParameter() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/controlStructures/valVarCatchParameter.kt");
@@ -333,18 +333,20 @@ public class ConstraintSystemImpl : ConstraintSystem {
val typeBounds = getTypeBounds(parameterType)
if (!parameterType.isMarkedNullable() || !newConstrainingType.isMarkedNullable()) {
if (!parameterType.isMarkedNullable() || !TypeUtils.isNullableType(newConstrainingType)) {
typeBounds.addBound(boundKind, newConstrainingType, constraintPosition)
return
}
// For parameter type T:
// constraint T? = Int? should transform to T >: Int and T <: Int?
// constraint T? >: Int? should transform to T >: Int
// constraint T? = Int! should transform to T >: Int and T <: Int!
// constraints T? >: Int?; T? >: Int! should transform to T >: Int
val notNullConstrainingType = TypeUtils.makeNotNullable(newConstrainingType)
if (boundKind == EXACT_BOUND || boundKind == LOWER_BOUND) {
typeBounds.addBound(LOWER_BOUND, notNullConstrainingType, constraintPosition)
}
// constraint T? <: Int? should transform to T <: Int?
// constraints T? <: Int?; T? <: Int! should transform to T <: Int?; T <: Int! correspondingly
if (boundKind == EXACT_BOUND || boundKind == UPPER_BOUND) {
typeBounds.addBound(UPPER_BOUND, newConstrainingType, constraintPosition)
}