rename
This commit is contained in:
@@ -170,17 +170,17 @@ public class Renderers {
|
||||
|
||||
public static TabledDescriptorRenderer renderConflictingSubstitutionsInferenceError(InferenceErrorData inferenceErrorData,
|
||||
TabledDescriptorRenderer result) {
|
||||
assert inferenceErrorData.constraintsSystem.hasConflictingConstraints();
|
||||
assert inferenceErrorData.constraintSystem.hasConflictingConstraints();
|
||||
|
||||
Collection<CallableDescriptor> substitutedDescriptors = Lists.newArrayList();
|
||||
Collection<TypeSubstitutor> substitutors = ConstraintsUtil.getSubstitutorsForConflictingParameters(
|
||||
inferenceErrorData.constraintsSystem);
|
||||
inferenceErrorData.constraintSystem);
|
||||
for (TypeSubstitutor substitutor : substitutors) {
|
||||
CallableDescriptor substitutedDescriptor = inferenceErrorData.descriptor.substitute(substitutor);
|
||||
substitutedDescriptors.add(substitutedDescriptor);
|
||||
}
|
||||
|
||||
TypeParameterDescriptor firstConflictingParameter = ConstraintsUtil.getFirstConflictingParameter(inferenceErrorData.constraintsSystem);
|
||||
TypeParameterDescriptor firstConflictingParameter = ConstraintsUtil.getFirstConflictingParameter(inferenceErrorData.constraintSystem);
|
||||
assert firstConflictingParameter != null;
|
||||
|
||||
result.text(newText()
|
||||
@@ -232,7 +232,7 @@ public class Renderers {
|
||||
@Override
|
||||
public boolean apply(@Nullable ConstraintPosition constraintPosition) {
|
||||
assert constraintPosition != null;
|
||||
return inferenceErrorData.constraintsSystem.hasTypeConstructorMismatchAt(constraintPosition);
|
||||
return inferenceErrorData.constraintSystem.hasTypeConstructorMismatchAt(constraintPosition);
|
||||
}
|
||||
};
|
||||
return renderer.table(TabledDescriptorRenderer.newTable()
|
||||
@@ -247,8 +247,8 @@ public class Renderers {
|
||||
public static TabledDescriptorRenderer renderNoInformationForParameterError(InferenceErrorData inferenceErrorData,
|
||||
TabledDescriptorRenderer renderer) {
|
||||
TypeParameterDescriptor firstUnknownParameter = null;
|
||||
for (TypeParameterDescriptor typeParameter : inferenceErrorData.constraintsSystem.getTypeVariables()) {
|
||||
if (inferenceErrorData.constraintsSystem.getTypeConstraints(typeParameter).isEmpty()) {
|
||||
for (TypeParameterDescriptor typeParameter : inferenceErrorData.constraintSystem.getTypeVariables()) {
|
||||
if (inferenceErrorData.constraintSystem.getTypeConstraints(typeParameter).isEmpty()) {
|
||||
firstUnknownParameter = typeParameter;
|
||||
break;
|
||||
}
|
||||
@@ -267,7 +267,7 @@ public class Renderers {
|
||||
public static TabledDescriptorRenderer renderUpperBoundViolatedInferenceError(InferenceErrorData inferenceErrorData, TabledDescriptorRenderer result) {
|
||||
TypeParameterDescriptor typeParameterDescriptor = null;
|
||||
for (TypeParameterDescriptor typeParameter : inferenceErrorData.descriptor.getTypeParameters()) {
|
||||
if (!ConstraintsUtil.checkUpperBoundIsSatisfied(inferenceErrorData.constraintsSystem, typeParameter)) {
|
||||
if (!ConstraintsUtil.checkUpperBoundIsSatisfied(inferenceErrorData.constraintSystem, typeParameter)) {
|
||||
typeParameterDescriptor = typeParameter;
|
||||
break;
|
||||
}
|
||||
@@ -278,9 +278,9 @@ public class Renderers {
|
||||
.table(newTable().
|
||||
descriptor(inferenceErrorData.descriptor));
|
||||
|
||||
JetType type = ConstraintsUtil.getValue(inferenceErrorData.constraintsSystem.getTypeConstraints(typeParameterDescriptor));
|
||||
JetType type = ConstraintsUtil.getValue(inferenceErrorData.constraintSystem.getTypeConstraints(typeParameterDescriptor));
|
||||
JetType upperBound = typeParameterDescriptor.getUpperBoundsAsType();
|
||||
JetType substitute = inferenceErrorData.constraintsSystem.getResultingSubstitutor().substitute(upperBound, Variance.INVARIANT);
|
||||
JetType substitute = inferenceErrorData.constraintSystem.getResultingSubstitutor().substitute(upperBound, Variance.INVARIANT);
|
||||
|
||||
result.text(newText()
|
||||
.normal(" is not satisfied: inferred type ")
|
||||
|
||||
@@ -340,10 +340,10 @@ public class CallResolver {
|
||||
) {
|
||||
assert resolvedCall.hasUnknownTypeParameters();
|
||||
D descriptor = resolvedCall.getCandidateDescriptor();
|
||||
ConstraintsSystem constraintsSystem = resolvedCall.getConstraintsSystem();
|
||||
assert constraintsSystem != null;
|
||||
ConstraintSystem constraintSystem = resolvedCall.getConstraintSystem();
|
||||
assert constraintSystem != null;
|
||||
|
||||
constraintsSystem.addSubtypingConstraint(descriptor.getReturnType(), context.expectedType,
|
||||
constraintSystem.addSubtypingConstraint(descriptor.getReturnType(), context.expectedType,
|
||||
ConstraintPosition.EXPECTED_TYPE_POSITION);
|
||||
|
||||
// constraints for function literals
|
||||
@@ -355,23 +355,23 @@ public class CallResolver {
|
||||
for (ValueArgument valueArgument : resolvedValueArgument.getArguments()) {
|
||||
if (!JetPsiUtil.isFunctionLiteralWithoutDeclaredParameterTypes(valueArgument.getArgumentExpression())) continue;
|
||||
|
||||
addConstraintForValueArgument(valueArgument, valueParameterDescriptor, constraintsSystem.getCurrentSubstitutor(),
|
||||
constraintsSystem, context);
|
||||
addConstraintForValueArgument(valueArgument, valueParameterDescriptor, constraintSystem.getCurrentSubstitutor(),
|
||||
constraintSystem, context);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!constraintsSystem.isSuccessful()) {
|
||||
if (!constraintSystem.isSuccessful()) {
|
||||
List<JetType> argumentTypes = checkValueArgumentTypes(context, resolvedCall, context.trace).argumentTypes;
|
||||
JetType receiverType = resolvedCall.getReceiverArgument().exists() ? resolvedCall.getReceiverArgument().getType() : null;
|
||||
tracing.typeInferenceFailed(context.trace,
|
||||
InferenceErrorData.create(descriptor, constraintsSystem, argumentTypes, receiverType, context.expectedType));
|
||||
InferenceErrorData.create(descriptor, constraintSystem, argumentTypes, receiverType, context.expectedType));
|
||||
resolvedCall.addStatus(ResolutionStatus.TYPE_INFERENCE_ERROR);
|
||||
failed.add(resolvedCall);
|
||||
return;
|
||||
}
|
||||
|
||||
D substitute = (D) descriptor.substitute(constraintsSystem.getResultingSubstitutor());
|
||||
D substitute = (D) descriptor.substitute(constraintSystem.getResultingSubstitutor());
|
||||
assert substitute != null;
|
||||
replaceValueParametersWithSubstitutedOnes(resolvedCall, substitute);
|
||||
resolvedCall.setResultingDescriptor(substitute); //replacement
|
||||
@@ -379,7 +379,7 @@ public class CallResolver {
|
||||
// Here we type check the arguments with inferred types expected
|
||||
checkValueArgumentTypes(context, resolvedCall, context.trace);
|
||||
|
||||
checkBounds(resolvedCall, constraintsSystem, context.trace, tracing);
|
||||
checkBounds(resolvedCall, constraintSystem, context.trace, tracing);
|
||||
resolvedCall.setHasUnknownTypeParameters(false);
|
||||
if (resolvedCall.getStatus().isSuccess() || resolvedCall.getStatus() == ResolutionStatus.UNKNOWN_STATUS) {
|
||||
resolvedCall.addStatus(ResolutionStatus.SUCCESS);
|
||||
@@ -392,13 +392,13 @@ public class CallResolver {
|
||||
|
||||
private <D extends CallableDescriptor> void checkBounds(
|
||||
@NotNull ResolvedCallImpl<D> call,
|
||||
@NotNull ConstraintsSystem constraintsSystem,
|
||||
@NotNull ConstraintSystem constraintSystem,
|
||||
@NotNull BindingTrace trace,
|
||||
@NotNull TracingStrategy tracing
|
||||
) {
|
||||
for (TypeParameterDescriptor typeParameter : call.getCandidateDescriptor().getTypeParameters()) {
|
||||
if (!ConstraintsUtil.checkUpperBoundIsSatisfied(constraintsSystem, typeParameter)) {
|
||||
tracing.upperBoundViolated(trace, InferenceErrorData.create(call.getCandidateDescriptor(), constraintsSystem));
|
||||
if (!ConstraintsUtil.checkUpperBoundIsSatisfied(constraintSystem, typeParameter)) {
|
||||
tracing.upperBoundViolated(trace, InferenceErrorData.create(call.getCandidateDescriptor(), constraintSystem));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -693,7 +693,7 @@ public class CallResolver {
|
||||
|
||||
ResolutionDebugInfo.Data debugInfo = context.trace.get(ResolutionDebugInfo.RESOLUTION_DEBUG_INFO, context.call.getCallElement());
|
||||
|
||||
ConstraintsSystemImpl constraintsSystem = new ConstraintsSystemImpl();
|
||||
ConstraintSystemImpl constraintsSystem = new ConstraintSystemImpl();
|
||||
|
||||
// If the call is recursive, e.g.
|
||||
// fun foo<T>(t : T) : T = foo(t)
|
||||
@@ -709,7 +709,7 @@ public class CallResolver {
|
||||
}
|
||||
|
||||
TypeSubstitutor substituteDontCare = ConstraintSystemWithPriorities
|
||||
.makeConstantSubstitutor(candidateWithFreshVariables.getTypeParameters(), ConstraintsSystemImpl.DONT_CARE);
|
||||
.makeConstantSubstitutor(candidateWithFreshVariables.getTypeParameters(), ConstraintSystemImpl.DONT_CARE);
|
||||
|
||||
// Value parameters
|
||||
for (Map.Entry<ValueParameterDescriptor, ResolvedValueArgument> entry : candidateCall.getValueArguments().entrySet()) {
|
||||
@@ -746,8 +746,8 @@ public class CallResolver {
|
||||
typeVariablesMap.put(candidateWithFreshVariables.getTypeParameters().get(typeParameterDescriptor.getIndex()),
|
||||
typeParameterDescriptor);
|
||||
}
|
||||
ConstraintsSystem constraintsBuilderWithRightTypeParameters = constraintsSystem.replaceTypeVariables(typeVariablesMap);
|
||||
candidateCall.setConstraintsSystem(constraintsBuilderWithRightTypeParameters);
|
||||
ConstraintSystem constraintBuilderWithRightTypeParameters = constraintsSystem.replaceTypeVariables(typeVariablesMap);
|
||||
candidateCall.setConstraintSystem(constraintBuilderWithRightTypeParameters);
|
||||
|
||||
|
||||
// Solution
|
||||
@@ -761,7 +761,7 @@ public class CallResolver {
|
||||
List<JetType> argumentTypes = checkingResult.argumentTypes;
|
||||
JetType receiverType = candidateCall.getReceiverArgument().exists() ? candidateCall.getReceiverArgument().getType() : null;
|
||||
context.tracing.typeInferenceFailed(context.trace,
|
||||
InferenceErrorData.create(candidate, constraintsBuilderWithRightTypeParameters, argumentTypes, receiverType, context.expectedType));
|
||||
InferenceErrorData.create(candidate, constraintBuilderWithRightTypeParameters, argumentTypes, receiverType, context.expectedType));
|
||||
return TYPE_INFERENCE_ERROR.combine(argumentsStatus);
|
||||
}
|
||||
}
|
||||
@@ -769,7 +769,7 @@ public class CallResolver {
|
||||
private boolean addConstraintForValueArgument(ValueArgument valueArgument,
|
||||
@NotNull ValueParameterDescriptor valueParameterDescriptor,
|
||||
@NotNull TypeSubstitutor substitutor,
|
||||
@NotNull ConstraintsSystem constraintsSystem,
|
||||
@NotNull ConstraintSystem constraintSystem,
|
||||
@NotNull ResolutionContext context) {
|
||||
|
||||
JetType effectiveExpectedType = getEffectiveExpectedType(valueParameterDescriptor, valueArgument);
|
||||
@@ -778,7 +778,7 @@ public class CallResolver {
|
||||
JetType type = argumentExpression != null ? expressionTypingServices.getType(
|
||||
context.scope, argumentExpression, substitutor.substitute(valueParameterDescriptor.getType(), Variance.INVARIANT),
|
||||
context.dataFlowInfo, traceForUnknown) : null;
|
||||
constraintsSystem.addSupertypeConstraint(effectiveExpectedType, type, ConstraintPosition.getValueParameterPosition(
|
||||
constraintSystem.addSupertypeConstraint(effectiveExpectedType, type, ConstraintPosition.getValueParameterPosition(
|
||||
valueParameterDescriptor.getIndex()));
|
||||
//todo no return
|
||||
if (type == null || ErrorUtils.isErrorType(type)) return false;
|
||||
@@ -977,7 +977,7 @@ public class CallResolver {
|
||||
if (argument.getSpreadElement() != null) {
|
||||
if (parameterDescriptor.getVarargElementType() == null) {
|
||||
// Spread argument passed to a non-vararg parameter, an error is already reported by ValueArgumentsToParametersMapper
|
||||
return ConstraintsSystemImpl.DONT_CARE;
|
||||
return ConstraintSystemImpl.DONT_CARE;
|
||||
}
|
||||
else {
|
||||
return parameterDescriptor.getType();
|
||||
|
||||
@@ -27,8 +27,7 @@ import org.jetbrains.jet.lang.diagnostics.Errors;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.BindingTrace;
|
||||
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.ConstraintsSystem;
|
||||
import org.jetbrains.jet.lang.resolve.calls.inference.ConstraintSystem;
|
||||
import org.jetbrains.jet.lang.resolve.calls.inference.InferenceErrorData;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
@@ -236,24 +235,24 @@ public class ResolutionTask<D extends CallableDescriptor, F extends D> extends R
|
||||
|
||||
@Override
|
||||
public void typeInferenceFailed(@NotNull BindingTrace trace, @NotNull InferenceErrorData data) {
|
||||
ConstraintsSystem constraintsSystem = data.constraintsSystem;
|
||||
assert !constraintsSystem.isSuccessful();
|
||||
if (constraintsSystem.hasErrorInConstrainingTypes()) {
|
||||
ConstraintSystem constraintSystem = data.constraintSystem;
|
||||
assert !constraintSystem.isSuccessful();
|
||||
if (constraintSystem.hasErrorInConstrainingTypes()) {
|
||||
return;
|
||||
}
|
||||
if (constraintsSystem.hasExpectedTypeMismatch()) {
|
||||
if (constraintSystem.hasExpectedTypeMismatch()) {
|
||||
JetType returnType = data.descriptor.getReturnType();
|
||||
assert returnType != null;
|
||||
trace.report(TYPE_INFERENCE_EXPECTED_TYPE_MISMATCH.on(reference, returnType, data.expectedType));
|
||||
}
|
||||
else if (constraintsSystem.hasTypeConstructorMismatch()) {
|
||||
else if (constraintSystem.hasTypeConstructorMismatch()) {
|
||||
trace.report(TYPE_INFERENCE_TYPE_CONSTRUCTOR_MISMATCH.on(reference, data));
|
||||
}
|
||||
else if (constraintsSystem.hasConflictingConstraints()) {
|
||||
else if (constraintSystem.hasConflictingConstraints()) {
|
||||
trace.report(TYPE_INFERENCE_CONFLICTING_SUBSTITUTIONS.on(reference, data));
|
||||
}
|
||||
else {
|
||||
assert constraintsSystem.hasUnknownParameters();
|
||||
assert constraintSystem.hasUnknownParameters();
|
||||
trace.report(TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER.on(reference, data));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ import org.jetbrains.jet.lang.descriptors.CallableDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.TemporaryBindingTrace;
|
||||
import org.jetbrains.jet.lang.resolve.calls.inference.ConstraintsSystem;
|
||||
import org.jetbrains.jet.lang.resolve.calls.inference.ConstraintSystem;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
|
||||
@@ -72,7 +72,7 @@ public class ResolvedCallImpl<D extends CallableDescriptor> implements ResolvedC
|
||||
private TemporaryBindingTrace trace;
|
||||
private ResolutionStatus status = UNKNOWN_STATUS;
|
||||
private boolean hasUnknownTypeParameters = false;
|
||||
private ConstraintsSystem constraintsSystem = null;
|
||||
private ConstraintSystem constraintSystem = null;
|
||||
|
||||
private ResolvedCallImpl(@NotNull ResolutionCandidate<D> candidate, @NotNull TemporaryBindingTrace trace) {
|
||||
this.candidateDescriptor = candidate.getDescriptor();
|
||||
@@ -130,13 +130,13 @@ public class ResolvedCallImpl<D extends CallableDescriptor> implements ResolvedC
|
||||
typeArguments.put(typeParameter, typeArgument);
|
||||
}
|
||||
|
||||
public void setConstraintsSystem(@NotNull ConstraintsSystem constraintsSystem) {
|
||||
this.constraintsSystem = constraintsSystem;
|
||||
public void setConstraintSystem(@NotNull ConstraintSystem constraintSystem) {
|
||||
this.constraintSystem = constraintSystem;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public ConstraintsSystem getConstraintsSystem() {
|
||||
return constraintsSystem;
|
||||
public ConstraintSystem getConstraintSystem() {
|
||||
return constraintSystem;
|
||||
}
|
||||
|
||||
public void recordValueArgument(@NotNull ValueParameterDescriptor valueParameter, @NotNull ResolvedValueArgument valueArgument) {
|
||||
|
||||
+1
-1
@@ -28,7 +28,7 @@ import java.util.Set;
|
||||
/**
|
||||
* @author svtk
|
||||
*/
|
||||
public interface ConstraintsSystem {
|
||||
public interface ConstraintSystem {
|
||||
|
||||
/**
|
||||
* Registers a variable in a constraint system.
|
||||
+4
-4
@@ -32,7 +32,7 @@ import java.util.*;
|
||||
/**
|
||||
* @author svtk
|
||||
*/
|
||||
public class ConstraintsSystemImpl implements ConstraintsSystem {
|
||||
public class ConstraintSystemImpl implements ConstraintSystem {
|
||||
|
||||
public static final JetType DONT_CARE = ErrorUtils.createErrorTypeWithCustomDebugName("DONT_CARE");
|
||||
|
||||
@@ -42,7 +42,7 @@ public class ConstraintsSystemImpl implements ConstraintsSystem {
|
||||
private final TypeSubstitutor currentSubstitutor;
|
||||
private boolean hasErrorInConstrainingTypes;
|
||||
|
||||
public ConstraintsSystemImpl() {
|
||||
public ConstraintSystemImpl() {
|
||||
this.resultingSubstitutor = createTypeSubstitutorWithDefaultForUnknownTypeParameter(null);
|
||||
this.currentSubstitutor = createTypeSubstitutorWithDefaultForUnknownTypeParameter(new TypeProjection(DONT_CARE));
|
||||
}
|
||||
@@ -105,8 +105,8 @@ public class ConstraintsSystemImpl implements ConstraintsSystem {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ConstraintsSystemImpl replaceTypeVariables(@NotNull Map<TypeParameterDescriptor, TypeParameterDescriptor> typeVariablesMap) {
|
||||
ConstraintsSystemImpl newConstraintSystem = new ConstraintsSystemImpl();
|
||||
public ConstraintSystemImpl replaceTypeVariables(@NotNull Map<TypeParameterDescriptor, TypeParameterDescriptor> typeVariablesMap) {
|
||||
ConstraintSystemImpl newConstraintSystem = new ConstraintSystemImpl();
|
||||
for (Map.Entry<TypeParameterDescriptor, TypeConstraintsImpl> entry : typeParameterConstraints.entrySet()) {
|
||||
TypeParameterDescriptor typeParameter = entry.getKey();
|
||||
TypeConstraintsImpl typeConstraints = entry.getValue();
|
||||
+17
-17
@@ -84,9 +84,9 @@ public class ConstraintsUtil {
|
||||
|
||||
|
||||
@Nullable
|
||||
public static TypeParameterDescriptor getFirstConflictingParameter(@NotNull ConstraintsSystem constraintsSystem) {
|
||||
for (TypeParameterDescriptor typeParameter : constraintsSystem.getTypeVariables()) {
|
||||
TypeConstraints constraints = constraintsSystem.getTypeConstraints(typeParameter);
|
||||
public static TypeParameterDescriptor getFirstConflictingParameter(@NotNull ConstraintSystem constraintSystem) {
|
||||
for (TypeParameterDescriptor typeParameter : constraintSystem.getTypeVariables()) {
|
||||
TypeConstraints constraints = constraintSystem.getTypeConstraints(typeParameter);
|
||||
if (getValues(constraints).size() > 1) {
|
||||
return typeParameter;
|
||||
}
|
||||
@@ -95,11 +95,11 @@ public class ConstraintsUtil {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Collection<TypeSubstitutor> getSubstitutorsForConflictingParameters(@NotNull ConstraintsSystem constraintsSystem) {
|
||||
TypeParameterDescriptor firstConflictingParameter = getFirstConflictingParameter(constraintsSystem);
|
||||
public static Collection<TypeSubstitutor> getSubstitutorsForConflictingParameters(@NotNull ConstraintSystem constraintSystem) {
|
||||
TypeParameterDescriptor firstConflictingParameter = getFirstConflictingParameter(constraintSystem);
|
||||
if (firstConflictingParameter == null) return Collections.emptyList();
|
||||
|
||||
Collection<JetType> conflictingTypes = getValues(constraintsSystem.getTypeConstraints(firstConflictingParameter));
|
||||
Collection<JetType> conflictingTypes = getValues(constraintSystem.getTypeConstraints(firstConflictingParameter));
|
||||
|
||||
ArrayList<Map<TypeConstructor, TypeProjection>> substitutionContexts = Lists.newArrayList();
|
||||
for (JetType type : conflictingTypes) {
|
||||
@@ -108,10 +108,10 @@ public class ConstraintsUtil {
|
||||
substitutionContexts.add(context);
|
||||
}
|
||||
|
||||
for (TypeParameterDescriptor typeParameter : constraintsSystem.getTypeVariables()) {
|
||||
for (TypeParameterDescriptor typeParameter : constraintSystem.getTypeVariables()) {
|
||||
if (typeParameter == firstConflictingParameter) continue;
|
||||
|
||||
JetType safeType = getSafeValue(constraintsSystem, typeParameter);
|
||||
JetType safeType = getSafeValue(constraintSystem, typeParameter);
|
||||
for (Map<TypeConstructor, TypeProjection> context : substitutionContexts) {
|
||||
TypeProjection typeProjection = new TypeProjection(safeType);
|
||||
context.put(typeParameter.getTypeConstructor(), typeProjection);
|
||||
@@ -125,8 +125,8 @@ public class ConstraintsUtil {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JetType getSafeValue(@NotNull ConstraintsSystem constraintsSystem, @NotNull TypeParameterDescriptor typeParameter) {
|
||||
TypeConstraints constraints = constraintsSystem.getTypeConstraints(typeParameter);
|
||||
public static JetType getSafeValue(@NotNull ConstraintSystem constraintSystem, @NotNull TypeParameterDescriptor typeParameter) {
|
||||
TypeConstraints constraints = constraintSystem.getTypeConstraints(typeParameter);
|
||||
JetType type = getValue(constraints);
|
||||
if (type != null) {
|
||||
return type;
|
||||
@@ -135,13 +135,13 @@ public class ConstraintsUtil {
|
||||
return typeParameter.getUpperBoundsAsType();
|
||||
}
|
||||
|
||||
public static boolean checkUpperBoundIsSatisfied(@NotNull ConstraintsSystem constraintsSystem,
|
||||
public static boolean checkUpperBoundIsSatisfied(@NotNull ConstraintSystem constraintSystem,
|
||||
@NotNull TypeParameterDescriptor typeParameter) {
|
||||
TypeConstraints typeConstraints = constraintsSystem.getTypeConstraints(typeParameter);
|
||||
TypeConstraints typeConstraints = constraintSystem.getTypeConstraints(typeParameter);
|
||||
assert typeConstraints != null;
|
||||
JetType type = getValue(typeConstraints);
|
||||
JetType upperBound = typeParameter.getUpperBoundsAsType();
|
||||
JetType substitute = constraintsSystem.getResultingSubstitutor().substitute(upperBound, Variance.INVARIANT);
|
||||
JetType substitute = constraintSystem.getResultingSubstitutor().substitute(upperBound, Variance.INVARIANT);
|
||||
|
||||
if (type != null) {
|
||||
if (substitute == null || !JetTypeChecker.INSTANCE.isSubtypeOf(type, substitute)) {
|
||||
@@ -151,11 +151,11 @@ public class ConstraintsUtil {
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean checkBoundsAreSatisfied(ConstraintsSystem constraintsSystem) {
|
||||
for (TypeParameterDescriptor typeVariable : constraintsSystem.getTypeVariables()) {
|
||||
JetType type = getValue(constraintsSystem.getTypeConstraints(typeVariable));
|
||||
public static boolean checkBoundsAreSatisfied(ConstraintSystem constraintSystem) {
|
||||
for (TypeParameterDescriptor typeVariable : constraintSystem.getTypeVariables()) {
|
||||
JetType type = getValue(constraintSystem.getTypeConstraints(typeVariable));
|
||||
JetType upperBound = typeVariable.getUpperBoundsAsType();
|
||||
JetType substitutedType = constraintsSystem.getResultingSubstitutor().substitute(upperBound, Variance.INVARIANT);
|
||||
JetType substitutedType = constraintSystem.getResultingSubstitutor().substitute(upperBound, Variance.INVARIANT);
|
||||
|
||||
if (type != null) {
|
||||
if (substitutedType == null || !JetTypeChecker.INSTANCE.isSubtypeOf(type, substitutedType)) {
|
||||
|
||||
+7
-7
@@ -29,27 +29,27 @@ import java.util.List;
|
||||
*/
|
||||
public class InferenceErrorData {
|
||||
public final CallableDescriptor descriptor;
|
||||
public final ConstraintsSystem constraintsSystem;
|
||||
public final ConstraintSystem constraintSystem;
|
||||
public final JetType receiverArgumentType;
|
||||
public final JetType expectedType;
|
||||
public final List<JetType> valueArgumentsTypes;
|
||||
|
||||
private InferenceErrorData(@NotNull CallableDescriptor descriptor, @NotNull ConstraintsSystem constraintsSystem,
|
||||
private InferenceErrorData(@NotNull CallableDescriptor descriptor, @NotNull ConstraintSystem constraintSystem,
|
||||
@Nullable List<JetType> valueArgumentsTypes, @Nullable JetType receiverArgumentType, @Nullable JetType expectedType) {
|
||||
this.descriptor = descriptor;
|
||||
this.constraintsSystem = constraintsSystem;
|
||||
this.constraintSystem = constraintSystem;
|
||||
this.receiverArgumentType = receiverArgumentType;
|
||||
this.valueArgumentsTypes = valueArgumentsTypes;
|
||||
this.expectedType = expectedType;
|
||||
}
|
||||
|
||||
public static InferenceErrorData create(@NotNull CallableDescriptor descriptor, @NotNull ConstraintsSystem constraintsSystem,
|
||||
public static InferenceErrorData create(@NotNull CallableDescriptor descriptor, @NotNull ConstraintSystem constraintSystem,
|
||||
@NotNull List<JetType> valueArgumentsTypes, @Nullable JetType receiverArgumentType, @Nullable JetType expectedType) {
|
||||
return new InferenceErrorData(descriptor, constraintsSystem, valueArgumentsTypes, receiverArgumentType,
|
||||
return new InferenceErrorData(descriptor, constraintSystem, valueArgumentsTypes, receiverArgumentType,
|
||||
expectedType != TypeUtils.NO_EXPECTED_TYPE ? expectedType : null);
|
||||
}
|
||||
|
||||
public static InferenceErrorData create(@NotNull CallableDescriptor descriptor, @NotNull ConstraintsSystem constraintsSystem) {
|
||||
return new InferenceErrorData(descriptor, constraintsSystem, null, null, null);
|
||||
public static InferenceErrorData create(@NotNull CallableDescriptor descriptor, @NotNull ConstraintSystem constraintSystem) {
|
||||
return new InferenceErrorData(descriptor, constraintSystem, null, null, null);
|
||||
}
|
||||
}
|
||||
|
||||
+4
-4
@@ -232,20 +232,20 @@ public class ExpressionTypingUtils {
|
||||
@NotNull JetType receiverType,
|
||||
@NotNull CallableDescriptor receiverArgument
|
||||
) {
|
||||
ConstraintsSystem constraintsSystem = new ConstraintsSystemImpl();
|
||||
ConstraintSystem constraintSystem = new ConstraintSystemImpl();
|
||||
for (TypeParameterDescriptor typeParameterDescriptor : receiverArgument.getTypeParameters()) {
|
||||
constraintsSystem.registerTypeVariable(typeParameterDescriptor, Variance.INVARIANT);
|
||||
constraintSystem.registerTypeVariable(typeParameterDescriptor, Variance.INVARIANT);
|
||||
}
|
||||
|
||||
ReceiverDescriptor receiverParameter = receiverArgument.getReceiverParameter();
|
||||
if (expectedReceiver.exists() && receiverParameter.exists()) {
|
||||
constraintsSystem.addSupertypeConstraint(receiverParameter.getType(), receiverType, ConstraintPosition.RECEIVER_POSITION);
|
||||
constraintSystem.addSupertypeConstraint(receiverParameter.getType(), receiverType, ConstraintPosition.RECEIVER_POSITION);
|
||||
}
|
||||
else if (expectedReceiver.exists() || receiverParameter.exists()) {
|
||||
// Only one of receivers exist
|
||||
return false;
|
||||
}
|
||||
|
||||
return constraintsSystem.isSuccessful() && ConstraintsUtil.checkBoundsAreSatisfied(constraintsSystem);
|
||||
return constraintSystem.isSuccessful() && ConstraintsUtil.checkBoundsAreSatisfied(constraintSystem);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user