================================================================================
basic/newType
================================================================================

import "pkl:test"

class Person {
  name: String
}

res1 = new Person { name = "Pigeon" }

res2 {
  prop = new Person { name = "Pigeon" }

  new Person { name = "Pigeon" }

  ["Pigeon"] = new Person { name = "Pigeon" }
}

res3 = new Listing {
  new Person { name = "Pigeon" }
}
res4 = (res3) {
  [0] = new Person { name = "Pigeon" }
}

res5 = new Listing<Person> {
  new Person { name = "Pigeon" }
  new { name = "Barn Owl" }
}
res6 = (res5) {
  [0] = new { name = "Pigeon2" }
  [1] { name = "Barn Owl2" }
}

res7 = new Mapping<String, Person> {
  ["Pigeon"] = new Person { name = "Pigeon" }
  ["Barn Owl"] = new { name = "Barn Owl" }
  ["Parrot"] { name = "Parrot" }
}
res8 = (res7) {
  ["Pigeon"] = new { name = "Pigeon2" }
  ["Barn Owl"] { name = "Barn Owl2" }
}

local mixin1 = new Mixin { name = "Other" }
res9 = new Person { name = "Pigeon" } |> mixin1
res9b = test.catch(() -> mixin1.apply(new Person {}, new Person {}))

local mixin2 = (mixin1) { name = "Override" }
res9c = new Person { name = "Pigeon" } |> mixin2
res9d = test.catch(() -> mixin2.apply(new Person {}, new Person {}))

local mixin3 = new Mixin<Person> { name = "Other" }
res10 = new Person { name = "Pigeon" } |> mixin3
res10b = test.catch(() -> mixin3.apply(new Person {}, new Person {}))
res10c = test.catch(() -> mixin3.apply(1))

local mixin4 = (mixin3) { name = "Override" }
res10d = new Person { name = "Pigeon" } |> mixin4
res10e = test.catch(() -> mixin4.apply(new Person {}, new Person {}))
res10f = test.catch(() -> mixin4.apply(1))

typealias Person2 = Person
res11 = new Person2 { name = "Pigeon" }

typealias PersonMapping = Mapping<String, Person>
res12 = new PersonMapping {
  ["Pigeon"] = new Person { name = "Pigeon" }
  ["Barn Owl"] = new { name = "Barn Owl" }
  ["Parrot"] { name = "Parrot" }
}

res13 = new Person? { name = "Pigeon" }

res14 = new Person|String { name = "Pigeon" }

res15 = test.catch(() -> new Int {})

res16 = test.catch(() -> new Set {})

res17 = test.catch(() -> new String|Person {})

res18 = test.catch(() -> new "foo" {})

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

