Skip to content
Playground(another site)

bynk.types.let_annotation_mismatch

Error A let value does not match its type annotation.

A let with a type annotation declares what the binding is, and its value must have exactly that type. The annotation is the contract that later code reads, so a value of another type is refused at the let, not where it is later used. Nothing is converted for you: change the value, convert it explicitly, or correct the annotation if the value is what you meant. The same rule governs a function's declared return, which is bynk.types.return_mismatch.

Example

fn run() -> Int {
let n: Int = "three" // ✗ a `String`, annotated `Int`
n
}
fn run() -> Int {
let n: Int = 3 // ✓
n
}

In the Book

See also

  • The grammar rule it governs: let_stmt.
  • Every code in its category, Type checking, on the diagnostic index.
  • bynk explain bynk.types.let_annotation_mismatch shows the same from the installed toolchain, without a network.