From 4657a4b271b059a969eb5b3885a74f0d15129b2e Mon Sep 17 00:00:00 2001 From: Svetlana Isakova Date: Tue, 24 Dec 2013 14:52:58 +0400 Subject: [PATCH] fixed bug in renderer for violated upper bound error --- .../jet/lang/diagnostics/rendering/Renderers.java | 6 +++++- .../conflictingSubstitutionsFromUpperBound.kt | 10 ++++++++++ .../jet/checkers/JetDiagnosticsTestGenerated.java | 5 +++++ .../jetbrains/jet/renderer/DescriptorRendererImpl.java | 3 ++- 4 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 compiler/testData/diagnostics/tests/inference/upperBounds/conflictingSubstitutionsFromUpperBound.kt diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/rendering/Renderers.java b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/rendering/Renderers.java index 15910b09c0d..826f4b94502 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/rendering/Renderers.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/rendering/Renderers.java @@ -267,7 +267,8 @@ public class Renderers { TypeParameterDescriptor typeParameterDescriptor = null; ConstraintSystemImpl constraintSystem = (ConstraintSystemImpl) inferenceErrorData.constraintSystem; - assert constraintSystem.getStatus().hasViolatedUpperBound(); + ConstraintSystemStatus status = constraintSystem.getStatus(); + assert status.hasViolatedUpperBound(); ConstraintSystem systemWithoutWeakConstraints = constraintSystem.getSystemWithoutWeakConstraints(); for (TypeParameterDescriptor typeParameter : inferenceErrorData.descriptor.getTypeParameters()) { @@ -275,6 +276,9 @@ public class Renderers { typeParameterDescriptor = typeParameter; } } + if (typeParameterDescriptor == null && status.hasConflictingConstraints()) { + return renderConflictingSubstitutionsInferenceError(inferenceErrorData, result); + } assert typeParameterDescriptor != null : errorMessage; JetType inferredValueForTypeParameter = systemWithoutWeakConstraints.getTypeBounds(typeParameterDescriptor).getValue(); diff --git a/compiler/testData/diagnostics/tests/inference/upperBounds/conflictingSubstitutionsFromUpperBound.kt b/compiler/testData/diagnostics/tests/inference/upperBounds/conflictingSubstitutionsFromUpperBound.kt new file mode 100644 index 00000000000..9e7bf3636a4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/upperBounds/conflictingSubstitutionsFromUpperBound.kt @@ -0,0 +1,10 @@ +package g + +import java.util.HashSet +fun > convert(src: Collection, dest: C): C = throw Exception("$src $dest") + +fun test(l: List) { + //todo should be inferred + val r = convert(l, HashSet()) + r: Int +} diff --git a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java index a7dcd42793e..762ec8a178c 100644 --- a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java @@ -3907,6 +3907,11 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest { JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("compiler/testData/diagnostics/tests/inference/upperBounds"), Pattern.compile("^(.+)\\.kt$"), true); } + @TestMetadata("conflictingSubstitutionsFromUpperBound.kt") + public void testConflictingSubstitutionsFromUpperBound() throws Exception { + doTest("compiler/testData/diagnostics/tests/inference/upperBounds/conflictingSubstitutionsFromUpperBound.kt"); + } + @TestMetadata("doNotInferFromBoundsOnly.kt") public void testDoNotInferFromBoundsOnly() throws Exception { doTest("compiler/testData/diagnostics/tests/inference/upperBounds/doNotInferFromBoundsOnly.kt"); diff --git a/core/descriptors/src/org/jetbrains/jet/renderer/DescriptorRendererImpl.java b/core/descriptors/src/org/jetbrains/jet/renderer/DescriptorRendererImpl.java index 4741a0a6e9c..a54b2b50d03 100644 --- a/core/descriptors/src/org/jetbrains/jet/renderer/DescriptorRendererImpl.java +++ b/core/descriptors/src/org/jetbrains/jet/renderer/DescriptorRendererImpl.java @@ -36,6 +36,7 @@ import java.util.*; import static org.jetbrains.jet.lang.types.TypeUtils.CANT_INFER_LAMBDA_PARAM_TYPE; import static org.jetbrains.jet.lang.types.TypeUtils.CANT_INFER_TYPE_PARAMETER; +import static org.jetbrains.jet.lang.types.TypeUtils.DONT_CARE; public class DescriptorRendererImpl implements DescriptorRenderer { private final boolean shortNames; @@ -213,7 +214,7 @@ public class DescriptorRendererImpl implements DescriptorRenderer { } private String renderTypeWithoutEscape(@NotNull JetType type) { - if (type == CANT_INFER_LAMBDA_PARAM_TYPE || type == CANT_INFER_TYPE_PARAMETER) { + if (type == CANT_INFER_LAMBDA_PARAM_TYPE || type == CANT_INFER_TYPE_PARAMETER || type == DONT_CARE) { return "???"; } if (type.isError()) {