mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Merge pull request #30423 from AnthonyLatsis/se-0267-additions
[SE-0267] Improvements (Ep. 1)
This commit is contained in:
@@ -418,12 +418,10 @@ parseFreestandingGenericWhereClause(GenericContext *genCtx,
|
||||
|
||||
genericParams->addTrailingWhereClause(Context, WhereLoc, Requirements);
|
||||
|
||||
// A where clause that references only outer generic parameters?
|
||||
} else if (flags.contains(PD_HasContainerType)) {
|
||||
} else {
|
||||
// A where clause against outer generic parameters.
|
||||
genCtx->setTrailingWhereClause(
|
||||
TrailingWhereClause::create(Context, WhereLoc, Requirements));
|
||||
} else {
|
||||
diagnose(WhereLoc, diag::where_toplevel_nongeneric);
|
||||
}
|
||||
|
||||
return ParserStatus();
|
||||
|
||||
@@ -620,11 +620,15 @@ GenericSignatureRequest::evaluate(Evaluator &evaluator,
|
||||
return cast<SubscriptDecl>(accessor->getStorage())->getGenericSignature();
|
||||
}
|
||||
|
||||
// ...or we may have a where clause dependent on outer generic parameters.
|
||||
// ...or we may only have a contextual where clause.
|
||||
} else if (const auto *where = GC->getTrailingWhereClause()) {
|
||||
// If there is no generic context for the where clause to
|
||||
// rely on, diagnose that now and bail out.
|
||||
if (!GC->isGenericContext()) {
|
||||
if (GC->getParent()->isModuleScopeContext()) {
|
||||
GC->getASTContext().Diags.diagnose(where->getWhereLoc(),
|
||||
diag::where_nongeneric_toplevel);
|
||||
return nullptr;
|
||||
} else if (!GC->isGenericContext()) {
|
||||
GC->getASTContext().Diags.diagnose(where->getWhereLoc(),
|
||||
diag::where_nongeneric_ctx);
|
||||
return nullptr;
|
||||
|
||||
@@ -651,30 +651,25 @@ static Type checkContextualRequirements(Type type,
|
||||
return type;
|
||||
}
|
||||
|
||||
// We are interested in either a contextual where clause or
|
||||
// a constrained extension context.
|
||||
TypeSubstitutionMap subMap;
|
||||
GenericSignature genericSig;
|
||||
SourceLoc noteLoc;
|
||||
if (decl->getTrailingWhereClause()) {
|
||||
subMap = parentTy->getContextSubstitutions(decl->getDeclContext());
|
||||
genericSig = decl->getGenericSignature();
|
||||
noteLoc = decl->getLoc();
|
||||
} else {
|
||||
{
|
||||
// We are interested in either a contextual where clause or
|
||||
// a constrained extension context.
|
||||
const auto ext = dyn_cast<ExtensionDecl>(decl->getDeclContext());
|
||||
if (ext && ext->isConstrainedExtension()) {
|
||||
subMap = parentTy->getContextSubstitutions(ext);
|
||||
genericSig = ext->getGenericSignature();
|
||||
if (decl->getTrailingWhereClause())
|
||||
noteLoc = decl->getLoc();
|
||||
else if (ext && ext->isConstrainedExtension())
|
||||
noteLoc = ext->getLoc();
|
||||
} else {
|
||||
else
|
||||
return type;
|
||||
}
|
||||
|
||||
if (noteLoc.isInvalid())
|
||||
noteLoc = loc;
|
||||
}
|
||||
|
||||
if (noteLoc.isInvalid())
|
||||
noteLoc = loc;
|
||||
|
||||
auto result =
|
||||
const auto subMap = parentTy->getContextSubstitutions(decl->getDeclContext());
|
||||
const auto genericSig = decl->getGenericSignature();
|
||||
const auto result =
|
||||
TypeChecker::checkGenericArguments(
|
||||
dc, loc, noteLoc, type,
|
||||
genericSig->getGenericParams(),
|
||||
|
||||
Reference in New Issue
Block a user