Class NoCaseVariantNameOrError

java.lang.Object
org.ek9lang.compiler.support.NoCaseVariantNameOrError
All Implemented Interfaces:
BiPredicate<List<ISymbol>, ISymbol>

public class NoCaseVariantNameOrError extends Object implements BiPredicate<List<ISymbol>, ISymbol>
Checks that a name being defined at module scope does not differ ONLY by case from a name already defined in that same module (across every construct kind - class, record, trait, function, component, service, text, program, application and constant).

NoNameCollisionOrError already rejects names that match EXACTLY. This is the 'too similar' companion to that rule, and follows the same opinion already applied to enumerated values in BasicSymbolFactory.populateEnumeration - the same word in a different case is highly likely to confuse a reader.

Beyond readability there is a hard failure behind this rule. Each module 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, while the directory entry keeps the name the first write created. The result compiles 100% clean and then dies at run time with NoClassDefFoundError. Rejecting the pair up front removes that whole failure mode, and keeps a build portable across case-sensitive and case-insensitive filesystems.

Note this deliberately normalises by CASE only. The enumerated-value rule also strips '_', but construct names legitimately use a leading underscore for synthetic/internal symbols, so stripping it here would over-fire.

  • Constructor Details

    • NoCaseVariantNameOrError

      public NoCaseVariantNameOrError(ErrorListener errorListener)
  • Method Details

    • test

      public boolean test(List<ISymbol> alreadyDefined, ISymbol symbol)
      Check the symbol being defined against those already defined in the same module. If this returns true then an error will have been added to the error listener.
      Specified by:
      test in interface BiPredicate<List<ISymbol>, ISymbol>
      Parameters:
      alreadyDefined - the symbols already defined in this module (all of its scopes).
      symbol - the symbol now being defined.