Merge pull request #40587 from CodaFi/substitute-teacher

Initial Semantics for Variadic Generics
This commit is contained in:
Robert Widmann
2021-12-20 11:25:25 -08:00
committed by GitHub
45 changed files with 1421 additions and 104 deletions

View File

@@ -1602,11 +1602,12 @@ namespace {
if (specializations.size() > typeVars.size()) {
de.diagnose(expr->getSubExpr()->getLoc(),
diag::type_parameter_count_mismatch,
bgt->getDecl()->getName(),
typeVars.size(), specializations.size(),
false)
.highlight(SourceRange(expr->getLAngleLoc(),
expr->getRAngleLoc()));
bgt->getDecl()->getName(), typeVars.size(),
specializations.size(),
/*too many arguments*/ false,
/*type sequence?*/ false)
.highlight(
SourceRange(expr->getLAngleLoc(), expr->getRAngleLoc()));
de.diagnose(bgt->getDecl(), diag::kind_declname_declared_here,
DescriptiveDeclKind::GenericType,
bgt->getDecl()->getName());
@@ -1717,6 +1718,18 @@ namespace {
return TupleType::get(elements, CS.getASTContext());
}
Type visitPackExpr(PackExpr *expr) {
// The type of a pack expression is simply a pack of the types of
// its subexpressions.
SmallVector<Type, 4> elements;
elements.reserve(expr->getNumElements());
for (unsigned i = 0, n = expr->getNumElements(); i != n; ++i) {
elements.emplace_back(CS.getType(expr->getElement(i)));
}
return PackType::get(CS.getASTContext(), elements);
}
Type visitSubscriptExpr(SubscriptExpr *expr) {
ValueDecl *decl = nullptr;
if (expr->hasDecl()) {
@@ -2764,7 +2777,7 @@ namespace {
CS.addConstraint(ConstraintKind::ApplicableFunction,
FunctionType::get(params, resultType, extInfo),
CS.getType(expr->getFn()),
CS.getType(fnExpr),
CS.getConstraintLocator(expr, ConstraintLocator::ApplyFunction));
// If we ended up resolving the result type variable to a concrete type,