================================================================================
basic/as2
================================================================================

amends "../snippetTest.pkl"

examples {
  ["list"] {
    List(1, 2, 3) as List<Int>
    module.catch(() -> List(1, 2, 3) as List<String>)
    module.catch(() -> Set(1, 2, 3) as List<Int>)
  }
  
  ["set"] {
    module.catch(() -> List(1, 2, 3) as Set<Int>)
    Set(1, 2, 3) as Set<Int>
    module.catch(() -> Set(1, 2, 3) as Set<String>)
  }
  
  ["map"] {
    Map("Pigeon", 42, "Barn Owl", 21) as Map<String, Int>
    module.catch(() -> Map("Pigeon", 42, "Barn Owl", 21) as Map<Int, String>)
  }
  
  ["listing"] {
    new Listing { 1; 2; 3 } as Listing<Int>
    module.catch(() -> new Listing { 1; 2; 3 } as Listing<String>)
  }
  
  ["mapping"] {
    module.catch(() -> new Listing { 1; 2; 3 } as Mapping<Int, String>)
    new Mapping { ["Pigeon"] = 42; ["Barn Owl"] = 21 } as Mapping<String, Int>
    module.catch(() -> new Mapping { ["Pigeon"] = 42; ["Barn Owl"] = 21 } as Mapping<Int, String>)
  }
  
  ["union type"] {
    42 as Int|String
    42 as String|Int
    42 as Number|String
    module.catch(() -> 42 as String|Duration)

    List(1, 2, 3) as List<String>|List<Int>
    List(1, 2, 3) as List<String|Int>
    module.catch(() -> List(1, 2, 3) as List<String>|Set<Int>)
  }
  
  ["nullable type"] {
    null as String?
    null as Map<String, Int>?
    module.catch(() -> null as Map<String, Int?>)
  }
  
  ["function type"] {
    (((x) -> x) as (Int) -> Int).apply(42)
    (((x) -> x) as (String) -> String).apply(42)
    module.catch(() -> ((x, y) -> x) as (Int) -> Int)
  }
  
  ["string literal type"] {
    "Pigeon" as "Pigeon"|"Barn Owl"
    module.catch(() -> "Pigeon" as "Piggy"|"Barn Owl")
  }
  
  ["constrained type"] {
    "abc" as String(length == 3)
    module.catch(() -> "abc" as String(length == 4))
    List("a", "b", "c") as List<String(length == 1)>
  }
}

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

