26
26
#include " llvm/ADT/Optional.h"
27
27
#include " llvm/ADT/STLExtras.h"
28
28
#include " llvm/ADT/SmallVector.h"
29
+ #include " llvm/Support/SaveAndRestore.h"
29
30
#include " llvm/Support/raw_ostream.h"
30
31
#include < memory>
31
32
@@ -772,6 +773,8 @@ class ConjunctionStep : public BindingStep<ConjunctionElementProducer> {
772
773
class SolverSnapshot {
773
774
ConstraintSystem &CS;
774
775
776
+ Optional<llvm::SaveAndRestore<DeclContext *>> DC = None;
777
+
775
778
llvm::SetVector<TypeVariableType *> TypeVars;
776
779
ConstraintList Constraints;
777
780
@@ -782,8 +785,15 @@ class ConjunctionStep : public BindingStep<ConjunctionElementProducer> {
782
785
std::unique_ptr<Scope> IsolationScope = nullptr ;
783
786
784
787
public:
785
- SolverSnapshot (ConstraintSystem &cs)
788
+ SolverSnapshot (ConstraintSystem &cs, Constraint *conjunction )
786
789
: CS(cs), TypeVars(std::move(cs.TypeVariables)) {
790
+ auto *locator = conjunction->getLocator ();
791
+ // If this conjunction represents a closure, we need to
792
+ // switch declaration context over to it.
793
+ if (locator->directlyAt <ClosureExpr>()) {
794
+ DC.emplace (CS.DC , castToExpr<ClosureExpr>(locator->getAnchor ()));
795
+ }
796
+
787
797
auto &CG = CS.getConstraintGraph ();
788
798
// Remove all of the current inactive constraints.
789
799
Constraints.splice (Constraints.end (), CS.InactiveConstraints );
@@ -827,6 +837,7 @@ class ConjunctionStep : public BindingStep<ConjunctionElementProducer> {
827
837
828
838
private:
829
839
void restore () {
840
+ DC.reset ();
830
841
CS.TypeVariables = std::move (TypeVars);
831
842
CS.InactiveConstraints .splice (CS.InactiveConstraints .end (), Constraints);
832
843
}
@@ -881,7 +892,7 @@ class ConjunctionStep : public BindingStep<ConjunctionElementProducer> {
881
892
882
893
// Make a snapshot of the constraint system state before conjunction.
883
894
if (conjunction->isIsolated ())
884
- Snapshot.emplace (cs);
895
+ Snapshot.emplace (cs, conjunction );
885
896
}
886
897
887
898
~ConjunctionStep () override {
0 commit comments