Skip to content
Playground(another site)

bynk.lambda.unannotated_param

Error A lambda parameter has no type annotation in a position where no function type is expected to infer it from.

A lambda's parameter types come from where it is used: passed to map over a List[Int], (x) => x + 1 takes x: Int. A lambda standing alone, bound by a let for instance, has no such context, and the compiler asks for the type rather than guess it from the body. Annotate the parameter, or pass the lambda directly where a function type is expected.

Example

let f = (x) => x + x // ✗ nothing says what `x` is
let f = (x: Int) => x + x // ✓ annotated

In the Book

See also

  • The grammar rule it governs: lambda_expr.
  • Every code in its category, Other, on the diagnostic index.
  • bynk explain bynk.lambda.unannotated_param shows the same from the installed toolchain, without a network.