Merge pull request #4281 from lucacervello/suggest-lambda-operator

Add suggest lambda operator instead of when
This commit is contained in:
Richard Feldman 2022-10-31 10:29:46 -07:00 committed by GitHub
commit bc2ec738a0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 4 deletions

View file

@ -259,6 +259,17 @@ fn to_expr_report<'a>(
Context::InNode(Node::WhenBranch, _pos, _) => {
return to_unexpected_arrow_report(alloc, lines, filename, *pos, start);
}
Context::InDef(_pos) => {
vec![alloc.stack([
alloc.reflow("Looks like you are trying to define a function. "),
alloc.reflow("In roc, functions are always written as a lambda, like "),
alloc
.parser_suggestion("increment = \\n -> n + 1")
.indent(4),
])]
}
_ => {
vec![alloc.stack([
alloc.concat([

View file

@ -5653,11 +5653,11 @@ All branches in an `if` must have the same type!
4 main = 5 -> 3
^^
The arrow -> is only used to define cases in a `when`.
Looks like you are trying to define a function.
when color is
Red -> "stop!"
Green -> "go!"
In roc, functions are always written as a lambda, like
increment = \n -> n + 1
"###
);