E01060: is a reserved keyword and cannot be used as an identifier

Category: E01xxx Parsing and excluded constructs · Reported in phase: SYMBOL_DEFINITION · Classification: RESERVED_WORD_AS_IDENTIFIER · All error codes

What went wrong

You have used a reserved keyword as an identifier. These keywords have special meaning in EK9 and cannot be used as names for any symbol.

Worked examples

Compilable examples demonstrating this error and the correct fix:

  • ek9 -q 291 (Why does the compiler reject my variable name?)
  • ek9 -q 290 (What variable names are banned in EK9?)

Reserved keywords

  • assert - Test assertion statement
  • require - Production precondition/invariant
  • assertThrows - Test assertion for expected exceptions
  • assertDoesNotThrow - Test assertion for no exception

How to fix it

Choose a descriptive name that doesn't clash with reserved keywords:

  • checkCondition(), validateInput() instead of 'assert', 'require'
  • Assertion, Requirement for class names
  • assertionValue, requirementLevel for variables

Rationale

These keywords are LANGUAGE CONSTRUCTS, not function calls:

assert condition              // Compile-time validated construct
require precondition          // Runtime precondition check
assertThrows(Type, expr)      // Exception expectation test

They have special compile-time validation and code generation that user-defined functions cannot replicate.

Common causes

  • Code from other languages where these are valid identifiers
  • Naming validation methods 'assert' or 'require'

See also

  • E01060: Reserved KEYWORD used as identifier
  • E01030: Name collision between different symbol kinds
  • E01040: Duplicate type definition

Examples

Every example is compiled by the EK9 compiler: the first fails exactly as captioned, the others fix it.

Fails with E01060: is a reserved keyword and cannot be used as an identifier

#!ek9
defines module error.e01060.bad

  //=== TEST 1: Function names ===

  defines class

    BadMethodNames
      mainValue <- 0

      assertDoesNotThrow()
        <- result as Boolean: true

      assertThrows()
        <- result as Boolean: true

      assert()
        <- result as Boolean: true

      require()
        <- result as Boolean: true

  defines function

    assert()
      <- result as Boolean: true

    require()
      <- result as Boolean: true

    assertThrows()
      <- result as Boolean: true

    assertDoesNotThrow()
      <- result as Boolean: true

  //=== TEST 2: Method names (inside class scope) ===

Fixed: Name functions and methods for what they check; assert and require stay statements

#!ek9
defines module error.e01060.good

  defines class

    Validator
      limit as Integer: 100

      withinLimit()
        -> amount as Integer
        <- result as Boolean: amount <= limit

      default operator ?

  defines function

    isPositive()
      -> amount as Integer
      <- result as Boolean: amount > 0

    checkedTotal()
      ->
        first as Integer
        second as Integer
      <- result as Integer?

      require isPositive(first) and isPositive(second)
      result: first + second