E08070: never initialised

Category: E08xxx Pre-IR checks (flow analysis) · Reported in phase: PRE_IR_CHECKS · Classification: NEVER_INITIALISED · All error codes

What went wrong

A class property was declared with no value and nothing gives it one. A property declared as 'name as Type?' starts unset, and a type whose constructors do not set it (here a private default constructor) leaves it unset for the life of the object.

Worked examples

Compilable examples demonstrating this error and the correct fix:

  • ek9 -q 104 (Why does EK9 require explicit constructors for uninitiali...)

How to fix it

  1. Initialise the property where it is declared: 'owner as String: "unassigned"'
  2. Or set it in a constructor, as the [EXAMPLE] below shows
  3. Or remove the property if nothing needs it

Common causes

  • Declaring a property with '?' and never assigning it
  • A private default constructor that does not set every property
  • A property left over after the code that used it was removed

See also

  • E08070: property never initialised (this error)
  • E08020: variable used before it is initialised

Examples

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

Fails with E08070: never initialised

#!ek9
defines module error.e08070.bad

  defines class

    Ledger
      owner as String?

      default private Ledger()

      describe()
        <- rtn as String: "ledger"

      override operator ? as pure
        <- rtn as Boolean: true

Fixed: Initialise the property where it is declared

#!ek9
defines module error.e08070.good

  defines class

    Ledger
      owner as String: "unassigned"

      default operator ?

Fixed: Or set it in a constructor

#!ek9
defines module error.e08070.good.constructor

  defines class

    Ledger
      owner as String?

      default private Ledger()

      Ledger()
        -> name as String
        owner: name

      default operator ?

Questions and answers

These Q&A entries show E08070 and its fix:

Found a problem?

If EK9 reported E08070 for a program you think is valid, or did not report it where it should have, use the compiler form with the smallest program that shows it. If this page is wrong or unclear, use the documentation form. Both are at github.com/ek9lang/ek9-issues.