E07170: a developer coded constructor(s) are required where uninitialised properties are used

Category: E07xxx Full resolution · Reported in phase: PRE_IR_CHECKS · Classification: EXPLICIT_CONSTRUCTOR_REQUIRED · All error codes

What went wrong

Your class has properties that aren't initialized and doesn't have a constructor to initialize them. Properties must be either initialized at declaration or set in a constructor.

Worked examples

Compilable examples demonstrating this error and the correct fix:

  • ek9 -q 104 (Why does EK9 require explicit constructo...)

How to fix it

  1. Initialize properties at declaration with values
  2. Or add constructor to initialize properties
  3. Or use 'default' constructor for auto-initialization

Common causes

  • Properties declared without values and no constructor
  • Forgot to provide default values or constructor
  • Incomplete class definition

See also

  • E07170: uninitialized properties without constructor (this error)
  • E07180: default operator missing prerequisite
  • E07190: default operator missing in super

Examples

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

Fails with E07170: a developer coded constructor(s) are required where uninitialised properties are used

#!ek9
defines module error.e07170.bad

  defines class

    //name is declared unset, and no constructor sets it
    Greeter
      name as String?

      rename()
        -> newName as String
        name: newName

      default operator ?

Fixed: Write a constructor that sets the property

#!ek9
defines module error.e07170.good

  defines class

    Greeter
      name as String?

      default private Greeter()

      Greeter()
        -> initialName as String
        this.name: initialName

      rename()
        -> newName as String
        name: newName

      default operator ?