Why is calling a computational operator without using its result an error in EK9?

← Code Quality · Ref: Q815

EK9 detects when a computational operator is called explicitly but its return value is discarded. This is dead code — the computation achieves nothing.

WHAT TRIGGERS E11050

Calling an operator via method syntax and ignoring the result:

  a._eq(b)     // computes equality but throws away the Boolean
  a.+(b)       // computes addition but throws away the result

These statements achieve nothing — the result is computed and discarded.

MUTATING VS COMPUTATIONAL

Mutating operators return Void and are valid as statements:

  a += b       // modifies a in place, no return to discard
  counter++    // mutates counter, Void return

Computational operators return values that must be used:

  isEqual <- a == b    // use the result
  sum <- a + b         // capture the value

HOW TO FIX

- Assign the result: isEqual <- a._eq(b)
- Use in an expression: if a == b
- If you want mutation, use the mutating operator: a += b

See Q310 for code quality overview. See Q316 for operator semantics.

Example

defines module qa.quality.discarded.return

  defines program

    DiscardedReturnDemo()
      -> greeting as String
      stdout <- Stdout()

      farewell <- "goodbye"

      // === CORRECT: capture the explicit operator call result ===
      isEqual <- greeting.==(farewell)
      stdout.println(`Equal: ${isEqual}`)

      // === CORRECT: use in an expression ===
      if greeting == farewell
        stdout.println("same")
      else
        stdout.println("different")

      // === CORRECT: explicit operator call with captured result ===
      price <- 100
      tax <- 15
      sum <- price.+(tax)
      require sum?

      // === CORRECT: mutating operators are fine as statements ===
      counter <- 0
      counter++
      stdout.println("Counter: " + $counter)

Common mistakes

E11050 — Calling the + operator via explicit method syntax and discarding the result means the addition achieves nothing. Assign the result or use the mutating operator +=. See ek9 -h E11050 for details.

Incorrect:

      price.+(tax)
      require price?

Correct:

      sum <- price.+(tax)
      require sum?
Other ways to ask this
  • What is E11050 DISCARDED_OPERATOR_RETURN?
  • Why can't I call an operator as a bare statement in EK9?
  • How do I fix discarded return value errors in EK9?

Coming from another language?

Java: silently discards operator results in expression statements. Python: same — no warning for unused computation. Rust: warns about unused Result but not operators. Go: requires using all return values. EK9: makes discarded computational operator returns a compile error.

Keywords: dead, mutation, computational, quality, return, operator, discarded, E11050, code