Why does EK9 reject duplicate properties in records with JSON support?
← Code Quality · Ref: Q829
EK9 requires every property name to be unique across a record's inheritance hierarchy, whatever operators it defaults. A child record that redeclares a parent property is E02010, with or without 'default operator'.
THE RULE
defines record ParentRecord as open name as String: String() default operator ChildRecord extends ParentRecord name as String: String() // ERROR E02010: property duplicated default operator
WHY IT ALSO PROTECTS JSON
The $$ operator generates JSON like {"name": "value"}. Because the name can never appear twice in the hierarchy, a generated $$ never has duplicate keys, so there is no separate JSON error. Writing $$ by hand does not make the redeclaration legal.
HOW TO FIX
- Use a different name in the child: childName as String
- Or set the inherited property instead of redeclaring it
See Q819 for duplicate property basics. See Q97 for records.
Example
defines module qa.quality.duplicate.json defines record BaseConfig as open label as String: String() default operator ? default operator $ ChildConfig extends BaseConfig childLabel as String: String() default operator ? default operator $ defines program DuplicateJsonDemo() stdout <- Stdout() child <- ChildConfig() stdout.println($child)
Common mistakes
E02010 — The parent BaseConfig already has 'label'. Redeclaring it in a child creates a duplicate property. Use a different name. See ek9 -h E02010 for details.
Incorrect:
ChildConfig extends BaseConfig label as String: String()
Correct:
ChildConfig extends BaseConfig childLabel as String: String()
Other ways to ask this
- Is a duplicated record property a JSON error or a duplicate property error?
- Why can't my child record redeclare a parent property with default operators?
- How does property duplication affect JSON serialization in EK9?
Coming from another language?
Java: Jackson serializes duplicate fields from parent+child creating ambiguous JSON. Python: no enforcement. Rust: no inheritance. Go: embedded struct fields can shadow. EK9: compile-time error prevents ambiguous JSON serialization.
Keywords: json, duplicate, property, E02010, toJson, serialization, record