================================================================================
basic/constModifier
================================================================================

import "pkl:test"

const constantSimpleValue = "constant"

nonConstantSimpleValue = "NON-CONSTANT"

const constantNestedValue {
  nestedSimpleValue = constantSimpleValue
}

nonConstantNestedValue {
  nestedSimpleValue = constantSimpleValue
}

function nonConstFunction() = nonConstantSimpleValue

const function constFunctionCallingNonConst(): (String) -> String = (s) -> s + nonConstFunction()

class Valid {
  nested = constantNestedValue
  simple = constantSimpleValue
  dereferenced = constantNestedValue.nestedSimpleValue
}

class BrokenSimple {
  improperDefault = nonConstantSimpleValue
}

class BrokenNested {
  improperNestedDefault = nonConstantNestedValue 
}

class BrokenFunction {
  improperDefaultFromNonConstFunction = nonConstFunction()
}

res01 = new Valid {}
res02 = test.catch(() -> "\(new BrokenSimple {})")
res03 = test.catch(() -> "\(new BrokenNested {})")
res04 = test.catch(() -> "\(new BrokenFunction {})")
res05 = test.catch(() -> constFunctionCallingNonConst().apply("hello "))

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

(module
  (importClause
    (stringConstant))
  (classProperty
    (modifier)
    (identifier)
    (slStringLiteral))
  (classProperty
    (identifier)
    (slStringLiteral))
  (classProperty
    (modifier)
    (identifier)
    (objectBody
      (objectProperty
        (identifier)
        (variableExpr
          (identifier)))))
  (classProperty
    (identifier)
    (objectBody
      (objectProperty
        (identifier)
        (variableExpr
          (identifier)))))
  (classMethod
    (methodHeader
      (identifier)
      (parameterList))
    (variableExpr
      (identifier)))
  (classMethod
    (methodHeader
      (modifier)
      (identifier)
      (parameterList)
      (typeAnnotation
        (type
          (type
            (qualifiedIdentifier
              (identifier)))
          (type
            (qualifiedIdentifier
              (identifier))))))
    (functionLiteral
      (parameterList
        (typedIdentifier
          (identifier)))
      (binaryExpr
        (variableExpr
          (identifier))
        (methodCallExpr
          (identifier)
          (argumentList)))))
  (clazz
    (identifier)
    (classBody
      (classProperty
        (identifier)
        (variableExpr
          (identifier)))
      (classProperty
        (identifier)
        (variableExpr
          (identifier)))
      (classProperty
        (identifier)
        (propertyCallExpr
          (variableExpr
            (identifier))
          (identifier)))))
  (clazz
    (identifier)
    (classBody
      (classProperty
        (identifier)
        (variableExpr
          (identifier)))))
  (clazz
    (identifier)
    (classBody
      (classProperty
        (identifier)
        (variableExpr
          (identifier)))))
  (clazz
    (identifier)
    (classBody
      (classProperty
        (identifier)
        (methodCallExpr
          (identifier)
          (argumentList)))))
  (classProperty
    (identifier)
    (newExpr
      (type
        (qualifiedIdentifier
          (identifier)))
      (objectBody)))
  (classProperty
    (identifier)
    (methodCallExpr
      (variableExpr
        (identifier))
      (identifier)
      (argumentList
        (functionLiteral
          (parameterList)
          (slStringLiteral
            (interpolationExpr
              (newExpr
                (type
                  (qualifiedIdentifier
                    (identifier)))
                (objectBody))))))))
  (classProperty
    (identifier)
    (methodCallExpr
      (variableExpr
        (identifier))
      (identifier)
      (argumentList
        (functionLiteral
          (parameterList)
          (slStringLiteral
            (interpolationExpr
              (newExpr
                (type
                  (qualifiedIdentifier
                    (identifier)))
                (objectBody))))))))
  (classProperty
    (identifier)
    (methodCallExpr
      (variableExpr
        (identifier))
      (identifier)
      (argumentList
        (functionLiteral
          (parameterList)
          (slStringLiteral
            (interpolationExpr
              (newExpr
                (type
                  (qualifiedIdentifier
                    (identifier)))
                (objectBody))))))))
  (classProperty
    (identifier)
    (methodCallExpr
      (variableExpr
        (identifier))
      (identifier)
      (argumentList
        (functionLiteral
          (parameterList)
          (methodCallExpr
            (methodCallExpr
              (identifier)
              (argumentList))
            (identifier)
            (argumentList
              (slStringLiteral))))))))
