E11050: operator returns a value but result is discarded - assign to variable or use in expression
What went wrong
An operator that returns a value was used as a standalone statement. The computed result is discarded — this is dead code.
Operators like +, -, *, /, ==, <>, contains, matches, length, ?, $ return values that represent the computation result. Discarding them means the computation was pointless.
Worked examples
Compilable examples demonstrating this error and the correct fix:
- ek9 -q 815 (Why is calling a computational operator without using its...)
Rationale
EK9's operator model is precise: mutating operators (+=, -=, :=:, ++, --) return Void because the side-effect IS the purpose. Computational operators return values because the VALUE is the purpose. If you discard that value, the statement achieves nothing.
How to fix it
- Assign the result: total <- price + tax
- Use in an expression: if price > limit
- If the side-effect was intended, use the mutating operator instead: price += tax
See also
Examples
Every example is compiled by the EK9 compiler: the first fails exactly as captioned, the others fix it.
Fails with E11050: operator returns a value but result is discarded - assign to variable or use in expression
#!ek9 defines module error.e11050.bad defines function testDiscardedComparisonOperator() a <- "hello" b <- "world" a.==(b) testDiscardedAddOperator() a <- 10 b <- 20 a.+(b) testDiscardedNotEqualOperator() a <- "hello" b <- "world" a.<>(b)
Fixed: Use the result of the operator
#!ek9 defines module error.e11050.good defines function sameWord() <- rtn as Boolean? first <- "hello" second <- "world" rtn: first == second total() <- rtn as Integer? first <- 10 second <- 20 rtn: first + second
Questions and answers
These Q&A entries show E11050 and its fix: