E07890: not mutable

Category: E07xxx Full resolution · Reported in phase: FULL_RESOLUTION · Classification: NOT_MUTABLE · All error codes

What went wrong

You're attempting to modify an IMMUTABLE value. Once set, immutable values cannot be changed.

Worked examples

Compilable examples demonstrating this error and the correct fix:

  • ek9 -q 141 (How does EK9 protect constants from mutation?)
  • ek9 -q 143 (How do EK9 constants compare to const, final, and static ...)
  • ek9 -q 140 (How do I define constants in EK9?)
  • ek9 -q 142 (How do I use constants across modules in EK9?)

How to fix it

  1. Use mutable variable if modification needed
  2. Create new value instead of modifying
  3. Remove mutation attempt

Common causes

  • Trying to reassign const
  • Mutation operation on immutable value

See also

  • E07890: immutable value modification (this error)
  • E08110: parameter reassignment

Examples

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

Fails with E07890: not mutable

#!ek9
defines module error.e07890.bad

  defines constant
    NAME <- "STEVE"
    START_DATE <- 2023-11-03

  defines function

    changeConstants()

      //A constant never changes
      START_DATE += P2D

      NAME: "Stephen"

Fixed: Copy the constant into a variable, and change that

#!ek9
defines module error.e07890.good

  defines constant
    NAME <- "STEVE"
    START_DATE <- 2023-11-03

  defines function

    nextWeek()
      <- rtn as Date: START_DATE

      //A variable, copied from the constant, can change
      rtn += P1W

    fullName()
      <- rtn as String: NAME + " Limb"

Questions and answers

These Q&A entries show E07890 and its fix: