@NotNull
  @Override
  protected Set<JetType> resolveUpperBounds() {
    Set<JetType> upperBounds = Sets.newLinkedHashSet();

    JetTypeParameter jetTypeParameter = this.jetTypeParameter;

    resolveUpperBoundsFromWhereClause(upperBounds);

    JetTypeReference extendsBound = jetTypeParameter.getExtendsBound();
    if (extendsBound != null) {
      upperBounds.add(resolveBoundType(extendsBound));
    }

    if (upperBounds.isEmpty()) {
      upperBounds.add(KotlinBuiltIns.getInstance().getDefaultBound());
    }

    return upperBounds;
  }
  private void computeTypeParameters(List<TypeParameterDescriptor> typeParameters) {
    if (typeParameters.size() != altFunDeclaration.getTypeParameters().size()) {
      throw new AlternativeSignatureMismatchException(
          "Method signature has %d type parameters, but alternative signature has %d",
          typeParameters.size(), altFunDeclaration.getTypeParameters().size());
    }

    altTypeParameters = new ArrayList<TypeParameterDescriptor>();

    for (int i = 0, size = typeParameters.size(); i < size; i++) {
      TypeParameterDescriptor originalTypeParamDescriptor = typeParameters.get(i);

      TypeParameterDescriptorImpl altParamDescriptor =
          originalToAltTypeParameters.get(originalTypeParamDescriptor);
      JetTypeParameter altTypeParameter = altFunDeclaration.getTypeParameters().get(i);

      int upperBoundIndex = 0;
      for (JetType upperBound : originalTypeParamDescriptor.getUpperBounds()) {
        JetTypeElement altTypeElement;

        if (upperBoundIndex == 0) {
          JetTypeReference extendsBound = altTypeParameter.getExtendsBound();
          if (extendsBound == null) { // default upper bound
            assert originalTypeParamDescriptor.getUpperBounds().size() == 1;
            altParamDescriptor.addDefaultUpperBound();
            break;
          } else {
            altTypeElement = extendsBound.getTypeElement();
          }
        } else {
          JetTypeConstraint constraint =
              findTypeParameterConstraint(
                  altFunDeclaration, originalTypeParamDescriptor.getName(), upperBoundIndex);
          if (constraint == null) {
            throw new AlternativeSignatureMismatchException(
                "Upper bound #%d for type parameter %s is missing",
                upperBoundIndex, originalTypeParamDescriptor.getName());
          }
          //noinspection ConstantConditions
          altTypeElement = constraint.getBoundTypeReference().getTypeElement();
        }

        assert (altTypeElement != null);

        altParamDescriptor.addUpperBound(
            TypeTransformingVisitor.computeType(
                altTypeElement, upperBound,
                originalToAltTypeParameters, UPPER_BOUND));
        upperBoundIndex++;
      }

      if (findTypeParameterConstraint(
              altFunDeclaration, originalTypeParamDescriptor.getName(), upperBoundIndex)
          != null) {
        throw new AlternativeSignatureMismatchException(
            "Extra upper bound #%d for type parameter %s",
            upperBoundIndex, originalTypeParamDescriptor.getName());
      }

      altParamDescriptor.setInitialized();
      altTypeParameters.add(altParamDescriptor);
    }
  }