E08220: program uses injection but has no linked application

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

What went wrong

A program uses component injection (via '!' suffix) but has no linked application. Without an application, the compiler cannot know which concrete components to inject.

Worked examples

Compilable examples demonstrating this error and the correct fix:

  • ek9 -q 672 (Why must programs declare 'with application of' for injec...)

How to fix it

  1. Add 'with application of <AppName>' to the program declaration
  2. Or remove the injection if DI is not needed

See also

  • E08220: program without application (this error)
  • E08210: missing registration
  • E08190: circular dependency

Examples

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

Fails with E08220: program uses injection but has no linked application

#!ek9
defines module error.e08220.bad

  defines component

    AbstractService as abstract
      doWork() as abstract
        <- rtn as Boolean?

      default operator ?

    ConcreteService is AbstractService
      override doWork()
        <- rtn as Boolean: true

      default operator ?

  defines program

    noAppProgram()
      stdout <- Stdout()

      svc as AbstractService!
      if svc.doWork()
        stdout.println("test")

Fixed: Link the program to an application that registers the component

#!ek9
defines module error.e08220.good

  defines component

    AbstractService as abstract
      doWork() as abstract
        <- rtn as Boolean?
      default operator ?

    ConcreteService is AbstractService
      override doWork()
        <- rtn as Boolean: true
      default operator ?

  defines application

    serviceApp
      register ConcreteService() as AbstractService

  defines program

    appProgram() with application of serviceApp
      stdout <- Stdout()
      svc as AbstractService!
      if svc.doWork()
        stdout.println("test")

Questions and answers

These Q&A entries show E08220 and its fix: