From 1632ec07cda5f4ee3a2726ff0365a498a9e93c85 Mon Sep 17 00:00:00 2001 From: Svetlana Isakova Date: Wed, 11 Jul 2012 17:56:23 +0400 Subject: [PATCH] moved 'checkBoundsAreSatisfied' to ConstraintsUtil --- .../calls/inference/ConstraintsSystemImpl.java | 17 +---------------- .../calls/inference/ConstraintsUtil.java | 15 +++++++++++++++ .../expressions/ExpressionTypingUtils.java | 8 ++++---- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/inference/ConstraintsSystemImpl.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/inference/ConstraintsSystemImpl.java index b8b03e4625e..c9c63bf020e 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/inference/ConstraintsSystemImpl.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/inference/ConstraintsSystemImpl.java @@ -123,7 +123,7 @@ public class ConstraintsSystemImpl implements ConstraintsSystem { addConstraint(ConstraintKind.SUPER_TYPE, subjectType, constrainingType, constraintPosition); } - public 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) { if (subjectType == DONT_CARE || constrainingType == DONT_CARE || subjectType == TypeUtils.NO_EXPECTED_TYPE || constrainingType == TypeUtils.NO_EXPECTED_TYPE) { @@ -234,19 +234,4 @@ public class ConstraintsSystemImpl implements ConstraintsSystem { public TypeSubstitutor getResultingSubstitutor() { return resultingSubstitutor; } - - public boolean upperBoundsAreSatisfied() { - for (TypeParameterDescriptor typeParameter : typeParameterConstraints.keySet()) { - JetType type = ConstraintsUtil.getValue(getTypeConstraints(typeParameter)); - JetType upperBound = typeParameter.getUpperBoundsAsType(); - JetType substitute = getResultingSubstitutor().substitute(upperBound, Variance.INVARIANT); - - if (type != null) { - if (substitute == null || !JetTypeChecker.INSTANCE.isSubtypeOf(type, substitute)) { - return false; - } - } - } - return true; - } } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/inference/ConstraintsUtil.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/inference/ConstraintsUtil.java index f2f8b54b4b5..23040edcf26 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/inference/ConstraintsUtil.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/inference/ConstraintsUtil.java @@ -150,4 +150,19 @@ public class ConstraintsUtil { } return true; } + + public static boolean checkBoundsAreSatisfied(ConstraintsSystem constraintsSystem) { + for (TypeParameterDescriptor typeVariable : constraintsSystem.getTypeVariables()) { + JetType type = getValue(constraintsSystem.getTypeConstraints(typeVariable)); + JetType upperBound = typeVariable.getUpperBoundsAsType(); + JetType substitutedType = constraintsSystem.getResultingSubstitutor().substitute(upperBound, Variance.INVARIANT); + + if (type != null) { + if (substitutedType == null || !JetTypeChecker.INSTANCE.isSubtypeOf(type, substitutedType)) { + return false; + } + } + } + return true; + } } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ExpressionTypingUtils.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ExpressionTypingUtils.java index 0faf2108fe2..3c269ea52ab 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ExpressionTypingUtils.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ExpressionTypingUtils.java @@ -232,20 +232,20 @@ public class ExpressionTypingUtils { @NotNull JetType receiverType, @NotNull CallableDescriptor receiverArgument ) { - ConstraintsSystemImpl constraintsBuilder = new ConstraintsSystemImpl(); + ConstraintsSystem constraintsSystem = new ConstraintsSystemImpl(); for (TypeParameterDescriptor typeParameterDescriptor : receiverArgument.getTypeParameters()) { - constraintsBuilder.registerTypeVariable(typeParameterDescriptor, Variance.INVARIANT); + constraintsSystem.registerTypeVariable(typeParameterDescriptor, Variance.INVARIANT); } ReceiverDescriptor receiverParameter = receiverArgument.getReceiverParameter(); if (expectedReceiver.exists() && receiverParameter.exists()) { - constraintsBuilder.addSubtypingConstraint(receiverType, receiverParameter.getType(), ConstraintPosition.RECEIVER_POSITION); + constraintsSystem.addSubtypingConstraint(receiverType, receiverParameter.getType(), ConstraintPosition.RECEIVER_POSITION); } else if (expectedReceiver.exists() || receiverParameter.exists()) { // Only one of receivers exist return false; } - return constraintsBuilder.isSuccessful() && constraintsBuilder.upperBoundsAreSatisfied(); + return constraintsSystem.isSuccessful() && ConstraintsUtil.checkBoundsAreSatisfied(constraintsSystem); } }