================================================================================
generators/forGeneratorLexicalScope
================================================================================

amends ".../snippetTest.pkl"

examples {
  ["accessing for-bound variable from a lambda in a nested for"] {
    new {
      for (l1 in List("a", "b")) {
        for (l2 in List("a", "d").filter((i) -> i == l1)) {
          l1 + l2
        }
      }
    }
  }
  ["accessing for-bound variable from a lambda in a nested when"] {
    new {
      for (l1 in List("a", "b")) {
        when (!List("a", "d").filter((i) -> i == l1).isEmpty) {
          l1
        }
      }
    }
  }
  ["accessing for-bound variable from an expression inside a nested for"] {
    new {
      for (_n in List(1, 2, 3)) {
        for (x in new App { n = _n }.list) {
          x
        }
      }
    }
  }
}

local class App {
  n: Int
  list = List(n, n, n)
}

--------------------------------------------------------------------------------

(module
  (moduleHeader
    (extendsOrAmendsClause
      (stringConstant)))
  (classProperty
    (identifier)
    (objectBody
      (objectEntry
        (slStringLiteral)
        (objectBody
          (objectElement
            (newExpr
              (objectBody
                (forGenerator
                  (typedIdentifier
                    (identifier))
                  (methodCallExpr
                    (identifier)
                    (argumentList
                      (slStringLiteral)
                      (slStringLiteral)))
                  (objectBody
                    (forGenerator
                      (typedIdentifier
                        (identifier))
                      (methodCallExpr
                        (methodCallExpr
                          (identifier)
                          (argumentList
                            (slStringLiteral)
                            (slStringLiteral)))
                        (identifier)
                        (argumentList
                          (functionLiteral
                            (parameterList
                              (typedIdentifier
                                (identifier)))
                            (binaryExpr
                              (variableExpr
                                (identifier))
                              (variableExpr
                                (identifier))))))
                      (objectBody
                        (objectElement
                          (binaryExpr
                            (variableExpr
                              (identifier))
                            (variableExpr
                              (identifier)))))))))))))
      (objectEntry
        (slStringLiteral)
        (objectBody
          (objectElement
            (newExpr
              (objectBody
                (forGenerator
                  (typedIdentifier
                    (identifier))
                  (methodCallExpr
                    (identifier)
                    (argumentList
                      (slStringLiteral)
                      (slStringLiteral)))
                  (objectBody
                    (whenGenerator
                      (propertyCallExpr
                        (methodCallExpr
                          (unaryExpr
                            (methodCallExpr
                              (identifier)
                              (argumentList
                                (slStringLiteral)
                                (slStringLiteral))))
                          (identifier)
                          (argumentList
                            (functionLiteral
                              (parameterList
                                (typedIdentifier
                                  (identifier)))
                              (binaryExpr
                                (variableExpr
                                  (identifier))
                                (variableExpr
                                  (identifier))))))
                        (identifier))
                      (objectBody
                        (objectElement
                          (variableExpr
                            (identifier))))))))))))
      (objectEntry
        (slStringLiteral)
        (objectBody
          (objectElement
            (newExpr
              (objectBody
                (forGenerator
                  (typedIdentifier
                    (identifier))
                  (methodCallExpr
                    (identifier)
                    (argumentList
                      (intLiteral)
                      (intLiteral)
                      (intLiteral)))
                  (objectBody
                    (forGenerator
                      (typedIdentifier
                        (identifier))
                      (propertyCallExpr
                        (newExpr
                          (type
                            (qualifiedIdentifier
                              (identifier)))
                          (objectBody
                            (objectProperty
                              (identifier)
                              (variableExpr
                                (identifier)))))
                        (identifier))
                      (objectBody
                        (objectElement
                          (variableExpr
                            (identifier))))))))))))))
  (clazz
    (modifier)
    (identifier)
    (classBody
      (classProperty
        (identifier)
        (typeAnnotation
          (type
            (qualifiedIdentifier
              (identifier)))))
      (classProperty
        (identifier)
        (methodCallExpr
          (identifier)
          (argumentList
            (variableExpr
              (identifier))
            (variableExpr
              (identifier))
            (variableExpr
              (identifier))))))))
