fixed bug in renderer for violated upper bound error

This commit is contained in:
Svetlana Isakova
2013-12-24 14:52:58 +04:00
committed by Andrey Breslav
parent c3ff6a2430
commit 4657a4b271
4 changed files with 22 additions and 2 deletions
@@ -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();
@@ -0,0 +1,10 @@
package g
import java.util.HashSet
fun <T, C: Collection<T>> convert(src: Collection<T>, dest: C): C = throw Exception("$src $dest")
fun test(l: List<Int>) {
//todo should be inferred
val r = <!TYPE_INFERENCE_UPPER_BOUND_VIOLATED!>convert<!>(l, <!TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>HashSet<!>())
<!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>r<!>: Int
}
@@ -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");
@@ -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()) {