swift
5a19c6d4 - cherry-pick tf-1144 fix from master PR

Commit
5 years ago
cherry-pick tf-1144 fix from master PR **Problem** When you have a pattern binding expression in the REPL that binds a tuple to an expression involving a closure (see tests in this PR for examples), you get this assertion failure: ``` swift-ide-test: /usr/local/google/home/marcrasi/swift-base-master/swift/lib/Sema/TypeCheckConstraints.cpp:1342: bool (anonymous namespace)::PreCheckExpression::walkToClosureExprPre(swift::ClosureExpr *): Assertion `(closure->getParent() == DC || closure->getParent()->isChildContextOf(DC)) && "Decl context isn't correct"' failed. ``` **Explanation** The [REPL rewrites the pattern binding](https://github.com/apple/swift/blob/37655db07af36d46913ace2feea4b9f36ac090cc/lib/Sema/TypeCheckREPL.cpp#L390). The rewrite introduces a new PatternBindingInitializer DeclContext that contains the initializer expression, but the rewrite does not update the closures in the initializer expression to set their parents to the new DeclContext. **This PR's solution** Update the closures in the initializer expression to set their parents to the new DeclContext.
Author
Marc Rasi
Committer
Marc Rasi
Parents
  • lib/AST
    • File
      Decl.cpp
  • test
    • IDE
      • File
        complete_repl_pattern_binding_with_closure.swift
    • Interpreter
      • File
        repl.swift