Why does EK9 reject empty defines blocks?

← Syntax and Structure Rules · Ref: Q943

EK9 does not allow empty defines blocks. Every section header must contain at least one meaningful declaration.

EMPTY BLOCKS ARE ERRORS

  defines class           // ERROR E01087 — nothing inside
  defines function        // ERROR E01087 — nothing inside

WHY NOT ALLOWED

Empty blocks serve no purpose. They indicate incomplete code, placeholder stubs, or copy-paste errors. EK9 treats them as errors because the compiler enforces completeness.

EVERY SECTION NEEDS CONTENT

  defines class
    MyClass               // At least one class declaration
      value <- 0
  defines function
    doWork()              // At least one function
      stdout <- Stdout()
      stdout.println("working")
  defines program
    Main()                // At least one program
      stdout <- Stdout()
      stdout.println("running")

If you are not ready to fill a section, remove the section header entirely. Add it back when you have content.

See Q893 for section header requirements. See Q725 for class body ordering.

Example

defines module qa.syntax.noemptydefines

  defines function

    greet() as pure
      -> name as String
      <- rtn as String: `Welcome, ${name}`

  defines class

    Greeter
      prefix <- "Hello"

      Greeter()
        -> p as String
        prefix :=: p

      makeGreeting() as pure
        -> name as String
        <- rtn as String: `${prefix}, ${name}`

      default operator ?

  defines program

    NoEmptyDefinesDemo()
      stdout <- Stdout()

      //Every section above has content
      stdout.println(greet("Steve"))

      greeter <- Greeter("Good morning")
      stdout.println(greeter.makeGreeting("World"))

Common mistakes

E01087 — Empty defines blocks are not allowed. Every section header (defines class, defines function, etc.) must contain at least one declaration. Remove the header if you have no content yet. See ek9 -h E01087 for details.

Incorrect:

  defines function

Correct:

  defines function

    greet() as pure
      -> name as String
      <- rtn as String: `Welcome, ${name}`
Other ways to ask this
  • What triggers E01087 in EK9?
  • Can I have an empty class body in EK9?
  • Why must every defines section have content?

Coming from another language?

Java: empty class bodies allowed (class Empty {}). Python: pass keyword for empty blocks. Rust: empty impl blocks allowed. Go: empty struct allowed. EK9: no empty blocks — every section must contain declarations.

Keywords: section, empty, required, stub, block, content, E01087, defines