E08082: comparison between literal values has a predetermined result

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

What went wrong

Both sides of this comparison are literal values, so the result is predetermined at compile time.

Worked examples

Compilable examples demonstrating this error and the correct fix:

  • ek9 -q 638 (Why should I use named constants instead of literal value...)
  • ek9 -q 558 (What are tautological conditions and how do I fix them?)
  • ek9 -q 557 (How does EK9 detect dead code and redundant conditions?)

How to fix it

  1. Replace one literal with a variable or named constant
  2. If the comparison is intentional, assign the result directly (true/false)
  3. Check for copy-paste errors in the operands

Common causes

  • Copy-paste error (forgot to change one operand)
  • Placeholder code that was never completed
  • Debugging remnant

See also

  • E08081: self-comparison (same variable on both sides)
  • E11064: magic literal in comparison

Examples

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

Fails with E08082: comparison between literal values has a predetermined result

#!ek9
defines module error.e08082.bad

  defines function

    checkIntegerEqual()
      <- result as Boolean?

      result: 1 == 1

    checkIntegerNotEqual()
      <- result as Boolean?

      result: 1 <> 2

    checkStringEqual()
      <- result as Boolean?

      result: "hello" == "hello"

    checkStringNotEqual()
      <- result as Boolean?

      result: "hello" <> "world"

    checkBooleanEqual()
      <- result as Boolean?

      result: true == false

    checkFloatLessThan()
      <- result as Boolean?

      result: 1.0 < 2.0

    checkCharEqual()
      <- result as Boolean?

      result: 'a' == 'a'

Fixed: Compare a variable, not two literals

#!ek9
defines module error.e08082.good

  defines function

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

      result: amount == 1

    compareTwoVariables()
      ->
        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

Questions and answers

These Q&A entries show E08082 and its fix: