refactoring: added hasOnlyErrorsFromPosition(ConstraintPosition)

to use it for errors from completer as well
This commit is contained in:
Svetlana Isakova
2013-10-01 14:42:22 +04:00
parent 6c584fd252
commit 0f444903f6
7 changed files with 21 additions and 19 deletions
@@ -28,6 +28,7 @@ import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.lang.resolve.TraceUtil; import org.jetbrains.jet.lang.resolve.TraceUtil;
import org.jetbrains.jet.lang.resolve.calls.context.BasicCallResolutionContext; import org.jetbrains.jet.lang.resolve.calls.context.BasicCallResolutionContext;
import org.jetbrains.jet.lang.resolve.calls.context.CallResolutionContext; import org.jetbrains.jet.lang.resolve.calls.context.CallResolutionContext;
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.ConstraintSystem;
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCallImpl; import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCallImpl;
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCallWithTrace; import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCallWithTrace;
@@ -128,7 +129,7 @@ public class CallResolverUtil {
// Expected type mismatch was reported before as 'TYPE_INFERENCE_EXPECTED_TYPE_MISMATCH' // Expected type mismatch was reported before as 'TYPE_INFERENCE_EXPECTED_TYPE_MISMATCH'
ConstraintSystem constraintSystem = callToComplete.getConstraintSystem(); ConstraintSystem constraintSystem = callToComplete.getConstraintSystem();
if (constraintSystem != null && constraintSystem.getStatus().hasOnlyExpectedTypeMismatch()) return false; if (constraintSystem != null && constraintSystem.getStatus().hasOnlyErrorsFromPosition(ConstraintPosition.EXPECTED_TYPE_POSITION)) return false;
return true; return true;
} }
@@ -270,14 +270,13 @@ public class CandidateResolver {
BindingContext.CONSTRAINT_SYSTEM_COMPLETER, context.call.getCalleeExpression()); BindingContext.CONSTRAINT_SYSTEM_COMPLETER, context.call.getCalleeExpression());
if (constraintSystemCompleter == null) return; if (constraintSystemCompleter == null) return;
ConstraintSystemImpl backup = (ConstraintSystemImpl) constraintSystem.copy(); ConstraintSystem copy = constraintSystem.copy();
constraintSystemCompleter.completeConstraintSystem(copy, resolvedCall);
//todo improve error reporting with errors in constraints from completer //todo improve error reporting with errors in constraints from completer
constraintSystemCompleter.completeConstraintSystem(constraintSystem, resolvedCall); if (!copy.getStatus().hasOnlyErrorsFromPosition(ConstraintPosition.FROM_COMPLETER)) {
if (constraintSystem.getStatus().hasTypeConstructorMismatchAt(ConstraintPosition.FROM_COMPLETER) || resolvedCall.setConstraintSystem(copy);
(constraintSystem.getStatus().hasContradiction() && !backup.getStatus().hasContradiction())) {
resolvedCall.setConstraintSystem(backup);
} }
} }
@@ -295,8 +294,7 @@ public class CandidateResolver {
copy.addSupertypeConstraint(KotlinBuiltIns.getInstance().getUnitType(), returnType, ConstraintPosition.EXPECTED_TYPE_POSITION); copy.addSupertypeConstraint(KotlinBuiltIns.getInstance().getUnitType(), returnType, ConstraintPosition.EXPECTED_TYPE_POSITION);
if (copy.getStatus().isSuccessful()) { if (copy.getStatus().isSuccessful()) {
constraintSystem = copy; resolvedCall.setConstraintSystem(copy);
resolvedCall.setConstraintSystem(constraintSystem);
} }
} }
} }
@@ -220,7 +220,7 @@ public class TracingStrategyImpl implements TracingStrategy {
// (it's useful, when the arguments, e.g. lambdas or calls are incomplete) // (it's useful, when the arguments, e.g. lambdas or calls are incomplete)
return; return;
} }
if (status.hasOnlyExpectedTypeMismatch()) { if (status.hasOnlyErrorsFromPosition(ConstraintPosition.EXPECTED_TYPE_POSITION)) {
JetType declaredReturnType = data.descriptor.getReturnType(); JetType declaredReturnType = data.descriptor.getReturnType();
if (declaredReturnType == null) return; if (declaredReturnType == null) return;
@@ -32,6 +32,7 @@ import org.jetbrains.jet.lang.resolve.BindingContextUtils;
import org.jetbrains.jet.lang.resolve.BindingTrace; import org.jetbrains.jet.lang.resolve.BindingTrace;
import org.jetbrains.jet.lang.resolve.calls.CallResolver; import org.jetbrains.jet.lang.resolve.calls.CallResolver;
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo; 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.ConstraintSystem;
import org.jetbrains.jet.lang.resolve.calls.inference.ConstraintSystemStatus; 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.InferenceErrorData;
@@ -344,7 +345,7 @@ public class ControlStructureTypingUtils {
if (status.hasErrorInConstrainingTypes()) { if (status.hasErrorInConstrainingTypes()) {
return; return;
} }
if (status.hasOnlyExpectedTypeMismatch() || status.hasConflictingConstraints()) { if (status.hasOnlyErrorsFromPosition(ConstraintPosition.EXPECTED_TYPE_POSITION) || status.hasConflictingConstraints()) {
JetExpression expression = call.getCalleeExpression(); JetExpression expression = call.getCalleeExpression();
if (expression != null) { if (expression != null) {
expression.accept(checkTypeVisitor, new CheckTypeContext(trace, data.expectedType)); expression.accept(checkTypeVisitor, new CheckTypeContext(trace, data.expectedType));
@@ -4,6 +4,8 @@ open class A {
val B.w: Int by <!TYPE_INFERENCE_UPPER_BOUND_VIOLATED!>MyProperty<!>() val B.w: Int by <!TYPE_INFERENCE_UPPER_BOUND_VIOLATED!>MyProperty<!>()
} }
val B.r: Int by <!TYPE_INFERENCE_UPPER_BOUND_VIOLATED!>MyProperty<!>()
val A.e: Int by MyProperty() val A.e: Int by MyProperty()
class B { class B {
@@ -106,15 +106,14 @@ public class ConstraintSystemImpl implements ConstraintSystem {
} }
@Override @Override
public boolean hasOnlyExpectedTypeMismatch() { public boolean hasOnlyErrorsFromPosition(ConstraintPosition constraintPosition) {
if (isSuccessful()) return false; if (isSuccessful()) return false;
ConstraintSystem systemWithoutExpectedTypeConstraint = filterConstraintsOut(EXPECTED_TYPE_POSITION); ConstraintSystem systemWithoutConstraintsFromPosition = filterConstraintsOut(constraintPosition);
if (systemWithoutExpectedTypeConstraint.getStatus().isSuccessful()) { if (systemWithoutConstraintsFromPosition.getStatus().isSuccessful()) {
return true; return true;
} }
if (errorConstraintPositions.size() == 1 && errorConstraintPositions.contains(EXPECTED_TYPE_POSITION)) { if (errorConstraintPositions.size() == 1 && errorConstraintPositions.contains(constraintPosition)) {
// if systemWithoutExpectedTypeConstraint has unknown type parameters, it's not successful, // e.g. if systemWithoutConstraintsFromPosition has unknown type parameters, it's not successful
// but there can be expected type mismatch after expected type is added
return true; return true;
} }
return false; return false;
@@ -79,9 +79,10 @@ public interface ConstraintSystemStatus {
boolean hasTypeConstructorMismatchAt(@NotNull ConstraintPosition constraintPosition); boolean hasTypeConstructorMismatchAt(@NotNull ConstraintPosition constraintPosition);
/** /**
* Returns <tt>true</tt> if there is type constructor mismatch only in {@link ConstraintPosition.EXPECTED_TYPE_POSITION}. * Returns <tt>true</tt> if there is type constructor mismatch only in constraintPosition or
* constraint system is successful without constraints from this position.
*/ */
boolean hasOnlyExpectedTypeMismatch(); boolean hasOnlyErrorsFromPosition(ConstraintPosition constraintPosition);
/** /**
* Returns <tt>true</tt> if there is an error in constraining types. <p/> * Returns <tt>true</tt> if there is an error in constraining types. <p/>