Constraint Foo on T! should be turned into Foo! on T
This commit is contained in:
@@ -0,0 +1,8 @@
|
|||||||
|
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE
|
||||||
|
|
||||||
|
trait Foo
|
||||||
|
|
||||||
|
fun test() {
|
||||||
|
var nullable: Foo? = null
|
||||||
|
val foo: Collection<Foo> = java.util.Collections.singleton(nullable)
|
||||||
|
}
|
||||||
@@ -7795,6 +7795,11 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("singleton.kt")
|
||||||
|
public void testSingleton() throws Exception {
|
||||||
|
doTest("compiler/testData/diagnostics/tests/platformTypes/methodCall/singleton.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("string.kt")
|
@TestMetadata("string.kt")
|
||||||
public void testString() throws Exception {
|
public void testString() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/platformTypes/methodCall/string.kt");
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/platformTypes/methodCall/string.kt");
|
||||||
|
|||||||
+17
@@ -413,6 +413,23 @@ public class ConstraintSystemImpl implements ConstraintSystem {
|
|||||||
@NotNull TypeBoundsImpl.BoundKind boundKind,
|
@NotNull TypeBoundsImpl.BoundKind boundKind,
|
||||||
@NotNull ConstraintPosition constraintPosition
|
@NotNull ConstraintPosition constraintPosition
|
||||||
) {
|
) {
|
||||||
|
// Here we are handling the case when T! gets a bound Foo (or Foo?)
|
||||||
|
// In this case, type parameter T is supposed to get the bound Foo!
|
||||||
|
// Example:
|
||||||
|
// val c: Collection<Foo> = Collections.singleton(null : Foo?)
|
||||||
|
// Constraints for T are:
|
||||||
|
// Foo? <: T!
|
||||||
|
// Foo >: T!
|
||||||
|
// both Foo and Foo? transform to Foo! here
|
||||||
|
if (TypesPackage.isFlexible(parameterType)) {
|
||||||
|
if (parameterType instanceof CustomTypeVariable) {
|
||||||
|
CustomTypeVariable typeVariable = (CustomTypeVariable) parameterType;
|
||||||
|
if (typeVariable.getIsTypeVariable()) {
|
||||||
|
constrainingType = typeVariable.substitutionResult(constrainingType);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
TypeBoundsImpl typeBounds = getTypeBounds(parameterType);
|
TypeBoundsImpl typeBounds = getTypeBounds(parameterType);
|
||||||
assert typeBounds != null : "constraint should be generated only for type variables";
|
assert typeBounds != null : "constraint should be generated only for type variables";
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user