@@ -281,11 +281,10 @@ static bool isViableElement(ASTNode element,
281281using ElementInfo = std::tuple<ASTNode, ContextualTypeInfo,
282282 /* isDiscarded=*/ bool , ConstraintLocator *>;
283283
284- static void createConjunction (ConstraintSystem &cs,
284+ static void createConjunction (ConstraintSystem &cs, DeclContext *dc,
285285 ArrayRef<ElementInfo> elements,
286- ConstraintLocator *locator,
287- bool isIsolated = false ,
288- ArrayRef<TypeVariableType *> extraTypeVars = {}) {
286+ ConstraintLocator *locator, bool isIsolated,
287+ ArrayRef<TypeVariableType *> extraTypeVars) {
289288 SmallVector<Constraint *, 4 > constraints;
290289 SmallVector<TypeVariableType *, 2 > referencedVars;
291290 referencedVars.append (extraTypeVars.begin (), extraTypeVars.end ());
@@ -335,7 +334,7 @@ static void createConjunction(ConstraintSystem &cs,
335334 isIsolated = true ;
336335 }
337336
338- VarRefCollector paramCollector (cs);
337+ TypeVarRefCollector paramCollector (cs, dc, locator );
339338
340339 // Whether we're doing completion, and the conjunction is for a
341340 // SingleValueStmtExpr, or one of its braces.
@@ -517,6 +516,13 @@ class SyntacticElementConstraintGenerator
517516 ConstraintLocator *locator)
518517 : cs(cs), context(context), locator(locator) {}
519518
519+ void createConjunction (ArrayRef<ElementInfo> elements,
520+ ConstraintLocator *locator, bool isIsolated = false ,
521+ ArrayRef<TypeVariableType *> extraTypeVars = {}) {
522+ ::createConjunction (cs, context.getAsDeclContext(), elements, locator,
523+ isIsolated, extraTypeVars);
524+ }
525+
520526 void visitExprPattern (ExprPattern *EP) {
521527 auto target = SyntacticElementTarget::forExprPattern (EP);
522528
@@ -859,7 +865,7 @@ class SyntacticElementConstraintGenerator
859865 if (auto *join = context.ElementJoin .getPtrOrNull ())
860866 elements.push_back (makeJoinElement (cs, join, locator));
861867
862- createConjunction (cs, elements, locator);
868+ createConjunction (elements, locator);
863869 }
864870
865871 void visitGuardStmt (GuardStmt *guardStmt) {
@@ -868,7 +874,7 @@ class SyntacticElementConstraintGenerator
868874 visitStmtCondition (guardStmt, elements, locator);
869875 elements.push_back (makeElement (guardStmt->getBody (), locator));
870876
871- createConjunction (cs, elements, locator);
877+ createConjunction (elements, locator);
872878 }
873879
874880 void visitWhileStmt (WhileStmt *whileStmt) {
@@ -877,16 +883,15 @@ class SyntacticElementConstraintGenerator
877883 visitStmtCondition (whileStmt, elements, locator);
878884 elements.push_back (makeElement (whileStmt->getBody (), locator));
879885
880- createConjunction (cs, elements, locator);
886+ createConjunction (elements, locator);
881887 }
882888
883889 void visitDoStmt (DoStmt *doStmt) {
884890 visitBraceStmt (doStmt->getBody ());
885891 }
886892
887893 void visitRepeatWhileStmt (RepeatWhileStmt *repeatWhileStmt) {
888- createConjunction (cs,
889- {makeElement (repeatWhileStmt->getCond (),
894+ createConjunction ({makeElement (repeatWhileStmt->getCond (),
890895 cs.getConstraintLocator (
891896 locator, ConstraintLocator::Condition),
892897 getContextForCondition ()),
@@ -895,8 +900,7 @@ class SyntacticElementConstraintGenerator
895900 }
896901
897902 void visitPoundAssertStmt (PoundAssertStmt *poundAssertStmt) {
898- createConjunction (cs,
899- {makeElement (poundAssertStmt->getCondition (),
903+ createConjunction ({makeElement (poundAssertStmt->getCondition (),
900904 cs.getConstraintLocator (
901905 locator, ConstraintLocator::Condition),
902906 getContextForCondition ())},
@@ -913,12 +917,10 @@ class SyntacticElementConstraintGenerator
913917 auto *errorExpr = throwStmt->getSubExpr ();
914918
915919 createConjunction (
916- cs,
917- {makeElement (
918- errorExpr,
919- cs.getConstraintLocator (
920- locator, LocatorPathElt::SyntacticElement (errorExpr)),
921- {errType, CTP_ThrowStmt})},
920+ {makeElement (errorExpr,
921+ cs.getConstraintLocator (
922+ locator, LocatorPathElt::SyntacticElement (errorExpr)),
923+ {errType, CTP_ThrowStmt})},
922924 locator);
923925 }
924926
@@ -939,12 +941,10 @@ class SyntacticElementConstraintGenerator
939941 auto *selfExpr = discardStmt->getSubExpr ();
940942
941943 createConjunction (
942- cs,
943- {makeElement (
944- selfExpr,
945- cs.getConstraintLocator (
946- locator, LocatorPathElt::SyntacticElement (selfExpr)),
947- {nominalType, CTP_DiscardStmt})},
944+ {makeElement (selfExpr,
945+ cs.getConstraintLocator (
946+ locator, LocatorPathElt::SyntacticElement (selfExpr)),
947+ {nominalType, CTP_DiscardStmt})},
948948 locator);
949949 }
950950
@@ -962,7 +962,7 @@ class SyntacticElementConstraintGenerator
962962 // Body of the `for-in` loop.
963963 elements.push_back (makeElement (forEachStmt->getBody (), stmtLoc));
964964
965- createConjunction (cs, elements, locator);
965+ createConjunction (elements, locator);
966966 }
967967
968968 void visitSwitchStmt (SwitchStmt *switchStmt) {
@@ -990,7 +990,7 @@ class SyntacticElementConstraintGenerator
990990 if (auto *join = context.ElementJoin .getPtrOrNull ())
991991 elements.push_back (makeJoinElement (cs, join, switchLoc));
992992
993- createConjunction (cs, elements, switchLoc);
993+ createConjunction (elements, switchLoc);
994994 }
995995
996996 void visitDoCatchStmt (DoCatchStmt *doStmt) {
@@ -1007,7 +1007,7 @@ class SyntacticElementConstraintGenerator
10071007 for (auto *catchStmt : doStmt->getCatches ())
10081008 elements.push_back (makeElement (catchStmt, doLoc));
10091009
1010- createConjunction (cs, elements, doLoc);
1010+ createConjunction (elements, doLoc);
10111011 }
10121012
10131013 void visitCaseStmt (CaseStmt *caseStmt) {
@@ -1040,7 +1040,7 @@ class SyntacticElementConstraintGenerator
10401040
10411041 elements.push_back (makeElement (caseStmt->getBody (), caseLoc));
10421042
1043- createConjunction (cs, elements, caseLoc);
1043+ createConjunction (elements, caseLoc);
10441044 }
10451045
10461046 void visitBraceStmt (BraceStmt *braceStmt) {
@@ -1127,7 +1127,7 @@ class SyntacticElementConstraintGenerator
11271127 // want to type-check captures to make sure that the context
11281128 // is valid.
11291129 if (captureList)
1130- createConjunction (cs, elements, locator);
1130+ createConjunction (elements, locator);
11311131
11321132 return ;
11331133 }
@@ -1195,7 +1195,7 @@ class SyntacticElementConstraintGenerator
11951195 contextInfo.value_or (ContextualTypeInfo ()), isDiscarded));
11961196 }
11971197
1198- createConjunction (cs, elements, locator);
1198+ createConjunction (elements, locator);
11991199 }
12001200
12011201 void visitReturnStmt (ReturnStmt *returnStmt) {
@@ -1282,7 +1282,7 @@ class SyntacticElementConstraintGenerator
12821282 auto resultElt = makeElement (resultExpr, locator,
12831283 contextInfo.value_or (ContextualTypeInfo ()),
12841284 /* isDiscarded=*/ false );
1285- createConjunction (cs, {resultElt}, locator);
1285+ createConjunction ({resultElt}, locator);
12861286 }
12871287
12881288 ContextualTypeInfo getContextualResultInfo () const {
@@ -1520,6 +1520,9 @@ bool ConstraintSystem::generateConstraints(SingleValueStmtExpr *E) {
15201520
15211521void ConstraintSystem::generateConstraints (ArrayRef<ExprPattern *> exprPatterns,
15221522 ConstraintLocatorBuilder locator) {
1523+ assert (!exprPatterns.empty ());
1524+ auto *DC = exprPatterns.front ()->getDeclContext ();
1525+
15231526 // Form a conjunction of ExprPattern elements, isolated from the rest of the
15241527 // pattern.
15251528 SmallVector<ElementInfo> elements;
@@ -1532,7 +1535,7 @@ void ConstraintSystem::generateConstraints(ArrayRef<ExprPattern *> exprPatterns,
15321535 elements.push_back (makeElement (EP, getConstraintLocator (EP), context));
15331536 }
15341537 auto *loc = getConstraintLocator (locator);
1535- createConjunction (*this , elements, loc, /* isIsolated*/ true ,
1538+ createConjunction (*this , DC, elements, loc, /* isIsolated*/ true ,
15361539 referencedTypeVars);
15371540}
15381541
0 commit comments