E50040: cannot be abstract
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:
- ek9 -q 103 (What are abstract classes and methods in EK9?)
- ek9 -q 115 (How do dynamic classes work in EK9?)
- ek9 -q 111 (What are components in EK9?)
- ek9 -q 117 (How do I create a singleton in EK9?)
- ek9 -q 1290 (What does EK9 error E50040 mean when I write an abstra...)
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
- Remove 'abstract' if not supported by this construct
- If abstraction is needed, change to a construct that supports it
- For records, use composition instead of inheritance
See also
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:
- Q103: What are abstract classes and methods in EK9?
- Q111: What are components in EK9?
- Q115: How do dynamic classes work in EK9?
- Q117: How do I create a singleton in EK9?
- Q1234: Create me a generic Processor class of type T with an abstract process method, then extend it inline using a dynamic class with String as the type parameter.
- Q1290: What does EK9 error E50040 mean when I write an abstract method in a component and how do I fix it?
- Q1291: Why does E50040 fire on my abstract method in a class but not in a trait?
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.