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: Give each if and while a condition that can change, instead of a Boolean literal

#!ek9
defines module error.e07390.good.fix

  defines function

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

    negatedOrNested()
      -> amount as Integer
      <- rtn as Integer: amount
      if not amount?
        rtn: 1
      while (rtn > amount)
        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:

Found a problem?

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