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: A constructor makes an object, so it is never abstract: give it a body

#!ek9
defines module error.e07050.good.fix

  defines class

    Counter as abstract

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

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:

Found a problem?

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