================================================================================
listings/typeCheck
================================================================================

import "pkl:test"

hidden x1: Listing<String> = new {
  "pigeon"
  42
  "barn owl"
}

hidden x2: Listing<String(length > 3)> = new {
  "pigeon"
  "bob"
}

hidden x3: Listing<String>(!isEmpty)

res1 = test.catch(() -> x1)
res2 = test.catch(() -> x2)
res3 = test.catch(() -> x3)

hidden x4: Listing = new {
  throw("element unnecessarily evaluated")
}

hidden x5: Listing<Any> = new {
  throw("element unnecessarily evaluated")
}

hidden x6: Listing<unknown> = new {
  throw("element unnecessarily evaluated")
}

hidden x7 = new Listing {
  throw("element unnecessarily evaluated")
  42
  throw("element unnecessarily evaluated")
}

res4 = x4.length == 1
res5 = x5.length == 1
res6 = x6.length == 1
res7 = x7[1] == 42

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

(module
  (importClause
    (stringConstant))
  (classProperty
    (modifier)
    (identifier)
    (typeAnnotation
      (type
        (qualifiedIdentifier
          (identifier))
        (typeArgumentList
          (type
            (qualifiedIdentifier
              (identifier))))))
    (newExpr
      (objectBody
        (objectElement
          (slStringLiteral))
        (objectElement
          (intLiteral))
        (objectElement
          (slStringLiteral)))))
  (classProperty
    (modifier)
    (identifier)
    (typeAnnotation
      (type
        (qualifiedIdentifier
          (identifier))
        (typeArgumentList
          (type
            (type
              (qualifiedIdentifier
                (identifier)))
            (binaryExpr
              (variableExpr
                (identifier))
              (intLiteral))))))
    (newExpr
      (objectBody
        (objectElement
          (slStringLiteral))
        (objectElement
          (slStringLiteral)))))
  (classProperty
    (modifier)
    (identifier)
    (typeAnnotation
      (type
        (type
          (qualifiedIdentifier
            (identifier))
          (typeArgumentList
            (type
              (qualifiedIdentifier
                (identifier)))))
        (unaryExpr
          (variableExpr
            (identifier))))))
  (classProperty
    (identifier)
    (methodCallExpr
      (variableExpr
        (identifier))
      (identifier)
      (argumentList
        (functionLiteral
          (parameterList)
          (variableExpr
            (identifier))))))
  (classProperty
    (identifier)
    (methodCallExpr
      (variableExpr
        (identifier))
      (identifier)
      (argumentList
        (functionLiteral
          (parameterList)
          (variableExpr
            (identifier))))))
  (classProperty
    (identifier)
    (methodCallExpr
      (variableExpr
        (identifier))
      (identifier)
      (argumentList
        (functionLiteral
          (parameterList)
          (variableExpr
            (identifier))))))
  (classProperty
    (modifier)
    (identifier)
    (typeAnnotation
      (type
        (qualifiedIdentifier
          (identifier))))
    (newExpr
      (objectBody
        (objectElement
          (throwExpr
            (parenthesizedExpr
              (slStringLiteral)))))))
  (classProperty
    (modifier)
    (identifier)
    (typeAnnotation
      (type
        (qualifiedIdentifier
          (identifier))
        (typeArgumentList
          (type
            (qualifiedIdentifier
              (identifier))))))
    (newExpr
      (objectBody
        (objectElement
          (throwExpr
            (parenthesizedExpr
              (slStringLiteral)))))))
  (classProperty
    (modifier)
    (identifier)
    (typeAnnotation
      (type
        (qualifiedIdentifier
          (identifier))
        (typeArgumentList
          (type))))
    (newExpr
      (objectBody
        (objectElement
          (throwExpr
            (parenthesizedExpr
              (slStringLiteral)))))))
  (classProperty
    (modifier)
    (identifier)
    (newExpr
      (type
        (qualifiedIdentifier
          (identifier)))
      (objectBody
        (objectElement
          (throwExpr
            (parenthesizedExpr
              (slStringLiteral))))
        (objectElement
          (intLiteral))
        (objectElement
          (throwExpr
            (parenthesizedExpr
              (slStringLiteral)))))))
  (classProperty
    (identifier)
    (binaryExpr
      (propertyCallExpr
        (variableExpr
          (identifier))
        (identifier))
      (intLiteral)))
  (classProperty
    (identifier)
    (binaryExpr
      (propertyCallExpr
        (variableExpr
          (identifier))
        (identifier))
      (intLiteral)))
  (classProperty
    (identifier)
    (binaryExpr
      (propertyCallExpr
        (variableExpr
          (identifier))
        (identifier))
      (intLiteral)))
  (classProperty
    (identifier)
    (binaryExpr
      (subscriptExpr
        (variableExpr
          (identifier))
        (intLiteral))
      (intLiteral))))
