mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Merge branch 'main' into import-extension-visibility
This commit is contained in:
@@ -455,8 +455,28 @@ bool RequirementFailure::diagnoseAsError() {
|
||||
|
||||
if (auto *OTD = dyn_cast<OpaqueTypeDecl>(AffectedDecl)) {
|
||||
auto *namingDecl = OTD->getNamingDecl();
|
||||
emitDiagnostic(diag::type_does_not_conform_in_opaque_return,
|
||||
namingDecl, lhs, rhs, rhs->isAnyObject());
|
||||
|
||||
auto &req = getRequirement();
|
||||
switch (req.getKind()) {
|
||||
case RequirementKind::Conformance:
|
||||
case RequirementKind::Layout:
|
||||
emitDiagnostic(diag::type_does_not_conform_in_opaque_return, namingDecl,
|
||||
lhs, rhs, rhs->isAnyObject());
|
||||
break;
|
||||
|
||||
case RequirementKind::Superclass:
|
||||
emitDiagnostic(diag::types_not_inherited_in_opaque_return, namingDecl,
|
||||
lhs, rhs);
|
||||
break;
|
||||
|
||||
case RequirementKind::SameType:
|
||||
emitDiagnostic(diag::type_is_not_equal_in_opaque_return, namingDecl, lhs,
|
||||
rhs);
|
||||
break;
|
||||
|
||||
case RequirementKind::SameShape:
|
||||
return false;
|
||||
}
|
||||
|
||||
if (auto *repr = namingDecl->getOpaqueResultTypeRepr()) {
|
||||
emitDiagnosticAt(repr->getLoc(), diag::opaque_return_type_declared_here)
|
||||
@@ -903,7 +923,7 @@ bool GenericArgumentsMismatchFailure::diagnoseAsError() {
|
||||
auto *decl = DRE->getDecl();
|
||||
if (decl && decl->hasName()) {
|
||||
auto baseName = DRE->getDecl()->getBaseIdentifier();
|
||||
if (baseName.str().startswith("$__builder")) {
|
||||
if (baseName.str().starts_with("$__builder")) {
|
||||
diagnostic =
|
||||
diag::cannot_convert_result_builder_result_to_return_type;
|
||||
break;
|
||||
@@ -3473,9 +3493,7 @@ bool ContextualFailure::tryProtocolConformanceFixIt(
|
||||
evaluateOrDefault(getASTContext().evaluator,
|
||||
ResolveTypeWitnessesRequest{conformance},
|
||||
evaluator::SideEffect());
|
||||
evaluateOrDefault(getASTContext().evaluator,
|
||||
ResolveValueWitnessesRequest{conformance},
|
||||
evaluator::SideEffect());
|
||||
conformance->resolveValueWitnesses();
|
||||
|
||||
fakeConformances.push_back(conformance);
|
||||
}
|
||||
@@ -4660,6 +4678,7 @@ bool InvalidMemberRefOnExistential::diagnoseAsError() {
|
||||
break;
|
||||
|
||||
case AccessorKind::Get:
|
||||
case AccessorKind::DistributedGet:
|
||||
case AccessorKind::Read:
|
||||
case AccessorKind::Modify:
|
||||
case AccessorKind::Address:
|
||||
@@ -4696,7 +4715,8 @@ bool InvalidMemberRefOnExistential::diagnoseAsError() {
|
||||
while (auto *metatype = dyn_cast<MetatypeTypeRepr>(constraintRepr)) {
|
||||
// The generic equivalent of 'any P.Type' is '(some P).Type'
|
||||
constraintRepr = metatype->getBase()->getWithoutParens();
|
||||
if (isa<SimpleIdentTypeRepr>(constraintRepr))
|
||||
if (isa<UnqualifiedIdentTypeRepr>(constraintRepr) &&
|
||||
!cast<UnqualifiedIdentTypeRepr>(constraintRepr)->hasGenericArgList())
|
||||
needsParens = !isa<TupleTypeRepr>(metatype->getBase());
|
||||
}
|
||||
|
||||
@@ -5862,12 +5882,16 @@ bool OutOfOrderArgumentFailure::diagnoseAsError() {
|
||||
|
||||
// Move requires postfix comma only if argument is moved in-between
|
||||
// other arguments.
|
||||
bool requiresComma =
|
||||
!isExpr<BinaryExpr>(anchor) && PrevArgIdx != args->size() - 1;
|
||||
std::string argumentSeparator;
|
||||
if (auto *BE = getAsExpr<BinaryExpr>(anchor)) {
|
||||
auto operatorName = std::string(*getOperatorName(BE->getFn()));
|
||||
argumentSeparator = " " + operatorName + " ";
|
||||
} else if (PrevArgIdx != args->size() - 1) {
|
||||
argumentSeparator = ", ";
|
||||
}
|
||||
|
||||
diag.fixItRemove(removalRange);
|
||||
diag.fixItInsert(secondRange.Start,
|
||||
text.str() + (requiresComma ? ", " : ""));
|
||||
diag.fixItInsert(secondRange.Start, text.str() + argumentSeparator);
|
||||
};
|
||||
|
||||
// There are 4 diagnostic messages variations depending on
|
||||
@@ -6475,13 +6499,11 @@ bool NotCopyableFailure::diagnoseAsError() {
|
||||
emitDiagnostic(diag::noncopyable_generics, noncopyableTy);
|
||||
|
||||
#ifndef NDEBUG
|
||||
if (getASTContext().LangOpts.hasFeature(Feature::NoncopyableGenerics)) {
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||
getLocator()->dump(&getConstraintSystem());
|
||||
#pragma clang diagnostic pop
|
||||
llvm_unreachable("NoncopyableGenerics: vague diagnostic for locator");
|
||||
}
|
||||
#endif
|
||||
|
||||
return true;
|
||||
@@ -8258,6 +8280,44 @@ bool UnableToInferClosureReturnType::diagnoseAsError() {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool UnableToInferGenericPackElementType::diagnoseAsError() {
|
||||
auto *locator = getLocator();
|
||||
|
||||
auto packElementElt = locator->getLastElementAs<LocatorPathElt::PackElement>();
|
||||
assert(packElementElt && "Expected path to end with a pack element locator");
|
||||
|
||||
if (isExpr<NilLiteralExpr>(getAnchor())) {
|
||||
// `nil` appears as an element of generic pack params, let's record a
|
||||
// specify contextual type for nil fix.
|
||||
emitDiagnostic(diag::unresolved_nil_literal);
|
||||
} else {
|
||||
// unable to infer the type of an element of generic pack params
|
||||
emitDiagnostic(diag::could_not_infer_pack_element,
|
||||
packElementElt->getIndex());
|
||||
}
|
||||
|
||||
if (isExpr<ApplyExpr>(locator->getAnchor())) {
|
||||
// emit callee side diagnostics
|
||||
if (auto *calleeLocator = getSolution().getCalleeLocator(locator)) {
|
||||
if (const auto choice = getOverloadChoiceIfAvailable(calleeLocator)) {
|
||||
if (auto *decl = choice->choice.getDeclOrNull()) {
|
||||
if (auto applyArgToParamElt =
|
||||
locator->findFirst<LocatorPathElt::ApplyArgToParam>()) {
|
||||
if (auto paramDecl =
|
||||
getParameterAt(decl, applyArgToParamElt->getParamIdx())) {
|
||||
emitDiagnosticAt(
|
||||
paramDecl->getLoc(), diag::note_in_opening_pack_element,
|
||||
packElementElt->getIndex(), paramDecl->getNameStr());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static std::pair<StringRef, StringRef>
|
||||
getImportModuleAndDefaultType(const ASTContext &ctx,
|
||||
const ObjectLiteralExpr *expr) {
|
||||
|
||||
Reference in New Issue
Block a user