after rename subjectType and constraintType were exchanged
This commit is contained in:
@@ -338,7 +338,8 @@ public class CallResolver {
|
|||||||
ConstraintsSystem constraintsSystem = resolvedCall.getConstraintsSystem();
|
ConstraintsSystem constraintsSystem = resolvedCall.getConstraintsSystem();
|
||||||
assert constraintsSystem != null;
|
assert constraintsSystem != null;
|
||||||
|
|
||||||
constraintsSystem.addSupertypeConstraint(context.expectedType, descriptor.getReturnType(), ConstraintPosition.EXPECTED_TYPE_POSITION);
|
constraintsSystem.addSubtypingConstraint(descriptor.getReturnType(), context.expectedType,
|
||||||
|
ConstraintPosition.EXPECTED_TYPE_POSITION);
|
||||||
|
|
||||||
// constraints for function literals
|
// constraints for function literals
|
||||||
// Value parameters
|
// Value parameters
|
||||||
@@ -744,7 +745,8 @@ public class CallResolver {
|
|||||||
ReceiverDescriptor receiverArgument = candidateCall.getReceiverArgument();
|
ReceiverDescriptor receiverArgument = candidateCall.getReceiverArgument();
|
||||||
ReceiverDescriptor receiverParameter = candidateWithFreshVariables.getReceiverParameter();
|
ReceiverDescriptor receiverParameter = candidateWithFreshVariables.getReceiverParameter();
|
||||||
if (receiverArgument.exists() && receiverParameter.exists()) {
|
if (receiverArgument.exists() && receiverParameter.exists()) {
|
||||||
constraintsSystem.addSubtypingConstraint(receiverArgument.getType(), receiverParameter.getType(), ConstraintPosition.RECEIVER_POSITION);
|
constraintsSystem.addSupertypeConstraint(receiverParameter.getType(), receiverArgument.getType(),
|
||||||
|
ConstraintPosition.RECEIVER_POSITION);
|
||||||
}
|
}
|
||||||
|
|
||||||
ConstraintsSystemImpl constraintsBuilderWithRightTypeParameters = new ConstraintsSystemImpl(constraintsSystem.hasTypeConstructorMismatch(), constraintsSystem
|
ConstraintsSystemImpl constraintsBuilderWithRightTypeParameters = new ConstraintsSystemImpl(constraintsSystem.hasTypeConstructorMismatch(), constraintsSystem
|
||||||
@@ -785,7 +787,7 @@ public class CallResolver {
|
|||||||
context.scope, argumentExpression, substitutor.substitute(valueParameterDescriptor.getType(), Variance.INVARIANT),
|
context.scope, argumentExpression, substitutor.substitute(valueParameterDescriptor.getType(), Variance.INVARIANT),
|
||||||
context.dataFlowInfo, traceForUnknown) : null;
|
context.dataFlowInfo, traceForUnknown) : null;
|
||||||
if (type == null || ErrorUtils.isErrorType(type)) return false;
|
if (type == null || ErrorUtils.isErrorType(type)) return false;
|
||||||
constraintsSystem.addSubtypingConstraint(type, effectiveExpectedType, ConstraintPosition.getValueParameterPosition(
|
constraintsSystem.addSupertypeConstraint(effectiveExpectedType, type, ConstraintPosition.getValueParameterPosition(
|
||||||
valueParameterDescriptor.getIndex()));
|
valueParameterDescriptor.getIndex()));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
+34
-32
@@ -25,7 +25,6 @@ import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
|||||||
import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor;
|
import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor;
|
||||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||||
import org.jetbrains.jet.lang.types.*;
|
import org.jetbrains.jet.lang.types.*;
|
||||||
import org.jetbrains.jet.lang.types.checker.JetTypeChecker;
|
|
||||||
import org.jetbrains.jet.lang.types.checker.TypeCheckingProcedure;
|
import org.jetbrains.jet.lang.types.checker.TypeCheckingProcedure;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@@ -46,9 +45,9 @@ public class ConstraintsSystemImpl implements ConstraintsSystem {
|
|||||||
return ConstraintKind.EQUAL;
|
return ConstraintKind.EQUAL;
|
||||||
}
|
}
|
||||||
if (variance == Variance.OUT_VARIANCE) {
|
if (variance == Variance.OUT_VARIANCE) {
|
||||||
return ConstraintKind.SUB_TYPE;
|
return ConstraintKind.SUPER_TYPE;
|
||||||
}
|
}
|
||||||
return ConstraintKind.SUPER_TYPE;
|
return ConstraintKind.SUB_TYPE;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final Map<TypeParameterDescriptor, TypeConstraintsImpl> typeParameterConstraints = Maps.newLinkedHashMap();
|
private final Map<TypeParameterDescriptor, TypeConstraintsImpl> typeParameterConstraints = Maps.newLinkedHashMap();
|
||||||
@@ -123,63 +122,66 @@ public class ConstraintsSystemImpl implements ConstraintsSystem {
|
|||||||
addConstraint(ConstraintKind.SUPER_TYPE, subjectType, constrainingType, constraintPosition);
|
addConstraint(ConstraintKind.SUPER_TYPE, subjectType, constrainingType, constraintPosition);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addConstraint(@NotNull ConstraintKind constraintKind, @NotNull JetType subjectType, @NotNull JetType constrainingType,
|
private void addConstraint(@NotNull ConstraintKind constraintKind,
|
||||||
|
@NotNull JetType subjectType,
|
||||||
|
@NotNull JetType constrainingType,
|
||||||
@NotNull ConstraintPosition constraintPosition) {
|
@NotNull ConstraintPosition constraintPosition) {
|
||||||
if (subjectType == DONT_CARE || constrainingType == DONT_CARE || subjectType == TypeUtils.NO_EXPECTED_TYPE
|
|
||||||
|| constrainingType == TypeUtils.NO_EXPECTED_TYPE) {
|
if (constrainingType == DONT_CARE || subjectType == DONT_CARE || constrainingType == TypeUtils.NO_EXPECTED_TYPE
|
||||||
|
|| subjectType == TypeUtils.NO_EXPECTED_TYPE) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
DeclarationDescriptor constrainingTypeDescriptor = constrainingType.getConstructor().getDeclarationDescriptor();
|
DeclarationDescriptor constrainingTypeDescriptor = constrainingType.getConstructor().getDeclarationDescriptor();
|
||||||
DeclarationDescriptor subjectTypeDescriptor = subjectType.getConstructor().getDeclarationDescriptor();
|
DeclarationDescriptor subjectTypeDescriptor = subjectType.getConstructor().getDeclarationDescriptor();
|
||||||
|
|
||||||
if (constrainingTypeDescriptor instanceof TypeParameterDescriptor) {
|
if (subjectTypeDescriptor instanceof TypeParameterDescriptor) {
|
||||||
if (TypeUtils.dependsOnTypeParameterConstructors(subjectType, Collections.singleton(DONT_CARE.getConstructor()))) return;
|
if (TypeUtils.dependsOnTypeParameterConstructors(constrainingType, Collections.singleton(DONT_CARE.getConstructor()))) return;
|
||||||
if (constrainingType.isNullable()) {
|
if (subjectType.isNullable()) {
|
||||||
subjectType = TypeUtils.makeNotNullable(subjectType);
|
constrainingType = TypeUtils.makeNotNullable(constrainingType);
|
||||||
}
|
}
|
||||||
TypeParameterDescriptor typeParameter = (TypeParameterDescriptor) constrainingTypeDescriptor;
|
TypeParameterDescriptor typeParameter = (TypeParameterDescriptor) subjectTypeDescriptor;
|
||||||
if (constraintKind == ConstraintKind.SUB_TYPE) {
|
if (constraintKind == ConstraintKind.SUPER_TYPE) {
|
||||||
typeParameterConstraints.get(typeParameter).addLowerBound(subjectType);
|
typeParameterConstraints.get(typeParameter).addLowerBound(constrainingType);
|
||||||
}
|
}
|
||||||
else if (constraintKind == ConstraintKind.SUPER_TYPE) {
|
else if (constraintKind == ConstraintKind.SUB_TYPE) {
|
||||||
typeParameterConstraints.get(typeParameter).addUpperBound(subjectType);
|
typeParameterConstraints.get(typeParameter).addUpperBound(constrainingType);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
typeParameterConstraints.get(typeParameter).addExactBound(subjectType);
|
typeParameterConstraints.get(typeParameter).addExactBound(constrainingType);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (subjectTypeDescriptor instanceof ClassDescriptor && constrainingTypeDescriptor instanceof ClassDescriptor) {
|
if (constrainingTypeDescriptor instanceof ClassDescriptor && subjectTypeDescriptor instanceof ClassDescriptor) {
|
||||||
if (constraintKind != ConstraintKind.SUPER_TYPE) {
|
if (constraintKind != ConstraintKind.SUB_TYPE) {
|
||||||
JetType correspondingSupertype = TypeCheckingProcedure.findCorrespondingSupertype(subjectType, constrainingType);
|
|
||||||
if (correspondingSupertype != null) {
|
|
||||||
subjectType = correspondingSupertype;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
JetType correspondingSupertype = TypeCheckingProcedure.findCorrespondingSupertype(constrainingType, subjectType);
|
JetType correspondingSupertype = TypeCheckingProcedure.findCorrespondingSupertype(constrainingType, subjectType);
|
||||||
if (correspondingSupertype != null) {
|
if (correspondingSupertype != null) {
|
||||||
constrainingType = correspondingSupertype;
|
constrainingType = correspondingSupertype;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
JetType correspondingSupertype = TypeCheckingProcedure.findCorrespondingSupertype(subjectType, constrainingType);
|
||||||
|
if (correspondingSupertype != null) {
|
||||||
|
subjectType = correspondingSupertype;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (subjectType.getConstructor().getParameters().size() != constrainingType.getConstructor().getParameters().size()) {
|
if (constrainingType.getConstructor().getParameters().size() != subjectType.getConstructor().getParameters().size()) {
|
||||||
errorConstraintPositions.add(constraintPosition);
|
errorConstraintPositions.add(constraintPosition);
|
||||||
typeConstructorMismatch = true;
|
typeConstructorMismatch = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ClassDescriptor subClass = (ClassDescriptor) subjectType.getConstructor().getDeclarationDescriptor();
|
ClassDescriptor subClass = (ClassDescriptor) constrainingType.getConstructor().getDeclarationDescriptor();
|
||||||
ClassDescriptor superClass = (ClassDescriptor) constrainingType.getConstructor().getDeclarationDescriptor();
|
ClassDescriptor superClass = (ClassDescriptor) subjectType.getConstructor().getDeclarationDescriptor();
|
||||||
if (DescriptorUtils.isSubclass(subClass, superClass)) {
|
if (DescriptorUtils.isSubclass(subClass, superClass)) {
|
||||||
List<TypeProjection> subArguments = subjectType.getArguments();
|
List<TypeProjection> subArguments = constrainingType.getArguments();
|
||||||
List<TypeProjection> superArguments = constrainingType.getArguments();
|
List<TypeProjection> superArguments = subjectType.getArguments();
|
||||||
List<TypeParameterDescriptor> superParameters = constrainingType.getConstructor().getParameters();
|
List<TypeParameterDescriptor> superParameters = subjectType.getConstructor().getParameters();
|
||||||
for (int i = 0; i < superArguments.size(); i++) {
|
for (int i = 0; i < superArguments.size(); i++) {
|
||||||
addConstraint(varianceToConstraintKind(superParameters.get(i).getVariance()), subArguments.get(i).getType(), superArguments.get(i).getType(),
|
addConstraint(varianceToConstraintKind(superParameters.get(i).getVariance()), superArguments.get(i).getType(),
|
||||||
constraintPosition);
|
subArguments.get(i).getType(), constraintPosition);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -239,7 +239,7 @@ public class ExpressionTypingUtils {
|
|||||||
|
|
||||||
ReceiverDescriptor receiverParameter = receiverArgument.getReceiverParameter();
|
ReceiverDescriptor receiverParameter = receiverArgument.getReceiverParameter();
|
||||||
if (expectedReceiver.exists() && receiverParameter.exists()) {
|
if (expectedReceiver.exists() && receiverParameter.exists()) {
|
||||||
constraintsSystem.addSubtypingConstraint(receiverType, receiverParameter.getType(), ConstraintPosition.RECEIVER_POSITION);
|
constraintsSystem.addSupertypeConstraint(receiverParameter.getType(), receiverType, ConstraintPosition.RECEIVER_POSITION);
|
||||||
}
|
}
|
||||||
else if (expectedReceiver.exists() || receiverParameter.exists()) {
|
else if (expectedReceiver.exists() || receiverParameter.exists()) {
|
||||||
// Only one of receivers exist
|
// Only one of receivers exist
|
||||||
|
|||||||
Reference in New Issue
Block a user