@@ -82,6 +82,43 @@ void getSolutionSpecificVarTypes(
8282 const constraints::Solution &S,
8383 llvm::SmallDenseMap<const VarDecl *, Type> &Result);
8484
85+ // / While this RAII is alive the interface types of the variables defined in
86+ // / \c SolutionSpecificVarTypes are temporarily set to the types in the map.
87+ // / Afterwards, their types are restored.
88+ struct WithSolutionSpecificVarTypesRAII {
89+ llvm::SmallDenseMap<const VarDecl *, Type> RestoreVarTypes;
90+
91+ WithSolutionSpecificVarTypesRAII (
92+ llvm::SmallDenseMap<const VarDecl *, Type> SolutionSpecificVarTypes) {
93+ for (auto SolutionVarType : SolutionSpecificVarTypes) {
94+ if (SolutionVarType.first ->hasInterfaceType ()) {
95+ RestoreVarTypes[SolutionVarType.first ] =
96+ SolutionVarType.first ->getInterfaceType ();
97+ } else {
98+ RestoreVarTypes[SolutionVarType.first ] = Type ();
99+ }
100+ if (!SolutionVarType.second ->hasArchetype ()) {
101+ setInterfaceType (const_cast <VarDecl *>(SolutionVarType.first ),
102+ SolutionVarType.second );
103+ } else {
104+ setInterfaceType (const_cast <VarDecl *>(SolutionVarType.first ),
105+ ErrorType::get (SolutionVarType.second ));
106+ }
107+ }
108+ }
109+
110+ ~WithSolutionSpecificVarTypesRAII () {
111+ for (auto Var : RestoreVarTypes) {
112+ setInterfaceType (const_cast <VarDecl *>(Var.first ), Var.second );
113+ }
114+ }
115+
116+ private:
117+ // / Sets the interface type of \p VD, similar to \c VD->setInterfaceType
118+ // / but also allows resetting the interface type of \p VD to null.
119+ static void setInterfaceType (VarDecl *VD, Type Ty);
120+ };
121+
85122// / Whether the given completion expression is the only expression in its
86123// / containing closure or function body and its value is implicitly returned.
87124// /
0 commit comments