@@ -507,6 +507,9 @@ class SyntacticElementConstraintGenerator
507507 SyntacticElementContext context;
508508 ConstraintLocator *locator;
509509
510+ // / Whether a conjunction was generated.
511+ bool generatedConjunction = false ;
512+
510513public:
511514 // / Whether an error was encountered while generating constraints.
512515 bool hadError = false ;
@@ -519,6 +522,16 @@ class SyntacticElementConstraintGenerator
519522 void createConjunction (ArrayRef<ElementInfo> elements,
520523 ConstraintLocator *locator, bool isIsolated = false ,
521524 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+ }
522535 ::createConjunction (cs, context.getAsDeclContext(), elements, locator,
523536 isIsolated, extraTypeVars);
524537 }
@@ -865,10 +878,6 @@ class SyntacticElementConstraintGenerator
865878 elements.push_back (makeElement (ifStmt->getElseStmt (), elseLoc));
866879 }
867880
868- // Inject a join if we have one.
869- if (auto *join = context.ElementJoin .getPtrOrNull ())
870- elements.push_back (makeJoinElement (cs, join, locator));
871-
872881 createConjunction (elements, locator);
873882 }
874883
@@ -1010,10 +1019,6 @@ class SyntacticElementConstraintGenerator
10101019 elements.push_back (makeElement (rawCase, switchLoc));
10111020 }
10121021
1013- // Inject a join if we have one.
1014- if (auto *join = context.ElementJoin .getPtrOrNull ())
1015- elements.push_back (makeJoinElement (cs, join, switchLoc));
1016-
10171022 createConjunction (elements, switchLoc);
10181023 }
10191024
@@ -1036,10 +1041,6 @@ class SyntacticElementConstraintGenerator
10361041 for (auto *catchStmt : doStmt->getCatches ())
10371042 elements.push_back (makeElement (catchStmt, doLoc));
10381043
1039- // Inject a join if we have one.
1040- if (auto *join = context.ElementJoin .getPtrOrNull ())
1041- elements.push_back (makeJoinElement (cs, join, locator));
1042-
10431044 createConjunction (elements, doLoc);
10441045 }
10451046
@@ -1228,10 +1229,6 @@ class SyntacticElementConstraintGenerator
12281229 contextInfo.value_or (ContextualTypeInfo ()), isDiscarded));
12291230 }
12301231
1231- // Inject a join if we have one.
1232- if (auto *join = context.ElementJoin .getPtrOrNull ())
1233- elements.push_back (makeJoinElement (cs, join, locator));
1234-
12351232 createConjunction (elements, locator);
12361233 }
12371234
0 commit comments