How does EK9 detect duplicate names and properties in type hierarchies?
← Code Quality · Ref: Q739
EK9 rejects a property name that appears twice in a type hierarchy, at compile time.
DUPLICATE PROPERTY FIELD (E02010)
A child record, class, component or dynamic class cannot redeclare a property with the same name as a property anywhere up its super chain, whatever its type. Class and component properties are private, but a redeclared one would still be a second field: the parent's methods would read one copy and the child's methods the other.
JSON ($$) IS COVERED BY THE SAME RULE
Because no name can appear twice in a hierarchy, a generated $$ (to JSON) operator can never meet a duplicate key. There is no separate JSON error: redeclaring the property is E02010 whichever operators are defaulted.
CORRECT PATTERNS
Use distinct names for properties at each level. If a child needs different data, use a different property name. If the parent property is sufficient, access it through inherited methods.
See Q93 for class definition. See Q97 for records vs classes.
Example
defines module qa.codequality.duplicatenames defines class Employee name <- String() role <- String() Employee() -> name as String role as String this.name: name this.role: role describe() <- rtn as String: `${name} (${role})` default operator defines program DuplicateNamesDemo() stdout <- Stdout() emp <- Employee("Alice", "Engineer") stdout.println(emp.describe()) stdout.println(`Equal: ${emp == Employee("Alice", "Engineer")}`)
Common mistakes
E50060 — EK9 has no toString() method. Use string interpolation or the class's describe() method. See ek9 -h E50060 for details.
Incorrect:
stdout.println(emp.toString())
Correct:
stdout.println(emp.describe())
E50060 — Employee has no getName() method. Use describe() to get employee information. See ek9 -h E50060 for details.
Incorrect:
emp <- Employee("Alice", "Engineer").getName()
Correct:
emp <- Employee("Alice", "Engineer")
Other ways to ask this
- What is E02010 duplicate property in EK9?
- Does default operator $$ change whether a child may reuse a parent property name?
- Why does EK9 reject properties with the same name in parent and child?
Coming from another language?
Java: field shadowing is allowed but produces warnings. Python: attribute shadowing is implicit. Rust: no inheritance, no shadowing. Go: embedding can shadow fields. Kotlin: property override requires explicit 'override' keyword. EK9: duplicate names rejected at compile time, no shadowing allowed.
Keywords: quality, E02010, name, collision, hierarchy, duplicate, shadow, property, json