Why does EK9 reject duplicate property fields in records?
← Code Quality · Ref: Q819
EK9 prevents child records from redeclaring properties that already exist in the parent. Property shadowing creates confusion about which field is being accessed.
THE RULE
A child record cannot have a property with the same name as any inherited property:
BaseRecord
name as String
ChildRecord extends BaseRecord
name as String // ERROR: E02010 duplicate property
WHY THIS MATTERS
Property shadowing in Java causes subtle bugs: super.name and this.name refer to different fields. Code that accesses the field through the base type gets the wrong value. EK9 eliminates this by rejecting the duplicate at compile time.
HOW TO FIX
- Use a different name in the child: childName as String
- If you need to override behaviour, use a method instead
See Q97 for class vs record guidance. See Q96 for inheritance.
Example
defines module qa.quality.duplicate.property defines record BaseRecord as open label as String: String() default operator ? ChildRecord extends BaseRecord childLabel as String: String() default operator ? defines program DuplicatePropertyDemo() stdout <- Stdout() child <- ChildRecord() stdout.println(`Label: ${child.label}`) stdout.println(`Child label: ${child.childLabel}`)
Common mistakes
E02010 — The parent BaseRecord already has a property named 'label'. Redeclaring it in the child creates a duplicate. Use a different name. See ek9 -h E02010 for details.
Incorrect:
ChildRecord extends BaseRecord label as String: String()
Correct:
ChildRecord extends BaseRecord childLabel as String: String()
Other ways to ask this
- What is E02010 DUPLICATE_PROPERTY_FIELD?
- Why can't I redeclare a parent field in a child record?
- How does EK9 prevent property shadowing?
Coming from another language?
Java: allows field shadowing silently — a major source of bugs. Python: instance attributes shadow freely. Rust: no inheritance, so not applicable. Go: embedded structs can shadow. EK9: duplicate property field is a compile error.
Keywords: property, record, shadow, quality, duplicate, inheritance, field, E02010