Repository: apple/swift
File: lib/Sema/CSDiagnostics.cpp (C++)

Code before:
}

bool InvalidPackElement::diagnoseAsError() {
  emitDiagnostic(diag::each_non_pack, packElementType);
  return true;
}

bool InvalidPackReference::diagnoseAsError() {
  auto patternType =
      getPatternTypeOfSingleUnlabeledPackExpansionTuple(packType);
  auto diagnosisType = patternType ? patternType : packType;
  emitDiagnostic(diag::pack_reference_outside_expansion, diagnosisType);
  return true;
}

bool InvalidPackExpansion::diagnoseAsError() {
  auto *locator = getLocator();
  if (locator->isLastElement<LocatorPathElt::ApplyArgToParam>()) {
    if (auto argInfo = getFunctionArgApplyInfo(locator)) {
      // If the pack expansion is being passed to a param that expects a tuple
      // containing a pack, note this and add a fix-it.
      if (auto tuple = argInfo->getParamInterfaceType()->getAs<TupleType>()) {
        if (containsPackExpansionType(tuple)) {
          auto range = getSourceRange();
          emitDiagnostic(diag::invalid_expansion_argument_for_tuple,
                         argInfo->getParamInterfaceType())
              .fixItInsert(range.Start, "(")
              .fixItInsertAfter(range.End, ")");
          emitDiagnostic(diag::did_you_mean_tuple_pack_expansion);
          return true;
        }
      }
      emitDiagnostic(diag::invalid_expansion_argument,
                     argInfo->getParamInterfaceType());
      return true;
    }
  }

  emitDiagnostic(diag::expansion_expr_not_allowed);
  return true;
}

bool InvalidWhereClauseInPackIteration::diagnoseAsError() {
  emitDiagnostic(diag::pack_iteration_where_clause_not_supported);
  return true;
}

bool CollectionElementContextualFailure::diagnoseAsError() {
  auto anchor = getRawAnchor();
  auto *locator = getLocator();


Review comment (suggestion):
The message should use parameter type recorded in the diagnostic instead of an interface type.

Code after:
}

bool InvalidPackElement::diagnoseAsError() {
  emitDiagnostic(diag::each_non_pack, packElementType);
  return true;
}

bool InvalidPackReference::diagnoseAsError() {
  auto patternType =
      getPatternTypeOfSingleUnlabeledPackExpansionTuple(packType);
  auto diagnosisType = patternType ? patternType : packType;
  emitDiagnostic(diag::pack_reference_outside_expansion, diagnosisType);
  return true;
}

bool InvalidPackExpansion::diagnoseAsError() {
  auto *locator = getLocator();
  if (locator->isLastElement<LocatorPathElt::ApplyArgToParam>()) {
    if (auto argInfo = getFunctionArgApplyInfo(locator)) {
      emitDiagnostic(diag::invalid_expansion_argument,
                     argInfo->getParamInterfaceType());
      // If the pack expansion is being passed to a param that expects a tuple
      // containing a pack, note this and add a fix-it.
      if (auto tuple = argInfo->getParamInterfaceType()->getAs<TupleType>()) {
        if (containsPackExpansionType(tuple)) {
          auto range = getSourceRange();
          emitDiagnostic(diag::did_you_mean_tuple_pack_expansion)
              .fixItInsert(range.Start, "(")
              .fixItInsertAfter(range.End, ")");
        }
      }
      return true;
    }
  }

  emitDiagnostic(diag::expansion_expr_not_allowed);
  return true;
}

bool InvalidWhereClauseInPackIteration::diagnoseAsError() {
  emitDiagnostic(diag::pack_iteration_where_clause_not_supported);
  return true;
}

bool CollectionElementContextualFailure::diagnoseAsError() {
  auto anchor = getRawAnchor();
  auto *locator = getLocator();

  auto eltType = getFromType();
  auto contextualType = getToType();