(module
  (moduleHeader
    (extendsOrAmendsClause
      (stringConstant)))
  (classProperty
    (identifier)
    (objectBody
      (objectEntry
        (slStringLiteral)
        (objectBody
          (objectElement
            (methodCallExpr
              (binaryExpr
                (binaryExpr
                  (asExpr
                    (methodCallExpr
                      (identifier)
                      (argumentList
                        (intLiteral)
                        (intLiteral)
                        (intLiteral)))
                    (type
                      (qualifiedIdentifier
                        (identifier))))
                  (variableExpr
                    (identifier)))
                (moduleExpr))
              (identifier)
              (argumentList
                (functionLiteral
                  (parameterList)
                  (asExpr
                    (methodCallExpr
                      (identifier)
                      (argumentList
                        (intLiteral)
                        (intLiteral)
                        (intLiteral)))
                    (type
                      (qualifiedIdentifier
                        (identifier))
                      (typeArgumentList
                        (type
                          (qualifiedIdentifier
                            (identifier))))))))))
          (objectElement
            (methodCallExpr
              (moduleExpr)
              (identifier)
              (argumentList
                (functionLiteral
                  (parameterList)
                  (asExpr
                    (methodCallExpr
                      (identifier)
                      (argumentList
                        (intLiteral)
                        (intLiteral)
                        (intLiteral)))
                    (type
                      (qualifiedIdentifier
                        (identifier))
                      (typeArgumentList
                        (type
                          (qualifiedIdentifier
                            (identifier))))))))))))
      (objectEntry
        (slStringLiteral)
        (objectBody
          (objectElement
            (methodCallExpr
              (moduleExpr)
              (identifier)
              (argumentList
                (functionLiteral
                  (parameterList)
                  (asExpr
                    (methodCallExpr
                      (identifier)
                      (argumentList
                        (intLiteral)
                        (intLiteral)
                        (intLiteral)))
                    (type
                      (qualifiedIdentifier
                        (identifier))
                      (typeArgumentList
                        (type
                          (qualifiedIdentifier
                            (identifier))))))))))
          (objectElement
            (methodCallExpr
              (binaryExpr
                (binaryExpr
                  (asExpr
                    (methodCallExpr
                      (identifier)
                      (argumentList
                        (intLiteral)
                        (intLiteral)
                        (intLiteral)))
                    (type
                      (qualifiedIdentifier
                        (identifier))))
                  (variableExpr
                    (identifier)))
                (moduleExpr))
              (identifier)
              (argumentList
                (functionLiteral
                  (parameterList)
                  (asExpr
                    (methodCallExpr
                      (identifier)
                      (argumentList
                        (intLiteral)
                        (intLiteral)
                        (intLiteral)))
                    (type
                      (qualifiedIdentifier
                        (identifier))
                      (typeArgumentList
                        (type
                          (qualifiedIdentifier
                            (identifier))))))))))))
      (objectEntry
        (slStringLiteral)
        (objectBody
          (objectElement
            (asExpr
              (methodCallExpr
                (identifier)
                (argumentList
                  (slStringLiteral)
                  (intLiteral)
                  (slStringLiteral)
                  (intLiteral)))
              (type
                (qualifiedIdentifier
                  (identifier))
                (typeArgumentList
                  (type
                    (qualifiedIdentifier
                      (identifier)))
                  (type
                    (qualifiedIdentifier
                      (identifier)))))))
          (objectElement
            (methodCallExpr
              (moduleExpr)
              (identifier)
              (argumentList
                (functionLiteral
                  (parameterList)
                  (asExpr
                    (methodCallExpr
                      (identifier)
                      (argumentList
                        (slStringLiteral)
                        (intLiteral)
                        (slStringLiteral)
                        (intLiteral)))
                    (type
                      (qualifiedIdentifier
                        (identifier))
                      (typeArgumentList
                        (type
                          (qualifiedIdentifier
                            (identifier)))
                        (type
                          (qualifiedIdentifier
                            (identifier))))))))))))
      (objectEntry
        (slStringLiteral)
        (objectBody
          (objectElement
            (methodCallExpr
              (binaryExpr
                (binaryExpr
                  (asExpr
                    (newExpr
                      (type
                        (qualifiedIdentifier
                          (identifier)))
                      (objectBody
                        (objectElement
                          (intLiteral))
                        (objectElement
                          (intLiteral))
                        (objectElement
                          (intLiteral))))
                    (type
                      (qualifiedIdentifier
                        (identifier))))
                  (variableExpr
                    (identifier)))
                (moduleExpr))
              (identifier)
              (argumentList
                (functionLiteral
                  (parameterList)
                  (asExpr
                    (newExpr
                      (type
                        (qualifiedIdentifier
                          (identifier)))
                      (objectBody
                        (objectElement
                          (intLiteral))
                        (objectElement
                          (intLiteral))
                        (objectElement
                          (intLiteral))))
                    (type
                      (qualifiedIdentifier
                        (identifier))
                      (typeArgumentList
                        (type
                          (qualifiedIdentifier
                            (identifier))))))))))))
      (objectEntry
        (slStringLiteral)
        (objectBody
          (objectElement
            (methodCallExpr
              (moduleExpr)
              (identifier)
              (argumentList
                (functionLiteral
                  (parameterList)
                  (asExpr
                    (newExpr
                      (type
                        (qualifiedIdentifier
                          (identifier)))
                      (objectBody
                        (objectElement
                          (intLiteral))
                        (objectElement
                          (intLiteral))
                        (objectElement
                          (intLiteral))))
                    (type
                      (qualifiedIdentifier
                        (identifier))
                      (typeArgumentList
                        (type
                          (qualifiedIdentifier
                            (identifier)))
                        (type
                          (qualifiedIdentifier
                            (identifier))))))))))
          (objectElement
            (asExpr
              (newExpr
                (type
                  (qualifiedIdentifier
                    (identifier)))
                (objectBody
                  (objectEntry
                    (slStringLiteral)
                    (intLiteral))
                  (objectEntry
                    (slStringLiteral)
                    (intLiteral))))
              (type
                (qualifiedIdentifier
                  (identifier))
                (typeArgumentList
                  (type
                    (qualifiedIdentifier
                      (identifier)))
                  (type
                    (qualifiedIdentifier
                      (identifier)))))))
          (objectElement
            (methodCallExpr
              (moduleExpr)
              (identifier)
              (argumentList
                (functionLiteral
                  (parameterList)
                  (asExpr
                    (newExpr
                      (type
                        (qualifiedIdentifier
                          (identifier)))
                      (objectBody
                        (objectEntry
                          (slStringLiteral)
                          (intLiteral))
                        (objectEntry
                          (slStringLiteral)
                          (intLiteral))))
                    (type
                      (qualifiedIdentifier
                        (identifier))
                      (typeArgumentList
                        (type
                          (qualifiedIdentifier
                            (identifier)))
                        (type
                          (qualifiedIdentifier
                            (identifier))))))))))))
      (objectEntry
        (slStringLiteral)
        (objectBody
          (objectElement
            (asExpr
              (intLiteral)
              (type
                (type
                  (qualifiedIdentifier
                    (identifier)))
                (type
                  (qualifiedIdentifier
                    (identifier))))))
          (objectElement
            (asExpr
              (intLiteral)
              (type
                (type
                  (qualifiedIdentifier
                    (identifier)))
                (type
                  (qualifiedIdentifier
                    (identifier))))))
          (objectElement
            (asExpr
              (intLiteral)
              (type
                (type
                  (qualifiedIdentifier
                    (identifier)))
                (type
                  (qualifiedIdentifier
                    (identifier))))))
          (objectElement
            (methodCallExpr
              (moduleExpr)
              (identifier)
              (argumentList
                (functionLiteral
                  (parameterList)
                  (asExpr
                    (intLiteral)
                    (type
                      (type
                        (qualifiedIdentifier
                          (identifier)))
                      (type
                        (qualifiedIdentifier
                          (identifier)))))))))
          (objectElement
            (asExpr
              (binaryExpr
                (binaryExpr
                  (asExpr
                    (methodCallExpr
                      (identifier)
                      (argumentList
                        (intLiteral)
                        (intLiteral)
                        (intLiteral)))
                    (type
                      (type
                        (qualifiedIdentifier
                          (identifier))
                        (typeArgumentList
                          (type
                            (qualifiedIdentifier
                              (identifier)))))
                      (type
                        (qualifiedIdentifier
                          (identifier)))))
                  (variableExpr
                    (identifier)))
                (methodCallExpr
                  (identifier)
                  (argumentList
                    (intLiteral)
                    (intLiteral)
                    (intLiteral))))
              (type
                (qualifiedIdentifier
                  (identifier))
                (typeArgumentList
                  (type
                    (type
                      (qualifiedIdentifier
                        (identifier)))
                    (type
                      (qualifiedIdentifier
                        (identifier))))))))
          (objectElement
            (methodCallExpr
              (moduleExpr)
              (identifier)
              (argumentList
                (functionLiteral
                  (parameterList)
                  (asExpr
                    (methodCallExpr
                      (identifier)
                      (argumentList
                        (intLiteral)
                        (intLiteral)
                        (intLiteral)))
                    (type
                      (type
                        (qualifiedIdentifier
                          (identifier))
                        (typeArgumentList
                          (type
                            (qualifiedIdentifier
                              (identifier)))))
                      (type
                        (qualifiedIdentifier
                          (identifier))
                        (typeArgumentList
                          (type
                            (qualifiedIdentifier
                              (identifier)))))))))))))
      (objectEntry
        (slStringLiteral)
        (objectBody
          (objectElement
            (asExpr
              (nullLiteral)
              (type
                (type
                  (qualifiedIdentifier
                    (identifier))))))
          (objectElement
            (asExpr
              (nullLiteral)
              (type
                (type
                  (qualifiedIdentifier
                    (identifier))
                  (typeArgumentList
                    (type
                      (qualifiedIdentifier
                        (identifier)))
                    (type
                      (qualifiedIdentifier
                        (identifier))))))))
          (objectElement
            (methodCallExpr
              (moduleExpr)
              (identifier)
              (argumentList
                (functionLiteral
                  (parameterList)
                  (asExpr
                    (nullLiteral)
                    (type
                      (qualifiedIdentifier
                        (identifier))
                      (typeArgumentList
                        (type
                          (qualifiedIdentifier
                            (identifier)))
                        (type
                          (type
                            (qualifiedIdentifier
                              (identifier)))))))))))))
      (objectEntry
        (slStringLiteral)
        (objectBody
          (objectElement
            (methodCallExpr
              (parenthesizedExpr
                (asExpr
                  (parenthesizedExpr
                    (functionLiteral
                      (parameterList
                        (typedIdentifier
                          (identifier)))
                      (variableExpr
                        (identifier))))
                  (type
                    (type
                      (qualifiedIdentifier
                        (identifier)))
                    (type
                      (qualifiedIdentifier
                        (identifier))))))
              (identifier)
              (argumentList
                (intLiteral))))
          (objectElement
            (methodCallExpr
              (parenthesizedExpr
                (asExpr
                  (parenthesizedExpr
                    (functionLiteral
                      (parameterList
                        (typedIdentifier
                          (identifier)))
                      (variableExpr
                        (identifier))))
                  (type
                    (type
                      (qualifiedIdentifier
                        (identifier)))
                    (type
                      (qualifiedIdentifier
                        (identifier))))))
              (identifier)
              (argumentList
                (intLiteral))))
          (objectElement
            (methodCallExpr
              (moduleExpr)
              (identifier)
              (argumentList
                (functionLiteral
                  (parameterList)
                  (asExpr
                    (parenthesizedExpr
                      (functionLiteral
                        (parameterList
                          (typedIdentifier
                            (identifier))
                          (typedIdentifier
                            (identifier)))
                        (variableExpr
                          (identifier))))
                    (type
                      (type
                        (qualifiedIdentifier
                          (identifier)))
                      (type
                        (qualifiedIdentifier
                          (identifier)))))))))))
      (objectEntry
        (slStringLiteral)
        (objectBody
          (objectElement
            (asExpr
              (slStringLiteral)
              (type
                (type
                  (stringConstant))
                (type
                  (stringConstant)))))
          (objectElement
            (methodCallExpr
              (moduleExpr)
              (identifier)
              (argumentList
                (functionLiteral
                  (parameterList)
                  (asExpr
                    (slStringLiteral)
                    (type
                      (type
                        (stringConstant))
                      (type
                        (stringConstant))))))))))
      (objectEntry
        (slStringLiteral)
        (objectBody
          (objectElement
            (asExpr
              (slStringLiteral)
              (type
                (qualifiedIdentifier
                  (identifier)))))
          (objectElement
            (parenthesizedExpr
              (binaryExpr
                (variableExpr
                  (identifier))
                (intLiteral))))
          (objectElement
            (methodCallExpr
              (moduleExpr)
              (identifier)
              (argumentList
                (functionLiteral
                  (parameterList)
                  (asExpr
                    (slStringLiteral)
                    (type
                      (type
                        (qualifiedIdentifier
                          (identifier)))
                      (binaryExpr
                        (variableExpr
                          (identifier))
                        (intLiteral))))))))
          (objectElement
            (asExpr
              (methodCallExpr
                (identifier)
                (argumentList
                  (slStringLiteral)
                  (slStringLiteral)
                  (slStringLiteral)))
              (type
                (qualifiedIdentifier
                  (identifier))
                (typeArgumentList
                  (type
                    (type
                      (qualifiedIdentifier
                        (identifier)))
                    (binaryExpr
                      (variableExpr
                        (identifier))
                      (intLiteral))))))))))))
