E05030: not open to be extended
What went wrong
You're trying to extend a class that isn't marked as 'open'. In EK9, classes are CLOSED by default - they cannot be extended unless explicitly designed for inheritance.
Worked examples
Compilable examples demonstrating this error and the correct fix:
- ek9 -q 1043 (I get E05030 'not open to be extended'. What does this...)
- ek9 -q 102 (How do I make a class extensible with 'as open'?)
- ek9 -q 1044 (I tried to extend List and got E05030. How do I wrap...)
- ek9 -q 101 (Why are types closed by default in EK9?)
- ek9 -q 23 (What basic types does EK9 have?)
How to fix it
- If you control BaseClass: add 'as open' if inheritance is intended
- If you don't control BaseClass: use composition (wrap the class)
- Consider if inheritance is really needed - composition is often better
Rationale
Classes closed by default because:
- Prevents fragile base class problem (changes break subclasses)
- Forces explicit design for inheritance (intentional extension points)
- Encourages composition over inheritance (more flexible)
- Makes class contracts more predictable (sealed behavior)
Common causes
- Assuming classes are open like Java (EK9 defaults differ)
- Forgetting to add 'as open' when designing for inheritance
- Trying to extend built-in types (List, Dict, etc. - all closed)
See also
- E05030: extending closed class (this error)
- E05020: circular inheritance (different - cycle in hierarchy)
https://ek9.io/inheritance.html#closed-by-default https://ek9.io/forAI.json#$.closedByDefault
Examples
Every example is compiled by the EK9 compiler: the first fails exactly as captioned, the others fix it.
Fails with E05030: not open to be extended
#!ek9 defines module error.e05030.bad defines class Shape describe() <- description as String: "a shape" Circle extends Shape override describe() <- description as String: "a circle"
Fixed: Open the type you mean to extend
#!ek9 defines module error.e05030.good defines class Shape as open describe() <- description as String: "a shape" Circle extends Shape override describe() <- description as String: "a circle"
Questions and answers
These Q&A entries show E05030 and its fix:
- Q23: What basic types does EK9 have?
- Q51: What are abstract functions in EK9?
- Q101: Why are types closed by default in EK9?
- Q102: How do I make a class extensible with 'as open'?
- Q103: What are abstract classes and methods in EK9?
- Q105: How does method dispatch work in EK9?
- Q109: How do I use composition instead of inheritance in EK9?
- Q210: How does trait delegation with 'by' work in EK9?
- Q264: How do I implement the adapter pattern in EK9?
- Q278: Why does AI try to extend List, Dict, or closed types in EK9?
- Q574: What happens if I try to extend or override in a closed type?
- Q575: How do overrides work in deep class hierarchies?
- Q578: What is the relationship between open, abstract, and override?
- Q602: What is a circular type hierarchy and why does EK9 ban it?
- Q610: How do I refactor circular dependencies using composition?
- Q677: How does abstract implementation flow through a three-level hierarchy?
- Q784: Why can't I extend a class in EK9?
- Q1027: Review this design. Should I use composition instead of a large class?
- Q1043: I get E05030 'not open to be extended'. What does this mean and how do I fix it?
- Q1044: I tried to extend List and got E05030. How do I wrap a collection instead?
- Q1045: Review this design. Should it use composition instead of inheritance?
- Q1080: Copy a child class including parent fields.
- Q1108: Extend a BaseService component and add a version field to the child.
- Q1122: Write a dispatcher with a fallback handler for unmatched types.
- Q1123: Dispatch on a deep class hierarchy where exact match wins over parent handler.
- Q1130: Chain trait delegations so Top delegates to Middle which delegates to Final.
- Q1244: Create me a dispatcher for a deep class hierarchy (Shape -> Polygon -> Quadrilateral -> Square) where the Polygon handler catches Quadrilateral but a more specific Square handler exists.
- Q1250: Show me how to make a Repository class extensible so that InMemoryRepository can inherit from it without triggering E05030.
- Q1252: Write me an open logWriter function and a dynamic function instance that overrides its behaviour, demonstrating that 'as open' on a function allows dynamic instances to extend it.
- Q1254: Walk me through fixing error E05030 'not open to be extended' for three different cases: extending a closed class, extending a closed function, and extending a built-in type.
- Q1297: Can records extend other records in EK9?
- Q1365: How do I use a Set for unique values in EK9?
Found a problem?
If EK9 reported E05030 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.