E05200: incompatible genus with local constructor use

Category: E05xxx Explicit type symbol definition · Reported in phase: FULL_RESOLUTION · Classification: INCOMPATIBLE_GENUS_CONSTRUCTOR · All error codes

What went wrong

A constructor was called on a program or an application. Their genus (PROGRAM, GENERAL_APPLICATION, SERVICE_APPLICATION) does not allow local constructor use: a program is the operating-system entry point and is started by the runtime, and an application is the dependency-injection blueprint, brought to life by a program declared 'with application of'. Neither is an ordinary object you build by hand.

Worked examples

Compilable examples demonstrating this error and the correct fix:

  • ek9 -q 1312 (Why can't I instantiate a program or application with...)

How to fix it

  1. Remove the constructor call ('app <- OrderApp()', 'prog <- MyProgram()')
  2. Bind the program to the application: 'RunDemo() with application of OrderApp'
  3. Reach what the application registers through injection: 'orders as Orders!'

Common causes

  • Treating an application like a Spring context or a container object to 'new'
  • Calling one program from another to reuse its logic (move that logic into a function or a class both programs call)

See also

  • E08271: a 'register' statement must call a constructor
  • E50020: incompatible genus

Examples

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

Fails with E05200: incompatible genus with local constructor use

#!ek9
defines module error.e05200.bad

  defines application

    ServiceApplication
      stdout <- Stdout()

  defines program

    AnotherProgram()
      stdout <- Stdout()
      stdout.println("another")

    Launcher()
      //An application is wired to a program, never constructed
      app <- ServiceApplication()

      //A program is an entry point the runtime starts, never constructed
      other <- AnotherProgram()

Fixed: Wire the application to a program with 'with application of'; run each program from the command line

#!ek9
defines module error.e05200.good

  defines application

    ServiceApplication
      stdout <- Stdout()

  defines program

    AnotherProgram()
      stdout <- Stdout()
      stdout.println("another")

    Launcher() with application of ServiceApplication
      stdout <- Stdout()
      stdout.println("Starting with ServiceApplication")

Questions and answers

These Q&A entries show E05200 and its fix:

Found a problem?

If EK9 reported E05200 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.