E11032: variable name shadows operator keyword - use a more specific name

Category: E11xxx Code quality and IR analysis · Reported in phase: PRE_IR_CHECKS · Classification: OPERATOR_KEYWORD_AS_VARIABLE_NAME · All error codes

What went wrong

The variable name shadows a built-in operator keyword. EK9 allows these keywords as identifiers for flexibility, but using them as variable names makes the corresponding operator unusable in that scope — producing confusing downstream parse errors. A name that differs from one of these keywords only in case ('Length', 'Contains') is refused as well - it does not shadow the operator, but it is as easily confused with it, and the message says 'differs only in case from the operator'.

Worked examples

Compilable examples demonstrating this error and the correct fix:

  • ek9 -q 291 (Why does the compiler reject my variable name?)
  • ek9 -q 297 (What should I name my variable instead of temp or data?)
  • ek9 -q 290 (What variable names are banned in EK9?)

Rationale

Real-world example from Q&A development: naming a variable 'empty' then trying 'numbers is empty' or '${empty numbers}' produced baffling errors because the parser treated 'empty' as the variable, not the operator.

The EK9 grammar (identifier rule) explicitly lists EMPTY, LENGTH, CONTAINS, ABS, SQRT, MATCHES, and CLOSE as valid identifier alternatives. This is intentional for flexibility, but creates a shadowing trap where:

  1. The variable declaration compiles silently
  2. The operator becomes unusable in that scope
  3. Downstream errors are confusing and far from the actual problem

How to fix it

Replace the keyword name with a descriptive name:

Instead of: Use:

  • empty -> isEmpty, emptyList, noItems
  • length -> nameLength, itemCount, totalLength
  • contains -> hasItem, includesValue, containsKey
  • abs -> absoluteValue, magnitude
  • sqrt -> squareRoot, rootValue
  • close -> closeFile, closeConnection
  • matches -> matchesPattern, isMatch, regexResult

Operator syntax reference

  • 'x is empty' - suffix operator: test whether x has no items (empty is not unset)
  • 'length x' - prefix operator: get its length/size
  • 'x contains y' - infix operator: membership test
  • 'abs x' and 'sqrt x' - prefix operators: absolute value and square root
  • 'x matches /re/' - infix operator: regex match
  • 'close' - an operator a type declares and nothing calls by hand: a try, the statement or the generated close chain runs it

See also

https://ek9.io/quality.html#naming-quality https://ek9.io/forAI.json#$.bannedIdentifiers

Examples

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

Fails with E11032: variable name shadows operator keyword - use a more specific name

#!ek9
defines module error.e11032.bad

  defines function

    demo()
      <- rtn as String?
      empty <- List() of String
      length <- 42
      contains <- true
      rtn: `${empty} ${length} ${contains}`

Fixed: Name what the value means, not the operator

#!ek9
defines module error.e11032.good

  defines function

    demo()
      <- rtn as String?
      pendingItems <- List() of String
      nameLength <- 42
      hasItem <- true
      rtn: `${length pendingItems} ${nameLength} ${hasItem}`

Questions and answers

These Q&A entries show E11032 and its fix: