@@ -507,6 +507,9 @@ class SyntacticElementConstraintGenerator
507
507
SyntacticElementContext context;
508
508
ConstraintLocator *locator;
509
509
510
+ // / Whether a conjunction was generated.
511
+ bool generatedConjunction = false ;
512
+
510
513
public:
511
514
// / Whether an error was encountered while generating constraints.
512
515
bool hadError = false ;
@@ -519,6 +522,16 @@ class SyntacticElementConstraintGenerator
519
522
void createConjunction (ArrayRef<ElementInfo> elements,
520
523
ConstraintLocator *locator, bool isIsolated = false ,
521
524
ArrayRef<TypeVariableType *> extraTypeVars = {}) {
525
+ assert (!generatedConjunction && " Already generated conjunction" );
526
+ generatedConjunction = true ;
527
+
528
+ // Inject a join if we have one.
529
+ SmallVector<ElementInfo, 4 > scratch;
530
+ if (auto *join = context.ElementJoin .getPtrOrNull ()) {
531
+ scratch.append (elements.begin (), elements.end ());
532
+ scratch.push_back (makeJoinElement (cs, join, locator));
533
+ elements = scratch;
534
+ }
522
535
::createConjunction (cs, context.getAsDeclContext(), elements, locator,
523
536
isIsolated, extraTypeVars);
524
537
}
@@ -865,10 +878,6 @@ class SyntacticElementConstraintGenerator
865
878
elements.push_back (makeElement (ifStmt->getElseStmt (), elseLoc));
866
879
}
867
880
868
- // Inject a join if we have one.
869
- if (auto *join = context.ElementJoin .getPtrOrNull ())
870
- elements.push_back (makeJoinElement (cs, join, locator));
871
-
872
881
createConjunction (elements, locator);
873
882
}
874
883
@@ -1010,10 +1019,6 @@ class SyntacticElementConstraintGenerator
1010
1019
elements.push_back (makeElement (rawCase, switchLoc));
1011
1020
}
1012
1021
1013
- // Inject a join if we have one.
1014
- if (auto *join = context.ElementJoin .getPtrOrNull ())
1015
- elements.push_back (makeJoinElement (cs, join, switchLoc));
1016
-
1017
1022
createConjunction (elements, switchLoc);
1018
1023
}
1019
1024
@@ -1036,10 +1041,6 @@ class SyntacticElementConstraintGenerator
1036
1041
for (auto *catchStmt : doStmt->getCatches ())
1037
1042
elements.push_back (makeElement (catchStmt, doLoc));
1038
1043
1039
- // Inject a join if we have one.
1040
- if (auto *join = context.ElementJoin .getPtrOrNull ())
1041
- elements.push_back (makeJoinElement (cs, join, locator));
1042
-
1043
1044
createConjunction (elements, doLoc);
1044
1045
}
1045
1046
@@ -1228,10 +1229,6 @@ class SyntacticElementConstraintGenerator
1228
1229
contextInfo.value_or (ContextualTypeInfo ()), isDiscarded));
1229
1230
}
1230
1231
1231
- // Inject a join if we have one.
1232
- if (auto *join = context.ElementJoin .getPtrOrNull ())
1233
- elements.push_back (makeJoinElement (cs, join, locator));
1234
-
1235
1232
createConjunction (elements, locator);
1236
1233
}
1237
1234
0 commit comments