E01030: Variable/Function/Type duplicated, likely to lead to confusion
What went wrong
A name you've used matches an existing symbol of a DIFFERENT kind in scope. EK9 prevents this ambiguity to ensure clear, unambiguous code.
This error triggers when:
- Variable name matches a function name
- A LOCAL variable matches a method its type can call - its own (private too), an inherited one, or a trait's. A local 'total' given the result of 'total()' would mean a value on the left and a call on the right. A super's PRIVATE method is not reachable, so its name is free. Parameters and fields are not locals: a constructor parameter named like its field is fine. Rename the local, to 'sum' for example.
- Property name matches a module-level function
- Local variable shadows a captured variable
- A NAMED capture '(helper: 7)' in a dynamic function or class matches a function name - the capture is a new variable (it becomes a property of the dynamic function/class), so it obeys the same rule. Rename the capture: '(startingValue: 7)'. An unnamed capture '(total)' is checked where 'total' was declared.
Worked examples
Compilable examples demonstrating this error and the correct fix:
How to fix it
- Rename the conflicting symbol to be distinct
- Use descriptive names that indicate the symbol's purpose
- Check what symbols are already in scope before naming
Rationale
Ambiguous names cause bugs and confuse both humans and AI:
- Is 'myFunction' a call or a variable reference?
- Which symbol does a reference resolve to?
- AI assistants may generate incorrect code when names are ambiguous
See also
- E01030: Name collision (same name, DIFFERENT symbol kinds)
- E01040: Duplicate type definition (same type defined twice)
- E50050: Duplicate variable (same variable declared twice)
- E11030: Confusingly SIMILAR names (different names, same type)
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 E01030: Variable/Function/Type duplicated, likely to lead to confusion
#!ek9 defines module error.e01030.bad defines class Report //A property named like the function 'summary' below summary as String: "monthly" //A method named like the same function summary() <- rtn as String: "report" default operator ? defines function summary() <- rtn as String: "all reports"
Fixed: Give the property, the method and the function names that say what each one is
#!ek9 defines module error.e01030.good defines class Report period as String: "monthly" describe() <- rtn as String: "report for " + period default operator ? defines function reportsSummary() <- rtn as String: "all reports"
Questions and answers
These Q&A entries show E01030 and its fix:
- Q5: How are EK9 source files structured?
- Q49: How do I define a function in EK9?
- Q53: How do closures and variable capture work in EK9?
- Q655: Can I overload methods with different parameterised types in EK9?
- Q1392: Why can't a variable, parameter or named capture have the same name as a function or type?