E07390: constant Boolean literal in expression is pointless

Category: E07xxx Full resolution · Reported in phase: SYMBOL_DEFINITION · Classification: POINTLESS_EXPRESSION · All error codes

What went wrong

You have a constant Boolean value (like true or false) in a condition, making it pointless.

Worked examples

Compilable examples demonstrating this error and the correct fix:

  • ek9 -q 66 (How does the while loop work?)
  • ek9 -q 67 (How does do-while work in EK9?)
  • ek9 -q 77 (How do guard variables work in while loops?)

How to fix it

  1. Remove condition if always true - just call directly
  2. Remove dead code if always false
  3. Use actual conditional logic

Common causes

  • Debug code left in: if true ...
  • A literal as the control of a ternary: 'true <- first else second' always yields 'first'
  • Copy/paste error
  • Incomplete refactoring

See also

  • E07390: constant Boolean in condition (this error)
  • E07370: unreachable code after throw

Examples

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

Fails with E07390: constant Boolean literal in expression is pointless

#!ek9
defines module error.e07390.bad

  defines function

    parenthesised()
      -> amount as Integer
      <- rtn as Integer: amount
      if (false)
        rtn: 1
      while (true)
        rtn++

    negatedOrNested()
      -> amount as Integer
      <- rtn as Integer: amount
      if not false
        rtn: 1
      while ((false))
        rtn++

Fixed: Use a condition that can change

#!ek9
defines module error.e07390.good

  defines function

    countDown()
      -> amount as Integer
      <- rtn as Integer: amount

      //A condition that can be either true or false
      while rtn > 0
        rtn--

Questions and answers

These Q&A entries show E07390 and its fix: