@@ -844,6 +844,9 @@ namespace {
844
844
// / found during our walk.
845
845
llvm::MapVector<UnresolvedMemberExpr *, Type> UnresolvedBaseTypes;
846
846
847
+ // / A stack of pack element generic environments.
848
+ llvm::SmallVector<GenericEnvironment *, 2 > PackElementEnvironments;
849
+
847
850
// / Returns false and emits the specified diagnostic if the member reference
848
851
// / base is a nil literal. Returns true otherwise.
849
852
bool isValidBaseOfMemberRef (Expr *base, Diag<> diagnostic) {
@@ -1084,6 +1087,10 @@ namespace {
1084
1087
1085
1088
ConstraintSystem &getConstraintSystem () const { return CS; }
1086
1089
1090
+ void addPackElementEnvironment (GenericEnvironment *env) {
1091
+ PackElementEnvironments.push_back (env);
1092
+ }
1093
+
1087
1094
virtual Type visitErrorExpr (ErrorExpr *E) {
1088
1095
CS.recordFix (
1089
1096
IgnoreInvalidASTNode::create (CS, CS.getConstraintLocator (E)));
@@ -2957,10 +2964,8 @@ namespace {
2957
2964
2958
2965
Type visitPackExpansionExpr (PackExpansionExpr *expr) {
2959
2966
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 ();
2964
2969
2965
2970
auto *patternLoc =
2966
2971
CS.getConstraintLocator (expr, ConstraintLocator::PackExpansionPattern);
@@ -3991,6 +3996,10 @@ namespace {
3991
3996
}
3992
3997
}
3993
3998
3999
+ if (auto *expansion = dyn_cast<PackExpansionExpr>(expr)) {
4000
+ CG.addPackElementEnvironment (expansion->getGenericEnvironment ());
4001
+ }
4002
+
3994
4003
return Action::Continue (expr);
3995
4004
}
3996
4005
0 commit comments