Using Results
● Beginner3 minSpec 3.7
A result must be used. To throw one away on purpose, write const _ = …
fn add(a: Int, b: Int) -> Int {
a + b
}
fn main() {
add(1, 2)
}The compiler refused the program:
kavach run unused.kav
error: the result of `add` is unused: use it, or write `const _ = …` to throw it awayA forgotten result is a common bug: making an updated copy of a value and never using it. When you really don't need the result, say so:
fn add(a: Int, b: Int) -> Int {
a + b
}
fn main() {
const _ = add(1, 2)
print("done")
}The program ran and printed:
kavach run discard.kav
doneThe one exception is Shared.update, whose new value may be left unused: counter.update(n => n + 1). See Shared State.
What Kavach does for you
A forgotten result is caught
Calling a function and ignoring what it gives back is an error, the classic bug of making an updated copy and never using it.
const _ =says "on purpose".