E01040: Type/Function name duplicated

Category: E01xxx Parsing and excluded constructs · Reported in phase: SYMBOL_DEFINITION · Classification: DUPLICATE_TYPE · All error codes

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:

  • ek9 -q 1 (What does a minimal EK9 program look like?)
  • ek9 -q 8 (How do I tag my package so it can be easily found in remo...)
  • ek9 -q 9 (How can I control the license agreement for my package's ...)
  • ek9 -q 10 (How do I distinguish between development dependencies and...)

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: