Skip to content
Playground(another site)

bynk.parse.let_pattern_annotation

Error A let with a pattern carries a type annotation; the pattern's names take their types from the value.

A let that takes a value apart with a pattern gives its names the types they have in the value, so it has no place for an annotation after the pattern. Remove the : Type. To pin the type of the value itself, annotate an ordinary let first and match on that.

Example

fn count(r: Result[Int, String]) -> Int {
let Ok(n): Int = r else { 0 } // ✗ a pattern takes its types from the value
n
}
fn count(r: Result[Int, String]) -> Int {
let Ok(n) = r else { 0 } // ✓
n
}

In the Book

See also

  • The grammar rule it governs: let_else_stmt.
  • Every code in its category, Parser, on the diagnostic index.
  • bynk explain bynk.parse.let_pattern_annotation shows the same from the installed toolchain, without a network.