diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/tasks/TracingStrategyImpl.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/tasks/TracingStrategyImpl.java index 30095b7fa69..2554ca7b543 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/tasks/TracingStrategyImpl.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/tasks/TracingStrategyImpl.java @@ -23,9 +23,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.jet.lang.descriptors.*; import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lang.resolve.BindingTrace; -import org.jetbrains.jet.lang.resolve.calls.inference.ConstraintSystem; -import org.jetbrains.jet.lang.resolve.calls.inference.ConstraintSystemStatus; -import org.jetbrains.jet.lang.resolve.calls.inference.InferenceErrorData; +import org.jetbrains.jet.lang.resolve.calls.inference.*; import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCallWithTrace; import org.jetbrains.jet.lang.resolve.calls.model.VariableAsFunctionResolvedCall; import org.jetbrains.jet.lang.resolve.name.Name; @@ -226,7 +224,9 @@ public class TracingStrategyImpl implements TracingStrategy { JetType declaredReturnType = data.descriptor.getReturnType(); if (declaredReturnType == null) return; - JetType substitutedReturnType = constraintSystem.getResultingSubstitutor().substitute(declaredReturnType, Variance.INVARIANT); + ConstraintSystem systemWithoutExpectedTypeConstraint = + ((ConstraintSystemImpl) constraintSystem).filterConstraintsOut(ConstraintPosition.EXPECTED_TYPE_POSITION); + JetType substitutedReturnType = systemWithoutExpectedTypeConstraint.getResultingSubstitutor().substitute(declaredReturnType, Variance.INVARIANT); assert substitutedReturnType != null; //todo assert !noExpectedType(data.expectedType) : "Expected type doesn't exist, but there is an expected type mismatch error"; 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 dad8cfbe66d..6fcf8b03dde 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 @@ -486,9 +486,6 @@ public class ConstraintSystemImpl implements ConstraintSystem { @NotNull @Override public TypeSubstitutor getResultingSubstitutor() { - if (getStatus().hasOnlyExpectedTypeMismatch()) { - return filterConstraintsOut(EXPECTED_TYPE_POSITION).getResultingSubstitutor(); - } return resultingSubstitutor; } diff --git a/idea/testData/diagnosticMessage/typeInferenceExpectedTypeMismatch.kt b/idea/testData/diagnosticMessage/typeInferenceExpectedTypeMismatch.kt new file mode 100644 index 00000000000..d4664052421 --- /dev/null +++ b/idea/testData/diagnosticMessage/typeInferenceExpectedTypeMismatch.kt @@ -0,0 +1,11 @@ +package s + +fun id(t: T): T = t + +fun test(set: Set) { + val s: String = id(1) + + val l: List = id(set) + + val ss: Set = id(set) +} \ No newline at end of file diff --git a/idea/testData/diagnosticMessage/typeInferenceExpectedTypeMismatch1.html b/idea/testData/diagnosticMessage/typeInferenceExpectedTypeMismatch1.html new file mode 100644 index 00000000000..9d79d264d07 --- /dev/null +++ b/idea/testData/diagnosticMessage/typeInferenceExpectedTypeMismatch1.html @@ -0,0 +1,23 @@ + + +Type inference failed. Expected type mismatch: + + + + + + + + +
+required: + +jet.String +
+found: + + +jet.Int + +
+ \ No newline at end of file diff --git a/idea/testData/diagnosticMessage/typeInferenceExpectedTypeMismatch2.html b/idea/testData/diagnosticMessage/typeInferenceExpectedTypeMismatch2.html new file mode 100644 index 00000000000..1b99f352ef9 --- /dev/null +++ b/idea/testData/diagnosticMessage/typeInferenceExpectedTypeMismatch2.html @@ -0,0 +1,23 @@ + + +Type inference failed. Expected type mismatch: + + + + + + + + +
+required: + +jet.List<jet.Int> +
+found: + + +jet.Set<jet.Int> + +
+ \ No newline at end of file diff --git a/idea/testData/diagnosticMessage/typeInferenceExpectedTypeMismatch3.html b/idea/testData/diagnosticMessage/typeInferenceExpectedTypeMismatch3.html new file mode 100644 index 00000000000..70ac3f4138b --- /dev/null +++ b/idea/testData/diagnosticMessage/typeInferenceExpectedTypeMismatch3.html @@ -0,0 +1,23 @@ + + +Type inference failed. Expected type mismatch: + + + + + + + + +
+required: + +jet.Set<jet.String> +
+found: + + +jet.Set<jet.Int> + +
+ \ No newline at end of file diff --git a/idea/tests/org/jetbrains/jet/plugin/highlighter/DiagnosticMessageTest.java b/idea/tests/org/jetbrains/jet/plugin/highlighter/DiagnosticMessageTest.java index 3ff6e5a79a8..ea5c0273cf3 100644 --- a/idea/tests/org/jetbrains/jet/plugin/highlighter/DiagnosticMessageTest.java +++ b/idea/tests/org/jetbrains/jet/plugin/highlighter/DiagnosticMessageTest.java @@ -118,4 +118,8 @@ public class DiagnosticMessageTest extends JetLiteFixture { doTest("numberValueTypes", 4, Errors.TYPE_INFERENCE_EXPECTED_TYPE_MISMATCH, Errors.TYPE_INFERENCE_TYPE_CONSTRUCTOR_MISMATCH, Errors.TYPE_INFERENCE_CONFLICTING_SUBSTITUTIONS); } + + public void testTypeInferenceExpectedTypeMismatch() throws Exception { + doTest("typeInferenceExpectedTypeMismatch", 3, Errors.TYPE_INFERENCE_EXPECTED_TYPE_MISMATCH); + } }