E01089: differs only by case from an existing construct (too similar, likely to be confusing)

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

What went wrong

A name at module scope differs ONLY by letter case from a name already defined in this module. EK9 keeps every module construct - class, record, trait, function, component, service, text, program, application and constant - in one namespace, so a pair such as 'fibonacci' and 'Fibonacci' is too similar to read reliably.

There is also a hard failure behind this rule. Each construct is emitted to <simpleName>.class, so on a case-INSENSITIVE filesystem (macOS APFS by default, Windows NTFS) 'fibonacci.class' and 'Fibonacci.class' are ONE file: the second write silently clobbers the first. Without this error the code compiles 100% clean and then dies at run time with 'NoClassDefFoundError'. Rejecting the pair keeps a build portable across case-sensitive and case-insensitive filesystems.

Common causes

  • Naming a program after the function that does its work (the most common pairing)
  • Importing a Go habit, where letter case marks an identifier exported
  • Importing a Java habit, where a type and a method may share a name in different namespaces
  • A constant named as a case variant of the type it configures

How to fix it

Give the two constructs genuinely different names. Prefer naming the function for what it does rather than making it a case variant of the construct it serves - 'fibonacciSeries' beside the program 'Fibonacci'. If the two genuinely belong apart, move one to another module: different modules CAN hold names that differ only by case. The [EXAMPLE] section below shows the clash (a function 'fibonacci' beside a program 'Fibonacci') and the fix.

Note

This is the 'too similar' companion to the exact-match rules E01040 and E01030, and applies the same opinion EK9 already applies to enumerated values (E01050), which are compared with case and '_' normalised away.

See also

  • E01040: Duplicate TYPE definition (class/record/trait/function)
  • E01030: Name collision between DIFFERENT symbol kinds
  • E01050: Enumerated values that are duplicated or too similar

Examples

Every example is compiled by the EK9 compiler: the first fails exactly as captioned, the others fix it.

Fails with E01089: differs only by case from an existing construct (too similar, likely to be confusing)

#!ek9
defines module error.e01089.bad

  defines function

    fibonacci()
      -> count as Integer
      <- rtn as Integer: count

  defines program

    //Differs only by case from the function 'fibonacci' above
    Fibonacci()
      stdout <- Stdout()
      stdout.println(`${fibonacci(10)}`)

Fixed: Give the function and the program names that differ in more than case

#!ek9
defines module error.e01089.good

  defines function

    fibonacciSeries()
      -> count as Integer
      <- rtn as Integer: count

  defines program

    Fibonacci()
      stdout <- Stdout()
      stdout.println(`${fibonacciSeries(10)}`)

Found a problem?

If EK9 reported E01089 for a program you think is valid, or did not report it where it should have, use the compiler form with the smallest program that shows it. If this page is wrong or unclear, use the documentation form. Both are at github.com/ek9lang/ek9-issues.