(module
  (importClause
    (stringConstant))
  (clazz
    (identifier)
    (classBody
      (classProperty
        (identifier)
        (typeAnnotation
          (type
            (qualifiedIdentifier
              (identifier)))))))
  (classProperty
    (identifier)
    (newExpr
      (type
        (qualifiedIdentifier
          (identifier)))
      (objectBody
        (objectProperty
          (identifier)
          (slStringLiteral)))))
  (classProperty
    (identifier)
    (objectBody
      (objectProperty
        (identifier)
        (newExpr
          (type
            (qualifiedIdentifier
              (identifier)))
          (objectBody
            (objectProperty
              (identifier)
              (slStringLiteral)))))
      (objectElement
        (newExpr
          (type
            (qualifiedIdentifier
              (identifier)))
          (objectBody
            (objectProperty
              (identifier)
              (slStringLiteral)))))
      (objectEntry
        (slStringLiteral)
        (newExpr
          (type
            (qualifiedIdentifier
              (identifier)))
          (objectBody
            (objectProperty
              (identifier)
              (slStringLiteral)))))))
  (classProperty
    (identifier)
    (newExpr
      (type
        (qualifiedIdentifier
          (identifier)))
      (objectBody
        (objectElement
          (newExpr
            (type
              (qualifiedIdentifier
                (identifier)))
            (objectBody
              (objectProperty
                (identifier)
                (slStringLiteral))))))))
  (classProperty
    (identifier)
    (objectLiteral
      (parenthesizedExpr
        (variableExpr
          (identifier)))
      (objectBody
        (objectEntry
          (intLiteral)
          (newExpr
            (type
              (qualifiedIdentifier
                (identifier)))
            (objectBody
              (objectProperty
                (identifier)
                (slStringLiteral))))))))
  (classProperty
    (identifier)
    (newExpr
      (type
        (qualifiedIdentifier
          (identifier))
        (typeArgumentList
          (type
            (qualifiedIdentifier
              (identifier)))))
      (objectBody
        (objectElement
          (newExpr
            (type
              (qualifiedIdentifier
                (identifier)))
            (objectBody
              (objectProperty
                (identifier)
                (slStringLiteral)))))
        (objectElement
          (newExpr
            (objectBody
              (objectProperty
                (identifier)
                (slStringLiteral))))))))
  (classProperty
    (identifier)
    (objectLiteral
      (parenthesizedExpr
        (variableExpr
          (identifier)))
      (objectBody
        (objectEntry
          (intLiteral)
          (newExpr
            (objectBody
              (objectProperty
                (identifier)
                (slStringLiteral)))))
        (objectEntry
          (intLiteral)
          (objectBody
            (objectProperty
              (identifier)
              (slStringLiteral)))))))
  (classProperty
    (identifier)
    (newExpr
      (type
        (qualifiedIdentifier
          (identifier))
        (typeArgumentList
          (type
            (qualifiedIdentifier
              (identifier)))
          (type
            (qualifiedIdentifier
              (identifier)))))
      (objectBody
        (objectEntry
          (slStringLiteral)
          (newExpr
            (type
              (qualifiedIdentifier
                (identifier)))
            (objectBody
              (objectProperty
                (identifier)
                (slStringLiteral)))))
        (objectEntry
          (slStringLiteral)
          (newExpr
            (objectBody
              (objectProperty
                (identifier)
                (slStringLiteral)))))
        (objectEntry
          (slStringLiteral)
          (objectBody
            (objectProperty
              (identifier)
              (slStringLiteral)))))))
  (classProperty
    (identifier)
    (objectLiteral
      (parenthesizedExpr
        (variableExpr
          (identifier)))
      (objectBody
        (objectEntry
          (slStringLiteral)
          (newExpr
            (objectBody
              (objectProperty
                (identifier)
                (slStringLiteral)))))
        (objectEntry
          (slStringLiteral)
          (objectBody
            (objectProperty
              (identifier)
              (slStringLiteral)))))))
  (classProperty
    (modifier)
    (identifier)
    (newExpr
      (type
        (qualifiedIdentifier
          (identifier)))
      (objectBody
        (objectProperty
          (identifier)
          (slStringLiteral)))))
  (classProperty
    (identifier)
    (binaryExpr
      (newExpr
        (type
          (qualifiedIdentifier
            (identifier)))
        (objectBody
          (objectProperty
            (identifier)
            (slStringLiteral))))
      (variableExpr
        (identifier))))
  (classProperty
    (identifier)
    (methodCallExpr
      (variableExpr
        (identifier))
      (identifier)
      (argumentList
        (functionLiteral
          (parameterList)
          (methodCallExpr
            (variableExpr
              (identifier))
            (identifier)
            (argumentList
              (newExpr
                (type
                  (qualifiedIdentifier
                    (identifier)))
                (objectBody))
              (newExpr
                (type
                  (qualifiedIdentifier
                    (identifier)))
                (objectBody))))))))
  (classProperty
    (modifier)
    (identifier)
    (objectLiteral
      (parenthesizedExpr
        (variableExpr
          (identifier)))
      (objectBody
        (objectProperty
          (identifier)
          (slStringLiteral)))))
  (classProperty
    (identifier)
    (binaryExpr
      (newExpr
        (type
          (qualifiedIdentifier
            (identifier)))
        (objectBody
          (objectProperty
            (identifier)
            (slStringLiteral))))
      (variableExpr
        (identifier))))
  (classProperty
    (identifier)
    (methodCallExpr
      (variableExpr
        (identifier))
      (identifier)
      (argumentList
        (functionLiteral
          (parameterList)
          (methodCallExpr
            (variableExpr
              (identifier))
            (identifier)
            (argumentList
              (newExpr
                (type
                  (qualifiedIdentifier
                    (identifier)))
                (objectBody))
              (newExpr
                (type
                  (qualifiedIdentifier
                    (identifier)))
                (objectBody))))))))
  (classProperty
    (modifier)
    (identifier)
    (newExpr
      (type
        (qualifiedIdentifier
          (identifier))
        (typeArgumentList
          (type
            (qualifiedIdentifier
              (identifier)))))
      (objectBody
        (objectProperty
          (identifier)
          (slStringLiteral)))))
  (classProperty
    (identifier)
    (binaryExpr
      (newExpr
        (type
          (qualifiedIdentifier
            (identifier)))
        (objectBody
          (objectProperty
            (identifier)
            (slStringLiteral))))
      (variableExpr
        (identifier))))
  (classProperty
    (identifier)
    (methodCallExpr
      (variableExpr
        (identifier))
      (identifier)
      (argumentList
        (functionLiteral
          (parameterList)
          (methodCallExpr
            (variableExpr
              (identifier))
            (identifier)
            (argumentList
              (newExpr
                (type
                  (qualifiedIdentifier
                    (identifier)))
                (objectBody))
              (newExpr
                (type
                  (qualifiedIdentifier
                    (identifier)))
                (objectBody))))))))
  (classProperty
    (identifier)
    (methodCallExpr
      (variableExpr
        (identifier))
      (identifier)
      (argumentList
        (functionLiteral
          (parameterList)
          (methodCallExpr
            (variableExpr
              (identifier))
            (identifier)
            (argumentList
              (intLiteral)))))))
  (classProperty
    (modifier)
    (identifier)
    (objectLiteral
      (parenthesizedExpr
        (variableExpr
          (identifier)))
      (objectBody
        (objectProperty
          (identifier)
          (slStringLiteral)))))
  (classProperty
    (identifier)
    (binaryExpr
      (newExpr
        (type
          (qualifiedIdentifier
            (identifier)))
        (objectBody
          (objectProperty
            (identifier)
            (slStringLiteral))))
      (variableExpr
        (identifier))))
  (classProperty
    (identifier)
    (methodCallExpr
      (variableExpr
        (identifier))
      (identifier)
      (argumentList
        (functionLiteral
          (parameterList)
          (methodCallExpr
            (variableExpr
              (identifier))
            (identifier)
            (argumentList
              (newExpr
                (type
                  (qualifiedIdentifier
                    (identifier)))
                (objectBody))
              (newExpr
                (type
                  (qualifiedIdentifier
                    (identifier)))
                (objectBody))))))))
  (classProperty
    (identifier)
    (methodCallExpr
      (variableExpr
        (identifier))
      (identifier)
      (argumentList
        (functionLiteral
          (parameterList)
          (methodCallExpr
            (variableExpr
              (identifier))
            (identifier)
            (argumentList
              (intLiteral)))))))
  (typeAlias
    (identifier)
    (type
      (qualifiedIdentifier
        (identifier))))
  (classProperty
    (identifier)
    (newExpr
      (type
        (qualifiedIdentifier
          (identifier)))
      (objectBody
        (objectProperty
          (identifier)
          (slStringLiteral)))))
  (typeAlias
    (identifier)
    (type
      (qualifiedIdentifier
        (identifier))
      (typeArgumentList
        (type
          (qualifiedIdentifier
            (identifier)))
        (type
          (qualifiedIdentifier
            (identifier))))))
  (classProperty
    (identifier)
    (newExpr
      (type
        (qualifiedIdentifier
          (identifier)))
      (objectBody
        (objectEntry
          (slStringLiteral)
          (newExpr
            (type
              (qualifiedIdentifier
                (identifier)))
            (objectBody
              (objectProperty
                (identifier)
                (slStringLiteral)))))
        (objectEntry
          (slStringLiteral)
          (newExpr
            (objectBody
              (objectProperty
                (identifier)
                (slStringLiteral)))))
        (objectEntry
          (slStringLiteral)
          (objectBody
            (objectProperty
              (identifier)
              (slStringLiteral)))))))
  (classProperty
    (identifier)
    (newExpr
      (type
        (type
          (qualifiedIdentifier
            (identifier))))
      (objectBody
        (objectProperty
          (identifier)
          (slStringLiteral)))))
  (classProperty
    (identifier)
    (newExpr
      (type
        (type
          (qualifiedIdentifier
            (identifier)))
        (type
          (qualifiedIdentifier
            (identifier))))
      (objectBody
        (objectProperty
          (identifier)
          (slStringLiteral)))))
  (classProperty
    (identifier)
    (methodCallExpr
      (variableExpr
        (identifier))
      (identifier)
      (argumentList
        (functionLiteral
          (parameterList)
          (newExpr
            (type
              (qualifiedIdentifier
                (identifier)))
            (objectBody))))))
  (classProperty
    (identifier)
    (methodCallExpr
      (variableExpr
        (identifier))
      (identifier)
      (argumentList
        (functionLiteral
          (parameterList)
          (newExpr
            (type
              (qualifiedIdentifier
                (identifier)))
            (objectBody))))))
  (classProperty
    (identifier)
    (methodCallExpr
      (variableExpr
        (identifier))
      (identifier)
      (argumentList
        (functionLiteral
          (parameterList)
          (newExpr
            (type
              (type
                (qualifiedIdentifier
                  (identifier)))
              (type
                (qualifiedIdentifier
                  (identifier))))
            (objectBody))))))
  (classProperty
    (identifier)
    (methodCallExpr
      (variableExpr
        (identifier))
      (identifier)
      (argumentList
        (functionLiteral
          (parameterList)
          (newExpr
            (type
              (stringConstant))
            (objectBody)))))))
