Merge pull request #30423 from AnthonyLatsis/se-0267-additions

[SE-0267] Improvements (Ep. 1)
This commit is contained in:
Anthony Latsis
2020-03-21 08:59:13 +03:00
committed by GitHub
11 changed files with 103 additions and 45 deletions

View File

@@ -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();

View File

@@ -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;

View File

@@ -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(),