From 141e731f39e280b63e2b565eec83ac2a08522db2 Mon Sep 17 00:00:00 2001 From: Andrey Breslav Date: Mon, 25 Aug 2014 17:55:30 +0400 Subject: [PATCH] Constraint Foo on T! should be turned into Foo! on T --- .../tests/platformTypes/methodCall/singleton.kt | 8 ++++++++ .../checkers/JetDiagnosticsTestGenerated.java | 5 +++++ .../calls/inference/ConstraintSystemImpl.java | 17 +++++++++++++++++ 3 files changed, 30 insertions(+) create mode 100644 compiler/testData/diagnostics/tests/platformTypes/methodCall/singleton.kt diff --git a/compiler/testData/diagnostics/tests/platformTypes/methodCall/singleton.kt b/compiler/testData/diagnostics/tests/platformTypes/methodCall/singleton.kt new file mode 100644 index 00000000000..761f12c12a8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/methodCall/singleton.kt @@ -0,0 +1,8 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE + +trait Foo + +fun test() { + var nullable: Foo? = null + val foo: Collection = java.util.Collections.singleton(nullable) +} \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java index babe241e902..b27bdc320ee 100644 --- a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java @@ -7795,6 +7795,11 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest { doTest(fileName); } + @TestMetadata("singleton.kt") + public void testSingleton() throws Exception { + doTest("compiler/testData/diagnostics/tests/platformTypes/methodCall/singleton.kt"); + } + @TestMetadata("string.kt") public void testString() throws Exception { String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/platformTypes/methodCall/string.kt"); diff --git a/core/descriptors/src/org/jetbrains/jet/lang/resolve/calls/inference/ConstraintSystemImpl.java b/core/descriptors/src/org/jetbrains/jet/lang/resolve/calls/inference/ConstraintSystemImpl.java index fe324498bb5..5a92aa40438 100644 --- a/core/descriptors/src/org/jetbrains/jet/lang/resolve/calls/inference/ConstraintSystemImpl.java +++ b/core/descriptors/src/org/jetbrains/jet/lang/resolve/calls/inference/ConstraintSystemImpl.java @@ -413,6 +413,23 @@ public class ConstraintSystemImpl implements ConstraintSystem { @NotNull TypeBoundsImpl.BoundKind boundKind, @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 = 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); assert typeBounds != null : "constraint should be generated only for type variables";