How does EK9 detect duplicate names and properties in type hierarchies?
← Code Quality · Ref: Q739
EK9 detects two categories of property naming collisions in type hierarchies at compile time.
DUPLICATE NAME (E02010)
A child type cannot redeclare a property with the same name as a parent property. This prevents field shadowing which causes ambiguity in method resolution and state management.
DUPLICATE PROPERTY FOR JSON (E02020)
When a type hierarchy has two properties with the same name at different levels and uses the JSON serialization operator ($$), the compiler cannot determine which to include. EK9 rejects this at compile time rather than producing ambiguous JSON output.
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 name in EK9?
- What is E02020 duplicate property for JSON in EK9?
- 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: property, name, quality, E02020, shadow, duplicate, json, collision, hierarchy, E02010