What is a logical tautology and why does EK9 reject it?

← Data Flow Safety · Ref: Q795

EK9 detects logical tautologies and contradictions at compile time (E08085). A tautology is an expression that is ALWAYS true regardless of operand values. A contradiction is ALWAYS false.

TAUTOLOGY PATTERNS (always true)

  - flag or not flag: always true
  - not flag or flag: always true

CONTRADICTION PATTERNS (always false)

  - flag and not flag: always false
  - not flag and flag: always false

WHY REJECTED

These expressions indicate logic errors - typically a copy-paste mistake or incorrect variable name. If always-true is intended, use 'true' directly. If always-false, use 'false'.

CORRECT ALTERNATIVES

  - ready or fallback: different variables - valid
  - enabled and not expired: different variables - valid

See Q632 for define-before-use. See Q789 for unused variables.

Example

defines module qa.dataflowsafety.logicaltautology

  defines function

    checkAvailability()
      ->
        isReady as Boolean
        hasFallback as Boolean
      <- result as Boolean?

      result: isReady or hasFallback

    checkRequirements()
      ->
        isEnabled as Boolean
        isExpired as Boolean
      <- result as Boolean?

      result: isEnabled and not isExpired

Common mistakes

E08085 — The expression 'isReady or not isReady' is a logical tautology - it is always true regardless of the value of isReady. Use different variables or simplify to 'true'. See ek9 -h E08085 for details.

Incorrect:

      result: isReady or not isReady

Correct:

      result: isReady or hasFallback
Other ways to ask this
  • What triggers E08085 logical tautology?
  • Why does 'flag or not flag' cause a compiler error?
  • How does EK9 detect always-true logical expressions?

Coming from another language?

Java: no compiler detection, relies on FindBugs/SpotBugs. Python: no detection, relies on pylint. Rust: clippy warns about tautological comparisons. Kotlin: IntelliJ warns but compiles. Go: go vet does not detect logical tautologies. EK9: compile-time error E08085, code cannot proceed past this check.

Keywords: logical, dead, code, tautology, always, E08085, false, contradiction, true