E01040: Type/Function name duplicated
What went wrong
A type (class, record, trait, or function) with this name already exists in this module. Each type must have a unique name within its module.
Worked examples
Compilable examples demonstrating this error and the correct fix:
How to fix it
- Rename one of the duplicate type definitions
- If intentionally extending, use 'extends' instead of redefining
- Check for copy-paste errors that created duplicates
Common causes
- Copy-paste error creating duplicate definitions
- Defining same class/record/trait twice in same file
- Forgetting a type was already defined earlier in the module
- A variable, parameter or NAMED capture '(Widget: 7)' named exactly like a type - user-defined or built-in ('String') - rename the variable
Note
Different modules CAN have types with the same name. Use the '::' syntax to disambiguate when referencing types from different modules: 'MyClass()' is this module's, 'other.module::MyClass()' the other module's.
See also
- E01040: Duplicate TYPE definition (class/record/trait/function)
- E01030: Name collision between DIFFERENT symbol kinds
- E02010: Duplicate PROPERTY/field within a type hierarchy
https://ek9.io/forAI.json#$.methodResolution.functionResolution
Examples
Every example is compiled by the EK9 compiler: the first fails exactly as captioned, the others fix it.
Fails with E01040: Type/Function name duplicated
#!ek9 defines module error.e01040.bad defines class Customer name as String: "anonymous" default operator ? Customer email as String: "none" default operator ?
Fixed: One type, one name: merge the two, or give the second its own name
#!ek9 defines module error.e01040.good defines class Customer name as String: "anonymous" default operator ? CustomerContact email as String: "none" default operator ?
Questions and answers
These Q&A entries show E01040 and its fix:
- Q1: What does a minimal EK9 program look like?
- Q6: How do I organize code into modules?
- Q8: How do I tag my package so it can be easily found in remote repositories?
- Q9: How can I control the license agreement for my package's code?
- Q10: How do I distinguish between development dependencies and production dependencies?
- Q15: What is semantic versioning and why must I use it in EK9 packages?
- Q832: Why can't I have a local class with the same name as an imported reference in EK9?
- Q1392: Why can't a variable, parameter or named capture have the same name as a function or type?