bynk.parse.bare_expression_statement
Error An expression stands alone as a statement, followed by more of the block; a block has no expression statements, so its value would be discarded. Bind it with let _ <- (an effect) or let _ =.
A block has no expression statements: each statement is a let, do, expect, := and so on, and the last expression is the block's value. An expression written on its own line with more of the block after it would have its value thrown away, so the compiler asks you to say what happens to it. Bind it: let _ = expr when you only want to discard a value, or let _ <- expr when it is an effect to run and await (a call through a capability or an agent, or a cell's .update). The parser cannot see types, so it picks the <- form for a call that looks like an effect and the = form otherwise, and its note names the other. The fix is machine-applicable, so bynk check --fix applies it.
Example
on call bump() -> Effect[Result[Int, String]] { count.update((c) => c + 1) // ✗ an expression standing alone Ok(count)}
on call bump() -> Effect[Result[Int, String]] { let _ <- count.update((c) => c + 1) // ✓ the effect is bound Ok(count)}
let _ = a + b // ✓ a plain value you mean to discardIn the Book
See also
- The grammar rule it governs:
block. - Every code in its category, Parser, on the diagnostic index.
bynk explain bynk.parse.bare_expression_statementshows the same from the installed toolchain, without a network.