@@ -968,6 +968,7 @@ class SolutionApplicationTargetsKey {
968
968
stmtCondElement,
969
969
expr,
970
970
stmt,
971
+ pattern,
971
972
patternBindingEntry,
972
973
varDecl,
973
974
};
@@ -982,6 +983,8 @@ class SolutionApplicationTargetsKey {
982
983
983
984
const Stmt *stmt;
984
985
986
+ const Pattern *pattern;
987
+
985
988
struct PatternBindingEntry {
986
989
const PatternBindingDecl *patternBinding;
987
990
unsigned index;
@@ -1011,6 +1014,11 @@ class SolutionApplicationTargetsKey {
1011
1014
storage.stmt = stmt;
1012
1015
}
1013
1016
1017
+ SolutionApplicationTargetsKey (const Pattern *pattern) {
1018
+ kind = Kind::pattern;
1019
+ storage.pattern = pattern;
1020
+ }
1021
+
1014
1022
SolutionApplicationTargetsKey (
1015
1023
const PatternBindingDecl *patternBinding, unsigned index) {
1016
1024
kind = Kind::patternBindingEntry;
@@ -1042,6 +1050,9 @@ class SolutionApplicationTargetsKey {
1042
1050
case Kind::stmt:
1043
1051
return lhs.storage .stmt == rhs.storage .stmt ;
1044
1052
1053
+ case Kind::pattern:
1054
+ return lhs.storage .pattern == rhs.storage .pattern ;
1055
+
1045
1056
case Kind::patternBindingEntry:
1046
1057
return (lhs.storage .patternBindingEntry .patternBinding
1047
1058
== rhs.storage .patternBindingEntry .patternBinding ) &&
@@ -1083,6 +1094,11 @@ class SolutionApplicationTargetsKey {
1083
1094
DenseMapInfo<unsigned >::getHashValue (static_cast <unsigned >(kind)),
1084
1095
DenseMapInfo<void *>::getHashValue (storage.stmt ));
1085
1096
1097
+ case Kind::pattern:
1098
+ return hash_combine (
1099
+ DenseMapInfo<unsigned >::getHashValue (static_cast <unsigned >(kind)),
1100
+ DenseMapInfo<void *>::getHashValue (storage.pattern ));
1101
+
1086
1102
case Kind::patternBindingEntry:
1087
1103
return hash_combine (
1088
1104
DenseMapInfo<unsigned >::getHashValue (static_cast <unsigned >(kind)),
@@ -1701,6 +1717,13 @@ class SolutionApplicationTarget {
1701
1717
ContextualTypePurpose contextualPurpose,
1702
1718
TypeLoc convertType, bool isDiscarded);
1703
1719
1720
+ SolutionApplicationTarget (Expr *expr, DeclContext *dc, ExprPattern *pattern,
1721
+ Type patternType)
1722
+ : SolutionApplicationTarget(expr, dc, CTP_ExprPattern, patternType,
1723
+ /* isDiscarded=*/ false ) {
1724
+ setPattern (pattern);
1725
+ }
1726
+
1704
1727
SolutionApplicationTarget (AnyFunctionRef fn)
1705
1728
: SolutionApplicationTarget(fn, fn.getBody()) { }
1706
1729
@@ -1786,6 +1809,12 @@ class SolutionApplicationTarget {
1786
1809
static SolutionApplicationTarget forPropertyWrapperInitializer (
1787
1810
VarDecl *wrappedVar, DeclContext *dc, Expr *initializer);
1788
1811
1812
+ static SolutionApplicationTarget forExprPattern (Expr *expr, DeclContext *dc,
1813
+ ExprPattern *pattern,
1814
+ Type patternTy) {
1815
+ return {expr, dc, pattern, patternTy};
1816
+ }
1817
+
1789
1818
Expr *getAsExpr () const {
1790
1819
switch (kind) {
1791
1820
case Kind::expression:
@@ -1888,6 +1917,12 @@ class SolutionApplicationTarget {
1888
1917
return expression.pattern ;
1889
1918
}
1890
1919
1920
+ ExprPattern *getExprPattern () const {
1921
+ assert (kind == Kind::expression);
1922
+ assert (expression.contextualPurpose == CTP_ExprPattern);
1923
+ return cast<ExprPattern>(expression.pattern );
1924
+ }
1925
+
1891
1926
// / For a pattern initialization target, retrieve the contextual pattern.
1892
1927
ContextualPattern getContextualPattern () const ;
1893
1928
@@ -2008,7 +2043,8 @@ class SolutionApplicationTarget {
2008
2043
assert (kind == Kind::expression);
2009
2044
assert (expression.contextualPurpose == CTP_Initialization ||
2010
2045
expression.contextualPurpose == CTP_ForEachStmt ||
2011
- expression.contextualPurpose == CTP_ForEachSequence);
2046
+ expression.contextualPurpose == CTP_ForEachSequence ||
2047
+ expression.contextualPurpose == CTP_ExprPattern);
2012
2048
expression.pattern = pattern;
2013
2049
}
2014
2050
@@ -5107,6 +5143,15 @@ class ConstraintSystem {
5107
5143
= FreeTypeVariableBinding::Disallow);
5108
5144
5109
5145
public:
5146
+ // / Pre-check the target, validating any types that occur in it
5147
+ // / and folding sequence expressions.
5148
+ // /
5149
+ // / \param replaceInvalidRefsWithErrors Indicates whether it's allowed
5150
+ // / to replace any discovered invalid member references with `ErrorExpr`.
5151
+ static bool preCheckTarget (SolutionApplicationTarget &target,
5152
+ bool replaceInvalidRefsWithErrors,
5153
+ bool leaveClosureBodiesUnchecked);
5154
+
5110
5155
// / Pre-check the expression, validating any types that occur in the
5111
5156
// / expression and folding sequence expressions.
5112
5157
// /
0 commit comments