added class ExtendedInferenceErrorData
(to avoid @Nullable fields)
This commit is contained in:
@@ -39,6 +39,7 @@ import java.util.List;
|
||||
import static org.jetbrains.jet.lang.diagnostics.PositioningStrategies.*;
|
||||
import static org.jetbrains.jet.lang.diagnostics.Severity.ERROR;
|
||||
import static org.jetbrains.jet.lang.diagnostics.Severity.WARNING;
|
||||
import static org.jetbrains.jet.lang.resolve.calls.inference.InferenceErrorData.ExtendedInferenceErrorData;
|
||||
|
||||
/**
|
||||
* For error messages, see DefaultErrorMessages and IdeErrorMessages.
|
||||
@@ -357,9 +358,9 @@ public interface Errors {
|
||||
|
||||
SimpleDiagnosticFactory<PsiElement> CREATING_AN_INSTANCE_OF_ABSTRACT_CLASS = SimpleDiagnosticFactory.create(ERROR);
|
||||
|
||||
DiagnosticFactory1<PsiElement, InferenceErrorData> TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER = DiagnosticFactory1.create(ERROR);
|
||||
DiagnosticFactory1<PsiElement, InferenceErrorData> TYPE_INFERENCE_CONFLICTING_SUBSTITUTIONS = DiagnosticFactory1.create(ERROR);
|
||||
DiagnosticFactory1<PsiElement, InferenceErrorData> TYPE_INFERENCE_TYPE_CONSTRUCTOR_MISMATCH = DiagnosticFactory1.create(ERROR);
|
||||
DiagnosticFactory1<PsiElement, ExtendedInferenceErrorData> TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER = DiagnosticFactory1.create(ERROR);
|
||||
DiagnosticFactory1<PsiElement, ExtendedInferenceErrorData> TYPE_INFERENCE_CONFLICTING_SUBSTITUTIONS = DiagnosticFactory1.create(ERROR);
|
||||
DiagnosticFactory1<PsiElement, ExtendedInferenceErrorData> TYPE_INFERENCE_TYPE_CONSTRUCTOR_MISMATCH = DiagnosticFactory1.create(ERROR);
|
||||
DiagnosticFactory1<PsiElement, InferenceErrorData> TYPE_INFERENCE_UPPER_BOUND_VIOLATED = DiagnosticFactory1.create(ERROR);
|
||||
DiagnosticFactory2<PsiElement, JetType, JetType> TYPE_INFERENCE_EXPECTED_TYPE_MISMATCH = DiagnosticFactory2.create(ERROR);
|
||||
Collection<AbstractDiagnosticFactory> TYPE_INFERENCE_ERRORS = Lists.<AbstractDiagnosticFactory>newArrayList(TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER,
|
||||
|
||||
@@ -37,6 +37,7 @@ import org.jetbrains.jet.lang.types.checker.JetTypeChecker;
|
||||
import org.jetbrains.jet.resolve.DescriptorRenderer;
|
||||
|
||||
import static org.jetbrains.jet.lang.diagnostics.rendering.TabledDescriptorRenderer.*;
|
||||
import static org.jetbrains.jet.lang.resolve.calls.inference.InferenceErrorData.ExtendedInferenceErrorData;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
@@ -130,29 +131,29 @@ public class Renderers {
|
||||
};
|
||||
}
|
||||
|
||||
public static final Renderer<InferenceErrorData> TYPE_INFERENCE_CONFLICTING_SUBSTITUTIONS_RENDERER =
|
||||
new Renderer<InferenceErrorData>() {
|
||||
public static final Renderer<ExtendedInferenceErrorData> TYPE_INFERENCE_CONFLICTING_SUBSTITUTIONS_RENDERER =
|
||||
new Renderer<ExtendedInferenceErrorData>() {
|
||||
@NotNull
|
||||
@Override
|
||||
public String render(@NotNull InferenceErrorData inferenceErrorData) {
|
||||
public String render(@NotNull ExtendedInferenceErrorData inferenceErrorData) {
|
||||
return renderConflictingSubstitutionsInferenceError(inferenceErrorData, TabledDescriptorRenderer.create()).toString();
|
||||
}
|
||||
};
|
||||
|
||||
public static final Renderer<InferenceErrorData> TYPE_INFERENCE_TYPE_CONSTRUCTOR_MISMATCH_RENDERER =
|
||||
new Renderer<InferenceErrorData>() {
|
||||
public static final Renderer<ExtendedInferenceErrorData> TYPE_INFERENCE_TYPE_CONSTRUCTOR_MISMATCH_RENDERER =
|
||||
new Renderer<ExtendedInferenceErrorData>() {
|
||||
@NotNull
|
||||
@Override
|
||||
public String render(@NotNull InferenceErrorData inferenceErrorData) {
|
||||
public String render(@NotNull ExtendedInferenceErrorData inferenceErrorData) {
|
||||
return renderTypeConstructorMismatchError(inferenceErrorData, TabledDescriptorRenderer.create()).toString();
|
||||
}
|
||||
};
|
||||
|
||||
public static final Renderer<InferenceErrorData> TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER_RENDERER =
|
||||
new Renderer<InferenceErrorData>() {
|
||||
public static final Renderer<ExtendedInferenceErrorData> TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER_RENDERER =
|
||||
new Renderer<ExtendedInferenceErrorData>() {
|
||||
@NotNull
|
||||
@Override
|
||||
public String render(@NotNull InferenceErrorData inferenceErrorData) {
|
||||
public String render(@NotNull ExtendedInferenceErrorData inferenceErrorData) {
|
||||
return renderNoInformationForParameterError(inferenceErrorData, TabledDescriptorRenderer.create()).toString();
|
||||
}
|
||||
};
|
||||
@@ -166,7 +167,7 @@ public class Renderers {
|
||||
}
|
||||
};
|
||||
|
||||
public static TabledDescriptorRenderer renderConflictingSubstitutionsInferenceError(InferenceErrorData inferenceErrorData,
|
||||
public static TabledDescriptorRenderer renderConflictingSubstitutionsInferenceError(ExtendedInferenceErrorData inferenceErrorData,
|
||||
TabledDescriptorRenderer result) {
|
||||
assert inferenceErrorData.constraintSystem.hasConflictingConstraints();
|
||||
|
||||
@@ -224,7 +225,7 @@ public class Renderers {
|
||||
return result;
|
||||
}
|
||||
|
||||
public static TabledDescriptorRenderer renderTypeConstructorMismatchError(final InferenceErrorData inferenceErrorData,
|
||||
public static TabledDescriptorRenderer renderTypeConstructorMismatchError(final ExtendedInferenceErrorData inferenceErrorData,
|
||||
TabledDescriptorRenderer renderer) {
|
||||
Predicate<ConstraintPosition> isErrorPosition = new Predicate<ConstraintPosition>() {
|
||||
@Override
|
||||
@@ -242,7 +243,7 @@ public class Renderers {
|
||||
isErrorPosition));
|
||||
}
|
||||
|
||||
public static TabledDescriptorRenderer renderNoInformationForParameterError(InferenceErrorData inferenceErrorData,
|
||||
public static TabledDescriptorRenderer renderNoInformationForParameterError(ExtendedInferenceErrorData inferenceErrorData,
|
||||
TabledDescriptorRenderer renderer) {
|
||||
TypeParameterDescriptor firstUnknownParameter = null;
|
||||
for (TypeParameterDescriptor typeParameter : inferenceErrorData.constraintSystem.getTypeVariables()) {
|
||||
|
||||
@@ -52,6 +52,7 @@ import static org.jetbrains.jet.lang.resolve.BindingContext.*;
|
||||
import static org.jetbrains.jet.lang.resolve.calls.ResolutionStatus.*;
|
||||
import static org.jetbrains.jet.lang.resolve.calls.ResolvedCallImpl.MAP_TO_CANDIDATE;
|
||||
import static org.jetbrains.jet.lang.resolve.calls.ResolvedCallImpl.MAP_TO_RESULT;
|
||||
import static org.jetbrains.jet.lang.resolve.calls.inference.InferenceErrorData.ExtendedInferenceErrorData;
|
||||
import static org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor.NO_RECEIVER;
|
||||
import static org.jetbrains.jet.lang.types.TypeUtils.NO_EXPECTED_TYPE;
|
||||
|
||||
@@ -779,7 +780,7 @@ public class CallResolver {
|
||||
ResolutionStatus argumentsStatus = checkingResult.status;
|
||||
List<JetType> argumentTypes = checkingResult.argumentTypes;
|
||||
JetType receiverType = candidateCall.getReceiverArgument().exists() ? candidateCall.getReceiverArgument().getType() : null;
|
||||
InferenceErrorData inferenceErrorData = InferenceErrorData
|
||||
ExtendedInferenceErrorData inferenceErrorData = InferenceErrorData
|
||||
.create(candidate, constraintSystemWithRightTypeParameters, argumentTypes, receiverType, context.expectedType);
|
||||
if (hasContradiction) {
|
||||
context.tracing.typeInferenceFailed(candidateCall.getTrace(), inferenceErrorData, constraintSystemWithRightTypeParameters);
|
||||
|
||||
@@ -238,7 +238,7 @@ public class ResolutionTask<D extends CallableDescriptor, F extends D> extends R
|
||||
}
|
||||
|
||||
@Override
|
||||
public void typeInferenceFailed(@NotNull BindingTrace trace, @NotNull InferenceErrorData data, @NotNull ConstraintSystem systemWithoutExpectedTypeConstraint) {
|
||||
public void typeInferenceFailed(@NotNull BindingTrace trace, @NotNull InferenceErrorData.ExtendedInferenceErrorData data, @NotNull ConstraintSystem systemWithoutExpectedTypeConstraint) {
|
||||
ConstraintSystem constraintSystem = data.constraintSystem;
|
||||
assert !constraintSystem.isSuccessful();
|
||||
if (constraintSystem.hasErrorInConstrainingTypes()) {
|
||||
@@ -252,6 +252,7 @@ public class ResolutionTask<D extends CallableDescriptor, F extends D> extends R
|
||||
returnType = systemWithoutExpectedTypeConstraint.getResultingSubstitutor().substitute(returnType, Variance.INVARIANT);
|
||||
assert returnType != null;
|
||||
}
|
||||
assert data.expectedType != null;
|
||||
trace.report(TYPE_INFERENCE_EXPECTED_TYPE_MISMATCH.on(reference, returnType, data.expectedType));
|
||||
}
|
||||
else if (constraintSystem.hasTypeConstructorMismatch()) {
|
||||
|
||||
@@ -30,6 +30,8 @@ import org.jetbrains.jet.lang.types.JetType;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import static org.jetbrains.jet.lang.resolve.calls.inference.InferenceErrorData.ExtendedInferenceErrorData;
|
||||
|
||||
/**
|
||||
* @author abreslav
|
||||
*/
|
||||
@@ -85,7 +87,7 @@ import java.util.List;
|
||||
public void invisibleMember(@NotNull BindingTrace trace, @NotNull DeclarationDescriptorWithVisibility descriptor) {}
|
||||
|
||||
@Override
|
||||
public void typeInferenceFailed(@NotNull BindingTrace trace, @NotNull InferenceErrorData inferenceErrorData,
|
||||
public void typeInferenceFailed(@NotNull BindingTrace trace, @NotNull ExtendedInferenceErrorData inferenceErrorData,
|
||||
@NotNull ConstraintSystem systemWithoutExpectedTypeConstraint) {}
|
||||
|
||||
@Override
|
||||
@@ -124,7 +126,7 @@ import java.util.List;
|
||||
|
||||
void invisibleMember(@NotNull BindingTrace trace, @NotNull DeclarationDescriptorWithVisibility descriptor);
|
||||
|
||||
void typeInferenceFailed(@NotNull BindingTrace trace, @NotNull InferenceErrorData inferenceErrorData,
|
||||
void typeInferenceFailed(@NotNull BindingTrace trace, @NotNull ExtendedInferenceErrorData inferenceErrorData,
|
||||
@NotNull ConstraintSystem systemWithoutExpectedTypeConstraint);
|
||||
|
||||
void upperBoundViolated(@NotNull BindingTrace trace, @NotNull InferenceErrorData inferenceErrorData);
|
||||
|
||||
+22
-12
@@ -30,26 +30,36 @@ import java.util.List;
|
||||
public class InferenceErrorData {
|
||||
public final CallableDescriptor descriptor;
|
||||
public final ConstraintSystem constraintSystem;
|
||||
public final JetType receiverArgumentType;
|
||||
public final JetType expectedType;
|
||||
public final List<JetType> valueArgumentsTypes;
|
||||
|
||||
private InferenceErrorData(@NotNull CallableDescriptor descriptor, @NotNull ConstraintSystem constraintSystem,
|
||||
@Nullable List<JetType> valueArgumentsTypes, @Nullable JetType receiverArgumentType, @Nullable JetType expectedType) {
|
||||
private InferenceErrorData(@NotNull CallableDescriptor descriptor, @NotNull ConstraintSystem constraintSystem) {
|
||||
this.descriptor = descriptor;
|
||||
this.constraintSystem = constraintSystem;
|
||||
this.receiverArgumentType = receiverArgumentType;
|
||||
this.valueArgumentsTypes = valueArgumentsTypes;
|
||||
this.expectedType = expectedType;
|
||||
}
|
||||
|
||||
public static InferenceErrorData create(@NotNull CallableDescriptor descriptor, @NotNull ConstraintSystem constraintSystem,
|
||||
public static class ExtendedInferenceErrorData extends InferenceErrorData {
|
||||
public final JetType receiverArgumentType;
|
||||
public final JetType expectedType;
|
||||
|
||||
public final List<JetType> valueArgumentsTypes;
|
||||
|
||||
private ExtendedInferenceErrorData(
|
||||
@NotNull CallableDescriptor descriptor, @NotNull ConstraintSystem constraintSystem,
|
||||
@NotNull List<JetType> valueArgumentsTypes, @Nullable JetType receiverArgumentType, @Nullable JetType expectedType
|
||||
) {
|
||||
super(descriptor, constraintSystem);
|
||||
this.receiverArgumentType = receiverArgumentType;
|
||||
this.valueArgumentsTypes = valueArgumentsTypes;
|
||||
this.expectedType = expectedType;
|
||||
}
|
||||
}
|
||||
|
||||
public static ExtendedInferenceErrorData create(@NotNull CallableDescriptor descriptor, @NotNull ConstraintSystem constraintSystem,
|
||||
@NotNull List<JetType> valueArgumentsTypes, @Nullable JetType receiverArgumentType, @Nullable JetType expectedType) {
|
||||
return new InferenceErrorData(descriptor, constraintSystem, valueArgumentsTypes, receiverArgumentType,
|
||||
return new ExtendedInferenceErrorData(descriptor, constraintSystem, valueArgumentsTypes, receiverArgumentType,
|
||||
expectedType != TypeUtils.NO_EXPECTED_TYPE ? expectedType : null);
|
||||
}
|
||||
|
||||
public static InferenceErrorData create(@NotNull CallableDescriptor descriptor, @NotNull ConstraintSystem constraintSystem) {
|
||||
return new InferenceErrorData(descriptor, constraintSystem, null, null, null);
|
||||
return new InferenceErrorData(descriptor, constraintSystem);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -46,6 +46,7 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.jetbrains.jet.lang.diagnostics.rendering.Renderers.*;
|
||||
import static org.jetbrains.jet.lang.resolve.calls.inference.InferenceErrorData.ExtendedInferenceErrorData;
|
||||
|
||||
/**
|
||||
* @author svtk
|
||||
@@ -178,29 +179,29 @@ public class IdeRenderers {
|
||||
}
|
||||
}
|
||||
|
||||
public static final Renderer<InferenceErrorData> HTML_TYPE_INFERENCE_CONFLICTING_SUBSTITUTIONS_RENDERER =
|
||||
new Renderer<InferenceErrorData>() {
|
||||
public static final Renderer<ExtendedInferenceErrorData> HTML_TYPE_INFERENCE_CONFLICTING_SUBSTITUTIONS_RENDERER =
|
||||
new Renderer<ExtendedInferenceErrorData>() {
|
||||
@NotNull
|
||||
@Override
|
||||
public String render(@NotNull InferenceErrorData inferenceErrorData) {
|
||||
public String render(@NotNull ExtendedInferenceErrorData inferenceErrorData) {
|
||||
return renderConflictingSubstitutionsInferenceError(inferenceErrorData, HtmlTabledDescriptorRenderer.create()).toString();
|
||||
}
|
||||
};
|
||||
|
||||
public static final Renderer<InferenceErrorData> HTML_TYPE_INFERENCE_TYPE_CONSTRUCTOR_MISMATCH_RENDERER =
|
||||
new Renderer<InferenceErrorData>() {
|
||||
public static final Renderer<ExtendedInferenceErrorData> HTML_TYPE_INFERENCE_TYPE_CONSTRUCTOR_MISMATCH_RENDERER =
|
||||
new Renderer<ExtendedInferenceErrorData>() {
|
||||
@NotNull
|
||||
@Override
|
||||
public String render(@NotNull InferenceErrorData inferenceErrorData) {
|
||||
public String render(@NotNull ExtendedInferenceErrorData inferenceErrorData) {
|
||||
return renderTypeConstructorMismatchError(inferenceErrorData, HtmlTabledDescriptorRenderer.create()).toString();
|
||||
}
|
||||
};
|
||||
|
||||
public static final Renderer<InferenceErrorData> HTML_TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER_RENDERER =
|
||||
new Renderer<InferenceErrorData>() {
|
||||
public static final Renderer<ExtendedInferenceErrorData> HTML_TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER_RENDERER =
|
||||
new Renderer<ExtendedInferenceErrorData>() {
|
||||
@NotNull
|
||||
@Override
|
||||
public String render(@NotNull InferenceErrorData inferenceErrorData) {
|
||||
public String render(@NotNull ExtendedInferenceErrorData inferenceErrorData) {
|
||||
return renderNoInformationForParameterError(inferenceErrorData, HtmlTabledDescriptorRenderer.create()).toString();
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user