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

It is the SECTION that must not be empty. A single class with no members is legal; a defines section with nothing under it is E01087.

  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
      counter <- 0
      default operator ?
  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?
  • Is an empty defines class section allowed 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: an empty class (no members) is legal, but an empty defines SECTION is E01087 - every section must contain at least one declaration.

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