================================================================================
listings/listing2
================================================================================

import "pkl:test"

function id(x) = x

local x = new Listing {
  "one"
  "two"
  "three"
}

res1 = (x) {
  [1] = "updated two"
}

res1a = (x) {
  [id(1)] = id("updated two")
}

res2 = (x) {
  [0] = "updated one"
  [1] = "updated two"
  [2] = "updated three"
}

res2a = (x) {
  [id(0)] = id("updated one")
  [1] = id("updated two")
  [id(2)] = "updated three"
}

res3 = (x) {
  [2] = "updated three"
  [0] = "updated one"
  [1] = "updated two"
}

res3a = (x) {
  [id(2)] = id("updated three")
  [0] = id("updated one")
  [id(1)] = "updated two"
}

res4 = (x) {
  [0] = "updated one"
  "four"
  [1] = "updated two"
  "five"
  [2] = "updated three"
  "six"
}

res4a = (x) {
  [id(0)] = id("updated one")
  id("four")
  [1] = id("updated two")
  "five"
  [id(2)] = "updated three"
  id("six")
}

res5 = test.catch(() -> (x) { [3] = "four" })
res5a = test.catch(() -> (x) { [3] = id("four") })
res5b = test.catch(() -> (x) { [id(3)] = "four" })
res5c = test.catch(() -> (x) { [id(3)] = id("four") })

res6 = test.catch(() -> (x) { "four"; [3] = "updated four" })
res6a = test.catch(() -> (x) { id("four"); [id(3)] = id("updated four") })

res7 = test.catch(() -> (x) { [-1] = "value" })
res7a = test.catch(() -> (x) { [id(-1)] = id("value") })

res8 = test.catch(() -> (x) { ["wrong type"] = "value" })
res8a = test.catch(() -> (x) { [id("wrong type")] = id("value") })

res9 = test.catch(() -> new Listing { foo = "bar" })
res10 = test.catch(() -> (x) { foo = "foo" })
res11 = test.catch(() -> new Listing { "one"; foo = "foo" })
res12 = test.catch(() -> (x) { "four"; foo = "foo" })
res12a = test.catch(() -> (x) { id("four"); foo = "foo" })
res13 = test.catch(() -> (x) { [1] = "updated two"; foo = "foo" })
res13a = test.catch(() -> (x) { [id(1)] = id("updated two"); foo = "foo" })
res14 = test.catch(() -> (x) { "four"; [1] = "updated two"; foo = "foo" })
res14a = test.catch(() -> (x) { id("four"); [id(1)] = id("updated two"); foo = "foo" })

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

