E08081: comparing a value to itself is always constant and indicates a logic error

Category: E08xxx Pre-IR checks (flow analysis) · Reported in phase: PRE_IR_CHECKS · Classification: SELF_COMPARISON · All error codes

What went wrong

You're comparing a variable to itself. The result is always constant (always true for ==, always false for <>, always 0 for <=>), which indicates a logic error — typically a typo in one of the operands.

Worked examples

Compilable examples demonstrating this error and the correct fix:

  • ek9 -q 637 (How should I compare two similar variables to avoid self-...)
  • ek9 -q 318 (How does EK9 detect self-assignment and self-comparison?)

How to fix it

  1. Check variable names for typos — one operand is probably wrong
  2. Replace one operand with the intended comparison target
  3. If the comparison is truly redundant, remove the condition entirely

Common causes

  • Typo (wrong variable name on one side)
  • Copy/paste error from duplicating an expression
  • Refactoring that renamed one variable but not the other

See also

  • E08081: self-comparison (this error)
  • E08080: self-assignment
  • E08082: constant comparison (both operands are literals)

Examples

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

Fails with E08081: comparing a value to itself is always constant and indicates a logic error

#!ek9
defines module error.e08081.bad

  defines constant

    MAX_RETRIES <- 10

  defines function

    checkEquality()
      -> amount as Integer
      <- result as Boolean?

      result: amount == amount

    checkNotEqual()
      -> amount as Integer
      <- result as Boolean?

      result: amount <> amount

    checkNotEqual2()
      -> amount as Integer
      <- result as Boolean?

      result: amount != amount

    checkLessThan()
      -> amount as Integer
      <- result as Boolean?

      result: amount < amount

    checkGreaterThan()
      -> amount as Integer
      <- result as Boolean?

      result: amount > amount

    checkLessEqual()
      -> amount as Integer
      <- result as Boolean?

      result: amount <= amount

    checkGreaterEqual()
      -> amount as Integer
      <- result as Boolean?

      result: amount >= amount

    checkComparator()
      -> amount as Integer
      <- result as Integer?

      result: amount <=> amount

    checkFuzzy()
      -> greeting as String
      <- result as Integer?

      result: greeting <~> greeting

    checkContains()
      -> greeting as String
      <- result as Boolean?

      result: greeting contains greeting

    checkConstantComparison()
      <- result as Boolean?

      result: MAX_RETRIES == MAX_RETRIES

Fixed: Compare two different values

#!ek9
defines module error.e08081.good

  defines function

    compareDifferentVars()
      ->
        first as Integer
        second as Integer
      <- result as Boolean?

      result: first == second

    compareDifferentStrings()
      ->
        firstName as String
        lastName as String
      <- result as Boolean?

      result: firstName <> lastName

    compareRelational()
      ->
        first as Integer
        second as Integer
      <- result as Boolean?

      result: first < second

    compareComparator()
      ->
        first as Integer
        second as Integer
      <- result as Integer?

      result: first <=> second

    compareFuzzy()
      ->
        firstName as String
        lastName as String
      <- result as Integer?

      result: firstName <~> lastName

    compareContains()
      ->
        sentence as String
        keyword as String
      <- result as Boolean?

      result: sentence contains keyword

Questions and answers

These Q&A entries show E08081 and its fix:

Found a problem?

If EK9 reported E08081 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.