Skip to content

Commit 413c0da

Browse files
committed
[CSGen] Store a stack of pack element generic environments in constraint
generation.
1 parent f4d53a3 commit 413c0da

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

lib/Sema/CSGen.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -844,6 +844,9 @@ namespace {
844844
/// found during our walk.
845845
llvm::MapVector<UnresolvedMemberExpr *, Type> UnresolvedBaseTypes;
846846

847+
/// A stack of pack element generic environments.
848+
llvm::SmallVector<GenericEnvironment *, 2> PackElementEnvironments;
849+
847850
/// Returns false and emits the specified diagnostic if the member reference
848851
/// base is a nil literal. Returns true otherwise.
849852
bool isValidBaseOfMemberRef(Expr *base, Diag<> diagnostic) {
@@ -1084,6 +1087,10 @@ namespace {
10841087

10851088
ConstraintSystem &getConstraintSystem() const { return CS; }
10861089

1090+
void addPackElementEnvironment(GenericEnvironment *env) {
1091+
PackElementEnvironments.push_back(env);
1092+
}
1093+
10871094
virtual Type visitErrorExpr(ErrorExpr *E) {
10881095
CS.recordFix(
10891096
IgnoreInvalidASTNode::create(CS, CS.getConstraintLocator(E)));
@@ -2957,10 +2964,8 @@ namespace {
29572964

29582965
Type visitPackExpansionExpr(PackExpansionExpr *expr) {
29592966
auto *elementEnv = expr->getGenericEnvironment();
2960-
for (auto *binding : expr->getBindings()) {
2961-
auto type = visit(binding);
2962-
CS.setType(binding, type);
2963-
}
2967+
assert(PackElementEnvironments.back() == elementEnv);
2968+
PackElementEnvironments.pop_back();
29642969

29652970
auto *patternLoc =
29662971
CS.getConstraintLocator(expr, ConstraintLocator::PackExpansionPattern);
@@ -3991,6 +3996,10 @@ namespace {
39913996
}
39923997
}
39933998

3999+
if (auto *expansion = dyn_cast<PackExpansionExpr>(expr)) {
4000+
CG.addPackElementEnvironment(expansion->getGenericEnvironment());
4001+
}
4002+
39944003
return Action::Continue(expr);
39954004
}
39964005

0 commit comments

Comments
 (0)