@@ -1559,7 +1559,7 @@ class SolutionApplicationTarget {
15591559 stmtCondition,
15601560 caseLabelItem,
15611561 patternBinding,
1562- uninitializedWrappedVar ,
1562+ uninitializedVar ,
15631563 } kind;
15641564
15651565private:
@@ -1631,9 +1631,15 @@ class SolutionApplicationTarget {
16311631 DeclContext *dc;
16321632 } caseLabelItem;
16331633
1634- PatternBindingDecl *patternBinding;
1634+ struct {
1635+ // / Index into pattern binding declaration (if any).
1636+ unsigned index;
1637+ PointerUnion<VarDecl *, Pattern *> declaration;
1638+ // / Type associated with the declaration.
1639+ Type type;
1640+ } uninitializedVar;
16351641
1636- VarDecl *uninitializedWrappedVar ;
1642+ PatternBindingDecl *patternBinding ;
16371643 };
16381644
16391645 // If the pattern contains a single variable that has an attached
@@ -1679,9 +1685,18 @@ class SolutionApplicationTarget {
16791685 this ->patternBinding = patternBinding;
16801686 }
16811687
1682- SolutionApplicationTarget (VarDecl *wrappedVar) {
1683- kind = Kind::uninitializedWrappedVar;
1684- this ->uninitializedWrappedVar = wrappedVar;
1688+ SolutionApplicationTarget (VarDecl *uninitializedWrappedVar)
1689+ : kind(Kind::uninitializedVar) {
1690+ if (auto *PDB = uninitializedWrappedVar->getParentPatternBinding ()) {
1691+ patternBinding = PDB;
1692+ uninitializedVar.index =
1693+ PDB->getPatternEntryIndexForVarDecl (uninitializedWrappedVar);
1694+ } else {
1695+ uninitializedVar.index = 0 ;
1696+ }
1697+
1698+ uninitializedVar.declaration = uninitializedWrappedVar;
1699+ uninitializedVar.type = Type ();
16851700 }
16861701
16871702 // / Form a target for the initialization of a pattern from an expression.
@@ -1703,8 +1718,10 @@ class SolutionApplicationTarget {
17031718
17041719 // / Form a target for a property with an attached property wrapper that is
17051720 // / initialized out-of-line.
1706- static SolutionApplicationTarget forUninitializedWrappedVar (
1707- VarDecl *wrappedVar);
1721+ static SolutionApplicationTarget
1722+ forUninitializedWrappedVar (VarDecl *wrappedVar) {
1723+ return {wrappedVar};
1724+ }
17081725
17091726 // / Form a target for a synthesized property wrapper initializer.
17101727 static SolutionApplicationTarget forPropertyWrapperInitializer (
@@ -1719,7 +1736,7 @@ class SolutionApplicationTarget {
17191736 case Kind::stmtCondition:
17201737 case Kind::caseLabelItem:
17211738 case Kind::patternBinding:
1722- case Kind::uninitializedWrappedVar :
1739+ case Kind::uninitializedVar :
17231740 return nullptr ;
17241741 }
17251742 llvm_unreachable (" invalid expression type" );
@@ -1742,8 +1759,13 @@ class SolutionApplicationTarget {
17421759 case Kind::patternBinding:
17431760 return patternBinding->getDeclContext ();
17441761
1745- case Kind::uninitializedWrappedVar:
1746- return uninitializedWrappedVar->getDeclContext ();
1762+ case Kind::uninitializedVar: {
1763+ if (auto *wrappedVar =
1764+ uninitializedVar.declaration .dyn_cast <VarDecl *>())
1765+ return wrappedVar->getDeclContext ();
1766+
1767+ return patternBinding->getInitContext (uninitializedVar.index );
1768+ }
17471769 }
17481770 llvm_unreachable (" invalid decl context type" );
17491771 }
@@ -1915,7 +1937,7 @@ class SolutionApplicationTarget {
19151937 case Kind::stmtCondition:
19161938 case Kind::caseLabelItem:
19171939 case Kind::patternBinding:
1918- case Kind::uninitializedWrappedVar :
1940+ case Kind::uninitializedVar :
19191941 return None;
19201942
19211943 case Kind::function:
@@ -1930,7 +1952,7 @@ class SolutionApplicationTarget {
19301952 case Kind::function:
19311953 case Kind::caseLabelItem:
19321954 case Kind::patternBinding:
1933- case Kind::uninitializedWrappedVar :
1955+ case Kind::uninitializedVar :
19341956 return None;
19351957
19361958 case Kind::stmtCondition:
@@ -1945,7 +1967,7 @@ class SolutionApplicationTarget {
19451967 case Kind::function:
19461968 case Kind::stmtCondition:
19471969 case Kind::patternBinding:
1948- case Kind::uninitializedWrappedVar :
1970+ case Kind::uninitializedVar :
19491971 return None;
19501972
19511973 case Kind::caseLabelItem:
@@ -1960,7 +1982,7 @@ class SolutionApplicationTarget {
19601982 case Kind::function:
19611983 case Kind::stmtCondition:
19621984 case Kind::caseLabelItem:
1963- case Kind::uninitializedWrappedVar :
1985+ case Kind::uninitializedVar :
19641986 return nullptr ;
19651987
19661988 case Kind::patternBinding:
@@ -1978,8 +2000,8 @@ class SolutionApplicationTarget {
19782000 case Kind::patternBinding:
19792001 return nullptr ;
19802002
1981- case Kind::uninitializedWrappedVar :
1982- return uninitializedWrappedVar ;
2003+ case Kind::uninitializedVar :
2004+ return uninitializedVar. declaration . dyn_cast <VarDecl *>() ;
19832005 }
19842006 llvm_unreachable (" invalid case label type" );
19852007 }
@@ -2013,8 +2035,13 @@ class SolutionApplicationTarget {
20132035 case Kind::patternBinding:
20142036 return patternBinding->getSourceRange ();
20152037
2016- case Kind::uninitializedWrappedVar:
2017- return uninitializedWrappedVar->getSourceRange ();
2038+ case Kind::uninitializedVar: {
2039+ if (auto *wrappedVar =
2040+ uninitializedVar.declaration .dyn_cast <VarDecl *>()) {
2041+ return wrappedVar->getSourceRange ();
2042+ }
2043+ return uninitializedVar.declaration .get <Pattern *>()->getSourceRange ();
2044+ }
20182045 }
20192046 llvm_unreachable (" invalid target type" );
20202047 }
@@ -2037,8 +2064,13 @@ class SolutionApplicationTarget {
20372064 case Kind::patternBinding:
20382065 return patternBinding->getLoc ();
20392066
2040- case Kind::uninitializedWrappedVar:
2041- return uninitializedWrappedVar->getLoc ();
2067+ case Kind::uninitializedVar: {
2068+ if (auto *wrappedVar =
2069+ uninitializedVar.declaration .dyn_cast <VarDecl *>()) {
2070+ return wrappedVar->getLoc ();
2071+ }
2072+ return uninitializedVar.declaration .get <Pattern *>()->getLoc ();
2073+ }
20422074 }
20432075 llvm_unreachable (" invalid target type" );
20442076 }
0 commit comments