(module
  (importClause
    (stringConstant))
  (classMethod
    (methodHeader
      (identifier)
      (parameterList
        (typedIdentifier
          (identifier))))
    (variableExpr
      (identifier)))
  (classProperty
    (modifier)
    (identifier)
    (newExpr
      (type
        (qualifiedIdentifier
          (identifier)))
      (objectBody
        (objectElement
          (slStringLiteral))
        (objectElement
          (slStringLiteral))
        (objectElement
          (slStringLiteral)))))
  (classProperty
    (identifier)
    (objectLiteral
      (parenthesizedExpr
        (variableExpr
          (identifier)))
      (objectBody
        (objectEntry
          (intLiteral)
          (slStringLiteral)))))
  (classProperty
    (identifier)
    (objectLiteral
      (parenthesizedExpr
        (variableExpr
          (identifier)))
      (objectBody
        (objectEntry
          (methodCallExpr
            (identifier)
            (argumentList
              (intLiteral)))
          (methodCallExpr
            (identifier)
            (argumentList
              (slStringLiteral)))))))
  (classProperty
    (identifier)
    (objectLiteral
      (parenthesizedExpr
        (variableExpr
          (identifier)))
      (objectBody
        (objectEntry
          (intLiteral)
          (slStringLiteral))
        (objectEntry
          (intLiteral)
          (slStringLiteral))
        (objectEntry
          (intLiteral)
          (slStringLiteral)))))
  (classProperty
    (identifier)
    (objectLiteral
      (parenthesizedExpr
        (variableExpr
          (identifier)))
      (objectBody
        (objectEntry
          (methodCallExpr
            (identifier)
            (argumentList
              (intLiteral)))
          (methodCallExpr
            (identifier)
            (argumentList
              (slStringLiteral))))
        (objectEntry
          (intLiteral)
          (methodCallExpr
            (identifier)
            (argumentList
              (slStringLiteral))))
        (objectEntry
          (methodCallExpr
            (identifier)
            (argumentList
              (intLiteral)))
          (slStringLiteral)))))
  (classProperty
    (identifier)
    (objectLiteral
      (parenthesizedExpr
        (variableExpr
          (identifier)))
      (objectBody
        (objectEntry
          (intLiteral)
          (slStringLiteral))
        (objectEntry
          (intLiteral)
          (slStringLiteral))
        (objectEntry
          (intLiteral)
          (slStringLiteral)))))
  (classProperty
    (identifier)
    (objectLiteral
      (parenthesizedExpr
        (variableExpr
          (identifier)))
      (objectBody
        (objectEntry
          (methodCallExpr
            (identifier)
            (argumentList
              (intLiteral)))
          (methodCallExpr
            (identifier)
            (argumentList
              (slStringLiteral))))
        (objectEntry
          (intLiteral)
          (methodCallExpr
            (identifier)
            (argumentList
              (slStringLiteral))))
        (objectEntry
          (methodCallExpr
            (identifier)
            (argumentList
              (intLiteral)))
          (slStringLiteral)))))
  (classProperty
    (identifier)
    (objectLiteral
      (parenthesizedExpr
        (variableExpr
          (identifier)))
      (objectBody
        (objectEntry
          (intLiteral)
          (slStringLiteral))
        (objectElement
          (slStringLiteral))
        (objectEntry
          (intLiteral)
          (slStringLiteral))
        (objectElement
          (slStringLiteral))
        (objectEntry
          (intLiteral)
          (slStringLiteral))
        (objectElement
          (slStringLiteral)))))
  (classProperty
    (identifier)
    (objectLiteral
      (parenthesizedExpr
        (variableExpr
          (identifier)))
      (objectBody
        (objectEntry
          (methodCallExpr
            (identifier)
            (argumentList
              (intLiteral)))
          (methodCallExpr
            (identifier)
            (argumentList
              (slStringLiteral))))
        (objectElement
          (methodCallExpr
            (identifier)
            (argumentList
              (slStringLiteral))))
        (objectEntry
          (intLiteral)
          (methodCallExpr
            (identifier)
            (argumentList
              (slStringLiteral))))
        (objectElement
          (slStringLiteral))
        (objectEntry
          (methodCallExpr
            (identifier)
            (argumentList
              (intLiteral)))
          (slStringLiteral))
        (objectElement
          (methodCallExpr
            (identifier)
            (argumentList
              (slStringLiteral)))))))
  (classProperty
    (identifier)
    (methodCallExpr
      (variableExpr
        (identifier))
      (identifier)
      (argumentList
        (functionLiteral
          (parameterList)
          (objectLiteral
            (parenthesizedExpr
              (variableExpr
                (identifier)))
            (objectBody
              (objectEntry
                (intLiteral)
                (slStringLiteral))))))))
  (classProperty
    (identifier)
    (methodCallExpr
      (variableExpr
        (identifier))
      (identifier)
      (argumentList
        (functionLiteral
          (parameterList)
          (objectLiteral
            (parenthesizedExpr
              (variableExpr
                (identifier)))
            (objectBody
              (objectEntry
                (intLiteral)
                (methodCallExpr
                  (identifier)
                  (argumentList
                    (slStringLiteral))))))))))
  (classProperty
    (identifier)
    (methodCallExpr
      (variableExpr
        (identifier))
      (identifier)
      (argumentList
        (functionLiteral
          (parameterList)
          (objectLiteral
            (parenthesizedExpr
              (variableExpr
                (identifier)))
            (objectBody
              (objectEntry
                (methodCallExpr
                  (identifier)
                  (argumentList
                    (intLiteral)))
                (slStringLiteral))))))))
  (classProperty
    (identifier)
    (methodCallExpr
      (variableExpr
        (identifier))
      (identifier)
      (argumentList
        (functionLiteral
          (parameterList)
          (objectLiteral
            (parenthesizedExpr
              (variableExpr
                (identifier)))
            (objectBody
              (objectEntry
                (methodCallExpr
                  (identifier)
                  (argumentList
                    (intLiteral)))
                (methodCallExpr
                  (identifier)
                  (argumentList
                    (slStringLiteral))))))))))
  (classProperty
    (identifier)
    (methodCallExpr
      (variableExpr
        (identifier))
      (identifier)
      (argumentList
        (functionLiteral
          (parameterList)
          (objectLiteral
            (parenthesizedExpr
              (variableExpr
                (identifier)))
            (objectBody
              (objectElement
                (slStringLiteral))
              (objectEntry
                (intLiteral)
                (slStringLiteral))))))))
  (classProperty
    (identifier)
    (methodCallExpr
      (variableExpr
        (identifier))
      (identifier)
      (argumentList
        (functionLiteral
          (parameterList)
          (objectLiteral
            (parenthesizedExpr
              (variableExpr
                (identifier)))
            (objectBody
              (objectElement
                (methodCallExpr
                  (identifier)
                  (argumentList
                    (slStringLiteral))))
              (objectEntry
                (methodCallExpr
                  (identifier)
                  (argumentList
                    (intLiteral)))
                (methodCallExpr
                  (identifier)
                  (argumentList
                    (slStringLiteral))))))))))
  (classProperty
    (identifier)
    (methodCallExpr
      (variableExpr
        (identifier))
      (identifier)
      (argumentList
        (functionLiteral
          (parameterList)
          (objectLiteral
            (parenthesizedExpr
              (variableExpr
                (identifier)))
            (objectBody
              (objectEntry
                (unaryExpr
                  (intLiteral))
                (slStringLiteral))))))))
  (classProperty
    (identifier)
    (methodCallExpr
      (variableExpr
        (identifier))
      (identifier)
      (argumentList
        (functionLiteral
          (parameterList)
          (objectLiteral
            (parenthesizedExpr
              (variableExpr
                (identifier)))
            (objectBody
              (objectEntry
                (methodCallExpr
                  (identifier)
                  (argumentList
                    (unaryExpr
                      (intLiteral))))
                (methodCallExpr
                  (identifier)
                  (argumentList
                    (slStringLiteral))))))))))
  (classProperty
    (identifier)
    (methodCallExpr
      (variableExpr
        (identifier))
      (identifier)
      (argumentList
        (functionLiteral
          (parameterList)
          (objectLiteral
            (parenthesizedExpr
              (variableExpr
                (identifier)))
            (objectBody
              (objectEntry
                (slStringLiteral)
                (slStringLiteral))))))))
  (classProperty
    (identifier)
    (methodCallExpr
      (variableExpr
        (identifier))
      (identifier)
      (argumentList
        (functionLiteral
          (parameterList)
          (objectLiteral
            (parenthesizedExpr
              (variableExpr
                (identifier)))
            (objectBody
              (objectEntry
                (methodCallExpr
                  (identifier)
                  (argumentList
                    (slStringLiteral)))
                (methodCallExpr
                  (identifier)
                  (argumentList
                    (slStringLiteral))))))))))
  (classProperty
    (identifier)
    (methodCallExpr
      (variableExpr
        (identifier))
      (identifier)
      (argumentList
        (functionLiteral
          (parameterList)
          (newExpr
            (type
              (qualifiedIdentifier
                (identifier)))
            (objectBody
              (objectProperty
                (identifier)
                (slStringLiteral))))))))
  (classProperty
    (identifier)
    (methodCallExpr
      (variableExpr
        (identifier))
      (identifier)
      (argumentList
        (functionLiteral
          (parameterList)
          (objectLiteral
            (parenthesizedExpr
              (variableExpr
                (identifier)))
            (objectBody
              (objectProperty
                (identifier)
                (slStringLiteral))))))))
  (classProperty
    (identifier)
    (methodCallExpr
      (variableExpr
        (identifier))
      (identifier)
      (argumentList
        (functionLiteral
          (parameterList)
          (newExpr
            (type
              (qualifiedIdentifier
                (identifier)))
            (objectBody
              (objectElement
                (slStringLiteral))
              (objectProperty
                (identifier)
                (slStringLiteral))))))))
  (classProperty
    (identifier)
    (methodCallExpr
      (variableExpr
        (identifier))
      (identifier)
      (argumentList
        (functionLiteral
          (parameterList)
          (objectLiteral
            (parenthesizedExpr
              (variableExpr
                (identifier)))
            (objectBody
              (objectElement
                (slStringLiteral))
              (objectProperty
                (identifier)
                (slStringLiteral))))))))
  (classProperty
    (identifier)
    (methodCallExpr
      (variableExpr
        (identifier))
      (identifier)
      (argumentList
        (functionLiteral
          (parameterList)
          (objectLiteral
            (parenthesizedExpr
              (variableExpr
                (identifier)))
            (objectBody
              (objectElement
                (methodCallExpr
                  (identifier)
                  (argumentList
                    (slStringLiteral))))
              (objectProperty
                (identifier)
                (slStringLiteral))))))))
  (classProperty
    (identifier)
    (methodCallExpr
      (variableExpr
        (identifier))
      (identifier)
      (argumentList
        (functionLiteral
          (parameterList)
          (objectLiteral
            (parenthesizedExpr
              (variableExpr
                (identifier)))
            (objectBody
              (objectEntry
                (intLiteral)
                (slStringLiteral))
              (objectProperty
                (identifier)
                (slStringLiteral))))))))
  (classProperty
    (identifier)
    (methodCallExpr
      (variableExpr
        (identifier))
      (identifier)
      (argumentList
        (functionLiteral
          (parameterList)
          (objectLiteral
            (parenthesizedExpr
              (variableExpr
                (identifier)))
            (objectBody
              (objectEntry
                (methodCallExpr
                  (identifier)
                  (argumentList
                    (intLiteral)))
                (methodCallExpr
                  (identifier)
                  (argumentList
                    (slStringLiteral))))
              (objectProperty
                (identifier)
                (slStringLiteral))))))))
  (classProperty
    (identifier)
    (methodCallExpr
      (variableExpr
        (identifier))
      (identifier)
      (argumentList
        (functionLiteral
          (parameterList)
          (objectLiteral
            (parenthesizedExpr
              (variableExpr
                (identifier)))
            (objectBody
              (objectElement
                (slStringLiteral))
              (objectEntry
                (intLiteral)
                (slStringLiteral))
              (objectProperty
                (identifier)
                (slStringLiteral))))))))
  (classProperty
    (identifier)
    (methodCallExpr
      (variableExpr
        (identifier))
      (identifier)
      (argumentList
        (functionLiteral
          (parameterList)
          (objectLiteral
            (parenthesizedExpr
              (variableExpr
                (identifier)))
            (objectBody
              (objectElement
                (methodCallExpr
                  (identifier)
                  (argumentList
                    (slStringLiteral))))
              (objectEntry
                (methodCallExpr
                  (identifier)
                  (argumentList
                    (intLiteral)))
                (methodCallExpr
                  (identifier)
                  (argumentList
                    (slStringLiteral))))
              (objectProperty
                (identifier)
                (slStringLiteral)))))))))
