E50040: cannot be abstract

Category: E50xxx Common errors · Reported in phase: SYMBOL_DEFINITION · Classification: CANNOT_BE_ABSTRACT · All error codes

What went wrong

You've used the 'abstract' modifier on a construct that doesn't support it. Not all EK9 constructs can be abstract.

Worked examples

Compilable examples demonstrating this error and the correct fix:

Constructs that can be abstract

  • Classes: 'MyClass as abstract'
  • Functions: 'myFunction() as abstract'
  • Methods in classes/traits

Constructs that cannot be abstract

  • Records (they are data-focused, always concrete)
  • Program and service methods/operations (entry points; nothing can extend them, so nothing could implement the abstract member - 'override' on the same methods is E05100)
  • Generic function definitions (must have implementation)
  • Constructors (they must be concrete)
  • Operators (implementation required)

How to fix it

  1. Remove 'abstract' if not supported by this construct
  2. If abstraction is needed, change to a construct that supports it
  3. For records, use composition instead of inheritance

See also

  • E50040: invalid abstract modifier (this error)
  • E05100: 'override' on a program or service method
  • E06100: abstract generic function (specific to generics)

Examples

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

Fails with E50040: cannot be abstract

#!ek9
defines module error.e50040.bad

  defines class

    Shape
      area() as abstract
        <- rtn as Float?

Fixed: Mark the class abstract, as its method is

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

  defines class

    Shape as abstract
      area() as abstract
        <- rtn as Float?

Fixed: Only an open or abstract type may have an abstract method

#!ek9
defines module error.e50040.good

  defines class

    Shape as abstract
      area() as abstract
        <- rtn as Float?

    Square extends Shape
      side as Float: 1.0

      override area()
        <- rtn as Float: side * side

      default operator ?

Questions and answers

These Q&A entries show E50040 and its fix:

Found a problem?

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