improved error message
added debug info about constraint system status
This commit is contained in:
+30
@@ -24,6 +24,8 @@ import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor;
|
||||
import org.jetbrains.jet.lang.types.*;
|
||||
import org.jetbrains.jet.lang.types.checker.JetTypeChecker;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.*;
|
||||
|
||||
public class ConstraintsUtil {
|
||||
@@ -110,4 +112,32 @@ public class ConstraintsUtil {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static String getDebugMessageForStatus(@NotNull ConstraintSystemStatus status) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
List<Method> interestingMethods = Lists.newArrayList();
|
||||
for (Method method : status.getClass().getMethods()) {
|
||||
String name = method.getName();
|
||||
boolean isInteresting = name.startsWith("is") || name.startsWith("has") && !name.equals("hashCode");
|
||||
if (method.getParameterTypes().length == 0 && isInteresting) {
|
||||
interestingMethods.add(method);
|
||||
}
|
||||
}
|
||||
for (Iterator<Method> iterator = interestingMethods.iterator(); iterator.hasNext(); ) {
|
||||
Method method = iterator.next();
|
||||
try {
|
||||
sb.append("-").append(method.getName()).append(": ").append(method.invoke(status));
|
||||
if (iterator.hasNext()) {
|
||||
sb.append("\n");
|
||||
}
|
||||
}
|
||||
catch (IllegalAccessException e) {
|
||||
sb.append(e.getMessage());
|
||||
}
|
||||
catch (InvocationTargetException e) {
|
||||
sb.append(e.getMessage());
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
||||
+14
-5
@@ -35,6 +35,7 @@ import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo;
|
||||
import org.jetbrains.jet.lang.resolve.calls.inference.ConstraintPosition;
|
||||
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.ConstraintsUtil;
|
||||
import org.jetbrains.jet.lang.resolve.calls.inference.InferenceErrorData;
|
||||
import org.jetbrains.jet.lang.resolve.calls.model.MutableDataFlowInfoForArguments;
|
||||
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
|
||||
@@ -345,13 +346,13 @@ public class ControlStructureTypingUtils {
|
||||
if (status.hasErrorInConstrainingTypes()) {
|
||||
return;
|
||||
}
|
||||
JetExpression expression = call.getCalleeExpression();
|
||||
if (expression == null) return;
|
||||
if (status.hasOnlyErrorsFromPosition(ConstraintPosition.EXPECTED_TYPE_POSITION) || status.hasConflictingConstraints()) {
|
||||
JetExpression expression = call.getCalleeExpression();
|
||||
if (expression != null) {
|
||||
expression.accept(checkTypeVisitor, new CheckTypeContext(trace, data.expectedType));
|
||||
}
|
||||
expression.accept(checkTypeVisitor, new CheckTypeContext(trace, data.expectedType));
|
||||
return;
|
||||
}
|
||||
throwError("Expression: " + expression.getText() + ".\nConstraint system status: \n" + ConstraintsUtil.getDebugMessageForStatus(status));
|
||||
super.typeInferenceFailed(trace, data);
|
||||
}
|
||||
};
|
||||
@@ -365,7 +366,15 @@ public class ControlStructureTypingUtils {
|
||||
}
|
||||
|
||||
private void throwError() {
|
||||
throw new IllegalStateException("Resolution error of this type shouldn't occur for " + debugName);
|
||||
throwError(null);
|
||||
}
|
||||
|
||||
protected void throwError(@Nullable String additionalInformation) {
|
||||
String errorMessage = "Resolution error of this type shouldn't occur for " + debugName;
|
||||
if (additionalInformation != null) {
|
||||
errorMessage += ".\n" + additionalInformation;
|
||||
}
|
||||
throw new IllegalStateException(errorMessage);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+2
@@ -59,6 +59,8 @@ public class ConstraintSystemImpl implements ConstraintSystem {
|
||||
private boolean hasErrorInConstrainingTypes;
|
||||
|
||||
private final ConstraintSystemStatus constraintSystemStatus = new ConstraintSystemStatus() {
|
||||
// for debug ConstraintsUtil.getDebugMessageForStatus might be used
|
||||
|
||||
@Override
|
||||
public boolean isSuccessful() {
|
||||
return !hasContradiction() && !hasUnknownParameters();
|
||||
|
||||
Reference in New Issue
Block a user