Skip to content

Commit 4ba8d4c

Browse files
committed
[ConstraintSystem] Augment solution application target to support expression patterns
1 parent 50d0508 commit 4ba8d4c

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

include/swift/Sema/ConstraintSystem.h

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1715,6 +1715,13 @@ class SolutionApplicationTarget {
17151715
ContextualTypePurpose contextualPurpose,
17161716
TypeLoc convertType, bool isDiscarded);
17171717

1718+
SolutionApplicationTarget(Expr *expr, DeclContext *dc, ExprPattern *pattern,
1719+
Type patternType)
1720+
: SolutionApplicationTarget(expr, dc, CTP_ExprPattern, patternType,
1721+
/*isDiscarded=*/false) {
1722+
setPattern(pattern);
1723+
}
1724+
17181725
SolutionApplicationTarget(AnyFunctionRef fn)
17191726
: SolutionApplicationTarget(fn, fn.getBody()) { }
17201727

@@ -1800,6 +1807,12 @@ class SolutionApplicationTarget {
18001807
static SolutionApplicationTarget forPropertyWrapperInitializer(
18011808
VarDecl *wrappedVar, DeclContext *dc, Expr *initializer);
18021809

1810+
static SolutionApplicationTarget forExprPattern(Expr *expr, DeclContext *dc,
1811+
ExprPattern *pattern,
1812+
Type patternTy) {
1813+
return {expr, dc, pattern, patternTy};
1814+
}
1815+
18031816
Expr *getAsExpr() const {
18041817
switch (kind) {
18051818
case Kind::expression:
@@ -1902,6 +1915,12 @@ class SolutionApplicationTarget {
19021915
return expression.pattern;
19031916
}
19041917

1918+
ExprPattern *getExprPattern() const {
1919+
assert(kind == Kind::expression);
1920+
assert(expression.contextualPurpose == CTP_ExprPattern);
1921+
return cast<ExprPattern>(expression.pattern);
1922+
}
1923+
19051924
/// For a pattern initialization target, retrieve the contextual pattern.
19061925
ContextualPattern getContextualPattern() const;
19071926

@@ -2022,7 +2041,8 @@ class SolutionApplicationTarget {
20222041
assert(kind == Kind::expression);
20232042
assert(expression.contextualPurpose == CTP_Initialization ||
20242043
expression.contextualPurpose == CTP_ForEachStmt ||
2025-
expression.contextualPurpose == CTP_ForEachSequence);
2044+
expression.contextualPurpose == CTP_ForEachSequence ||
2045+
expression.contextualPurpose == CTP_ExprPattern);
20262046
expression.pattern = pattern;
20272047
}
20282048

0 commit comments

Comments
 (0)