@@ -281,11 +281,10 @@ static bool isViableElement(ASTNode element,
281
281
using ElementInfo = std::tuple<ASTNode, ContextualTypeInfo,
282
282
/* isDiscarded=*/ bool , ConstraintLocator *>;
283
283
284
- static void createConjunction (ConstraintSystem &cs,
284
+ static void createConjunction (ConstraintSystem &cs, DeclContext *dc,
285
285
ArrayRef<ElementInfo> elements,
286
- ConstraintLocator *locator,
287
- bool isIsolated = false ,
288
- ArrayRef<TypeVariableType *> extraTypeVars = {}) {
286
+ ConstraintLocator *locator, bool isIsolated,
287
+ ArrayRef<TypeVariableType *> extraTypeVars) {
289
288
SmallVector<Constraint *, 4 > constraints;
290
289
SmallVector<TypeVariableType *, 2 > referencedVars;
291
290
referencedVars.append (extraTypeVars.begin (), extraTypeVars.end ());
@@ -335,7 +334,7 @@ static void createConjunction(ConstraintSystem &cs,
335
334
isIsolated = true ;
336
335
}
337
336
338
- VarRefCollector paramCollector (cs);
337
+ TypeVarRefCollector paramCollector (cs, dc, locator );
339
338
340
339
// Whether we're doing completion, and the conjunction is for a
341
340
// SingleValueStmtExpr, or one of its braces.
@@ -517,6 +516,13 @@ class SyntacticElementConstraintGenerator
517
516
ConstraintLocator *locator)
518
517
: cs(cs), context(context), locator(locator) {}
519
518
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
+
520
526
void visitExprPattern (ExprPattern *EP) {
521
527
auto target = SyntacticElementTarget::forExprPattern (EP);
522
528
@@ -859,7 +865,7 @@ class SyntacticElementConstraintGenerator
859
865
if (auto *join = context.ElementJoin .getPtrOrNull ())
860
866
elements.push_back (makeJoinElement (cs, join, locator));
861
867
862
- createConjunction (cs, elements, locator);
868
+ createConjunction (elements, locator);
863
869
}
864
870
865
871
void visitGuardStmt (GuardStmt *guardStmt) {
@@ -868,7 +874,7 @@ class SyntacticElementConstraintGenerator
868
874
visitStmtCondition (guardStmt, elements, locator);
869
875
elements.push_back (makeElement (guardStmt->getBody (), locator));
870
876
871
- createConjunction (cs, elements, locator);
877
+ createConjunction (elements, locator);
872
878
}
873
879
874
880
void visitWhileStmt (WhileStmt *whileStmt) {
@@ -877,16 +883,15 @@ class SyntacticElementConstraintGenerator
877
883
visitStmtCondition (whileStmt, elements, locator);
878
884
elements.push_back (makeElement (whileStmt->getBody (), locator));
879
885
880
- createConjunction (cs, elements, locator);
886
+ createConjunction (elements, locator);
881
887
}
882
888
883
889
void visitDoStmt (DoStmt *doStmt) {
884
890
visitBraceStmt (doStmt->getBody ());
885
891
}
886
892
887
893
void visitRepeatWhileStmt (RepeatWhileStmt *repeatWhileStmt) {
888
- createConjunction (cs,
889
- {makeElement (repeatWhileStmt->getCond (),
894
+ createConjunction ({makeElement (repeatWhileStmt->getCond (),
890
895
cs.getConstraintLocator (
891
896
locator, ConstraintLocator::Condition),
892
897
getContextForCondition ()),
@@ -895,8 +900,7 @@ class SyntacticElementConstraintGenerator
895
900
}
896
901
897
902
void visitPoundAssertStmt (PoundAssertStmt *poundAssertStmt) {
898
- createConjunction (cs,
899
- {makeElement (poundAssertStmt->getCondition (),
903
+ createConjunction ({makeElement (poundAssertStmt->getCondition (),
900
904
cs.getConstraintLocator (
901
905
locator, ConstraintLocator::Condition),
902
906
getContextForCondition ())},
@@ -913,12 +917,10 @@ class SyntacticElementConstraintGenerator
913
917
auto *errorExpr = throwStmt->getSubExpr ();
914
918
915
919
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})},
922
924
locator);
923
925
}
924
926
@@ -939,12 +941,10 @@ class SyntacticElementConstraintGenerator
939
941
auto *selfExpr = discardStmt->getSubExpr ();
940
942
941
943
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})},
948
948
locator);
949
949
}
950
950
@@ -962,7 +962,7 @@ class SyntacticElementConstraintGenerator
962
962
// Body of the `for-in` loop.
963
963
elements.push_back (makeElement (forEachStmt->getBody (), stmtLoc));
964
964
965
- createConjunction (cs, elements, locator);
965
+ createConjunction (elements, locator);
966
966
}
967
967
968
968
void visitSwitchStmt (SwitchStmt *switchStmt) {
@@ -990,7 +990,7 @@ class SyntacticElementConstraintGenerator
990
990
if (auto *join = context.ElementJoin .getPtrOrNull ())
991
991
elements.push_back (makeJoinElement (cs, join, switchLoc));
992
992
993
- createConjunction (cs, elements, switchLoc);
993
+ createConjunction (elements, switchLoc);
994
994
}
995
995
996
996
void visitDoCatchStmt (DoCatchStmt *doStmt) {
@@ -1007,7 +1007,7 @@ class SyntacticElementConstraintGenerator
1007
1007
for (auto *catchStmt : doStmt->getCatches ())
1008
1008
elements.push_back (makeElement (catchStmt, doLoc));
1009
1009
1010
- createConjunction (cs, elements, doLoc);
1010
+ createConjunction (elements, doLoc);
1011
1011
}
1012
1012
1013
1013
void visitCaseStmt (CaseStmt *caseStmt) {
@@ -1040,7 +1040,7 @@ class SyntacticElementConstraintGenerator
1040
1040
1041
1041
elements.push_back (makeElement (caseStmt->getBody (), caseLoc));
1042
1042
1043
- createConjunction (cs, elements, caseLoc);
1043
+ createConjunction (elements, caseLoc);
1044
1044
}
1045
1045
1046
1046
void visitBraceStmt (BraceStmt *braceStmt) {
@@ -1127,7 +1127,7 @@ class SyntacticElementConstraintGenerator
1127
1127
// want to type-check captures to make sure that the context
1128
1128
// is valid.
1129
1129
if (captureList)
1130
- createConjunction (cs, elements, locator);
1130
+ createConjunction (elements, locator);
1131
1131
1132
1132
return ;
1133
1133
}
@@ -1195,7 +1195,7 @@ class SyntacticElementConstraintGenerator
1195
1195
contextInfo.value_or (ContextualTypeInfo ()), isDiscarded));
1196
1196
}
1197
1197
1198
- createConjunction (cs, elements, locator);
1198
+ createConjunction (elements, locator);
1199
1199
}
1200
1200
1201
1201
void visitReturnStmt (ReturnStmt *returnStmt) {
@@ -1282,7 +1282,7 @@ class SyntacticElementConstraintGenerator
1282
1282
auto resultElt = makeElement (resultExpr, locator,
1283
1283
contextInfo.value_or (ContextualTypeInfo ()),
1284
1284
/* isDiscarded=*/ false );
1285
- createConjunction (cs, {resultElt}, locator);
1285
+ createConjunction ({resultElt}, locator);
1286
1286
}
1287
1287
1288
1288
ContextualTypeInfo getContextualResultInfo () const {
@@ -1520,6 +1520,9 @@ bool ConstraintSystem::generateConstraints(SingleValueStmtExpr *E) {
1520
1520
1521
1521
void ConstraintSystem::generateConstraints (ArrayRef<ExprPattern *> exprPatterns,
1522
1522
ConstraintLocatorBuilder locator) {
1523
+ assert (!exprPatterns.empty ());
1524
+ auto *DC = exprPatterns.front ()->getDeclContext ();
1525
+
1523
1526
// Form a conjunction of ExprPattern elements, isolated from the rest of the
1524
1527
// pattern.
1525
1528
SmallVector<ElementInfo> elements;
@@ -1532,7 +1535,7 @@ void ConstraintSystem::generateConstraints(ArrayRef<ExprPattern *> exprPatterns,
1532
1535
elements.push_back (makeElement (EP, getConstraintLocator (EP), context));
1533
1536
}
1534
1537
auto *loc = getConstraintLocator (locator);
1535
- createConjunction (*this , elements, loc, /* isIsolated*/ true ,
1538
+ createConjunction (*this , DC, elements, loc, /* isIsolated*/ true ,
1536
1539
referencedTypeVars);
1537
1540
}
1538
1541
0 commit comments