E07050: 'abstract' modifier on a constructor is not logical

Category: E07xxx Full resolution · Reported in phase: SYMBOL_DEFINITION · Classification: ABSTRACT_CONSTRUCTOR · All error codes

What went wrong

You've marked a constructor as 'abstract', but constructors MUST create instances - they can never be abstract.

Worked examples

Compilable examples demonstrating this error and the correct fix:

  • ek9 -q 774 (Why can't a constructor be abstract in EK9?)

How to fix it

  1. Remove 'abstract' from constructor
  2. Use abstract factory method if you need polymorphic creation
  3. Constructors always create instances

Common causes

  • Confusion between constructors and factory methods
  • Trying to defer construction to subclasses
  • Misunderstanding abstract semantics

See also

  • E07050: abstract constructor (this error)
  • E07060: override constructor
  • E07070: constructor in trait

Examples

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

Fails with E07050: 'abstract' modifier on a constructor is not logical

#!ek9
defines module error.e07050.bad

  defines class

    Counter as abstract

      //A constructor makes an object, so it cannot be abstract
      Counter() as abstract
        -> start as Integer

Fixed: Give the constructor a body

#!ek9
defines module error.e07050.good

  defines class

    Counter
      count as Integer?

      default private Counter()

      Counter()
        -> start as Integer
        this.count: start

      default operator ?

Questions and answers

These Q&A entries show E07050 and its fix: