Merge pull request #4800 from Lunarmagpie/improve-arrow-error-message

Update error message to better explain `->`
This commit is contained in:
Folkert de Vries 2022-12-23 19:23:45 +01:00 committed by GitHub
commit 25aeab943a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 3 deletions

View file

@ -279,8 +279,8 @@ fn to_expr_report<'a>(
alloc.reflow("The arrow "), alloc.reflow("The arrow "),
alloc.parser_suggestion("->"), alloc.parser_suggestion("->"),
alloc.reflow(" is only used to define cases in a "), alloc.reflow(" is only used to define cases in a "),
alloc.keyword("when"), alloc.keyword("`when`"),
alloc.reflow("."), alloc.reflow("expression:"),
]), ]),
alloc alloc
.vcat(vec![ .vcat(vec![
@ -289,6 +289,13 @@ fn to_expr_report<'a>(
alloc.text("Green -> \"go!\"").indent(4), alloc.text("Green -> \"go!\"").indent(4),
]) ])
.indent(4), .indent(4),
alloc.reflow("And to define a function:"),
alloc
.vcat(vec![
alloc.text("increment : I64 -> I64"),
alloc.text("increment = \\n -> n + 1"),
])
.indent(4),
])] ])]
} }
}, },

View file

@ -5645,11 +5645,17 @@ All branches in an `if` must have the same type!
5 1 -> True 5 1 -> True
^^ ^^
The arrow -> is only used to define cases in a `when`. The arrow -> is used to define cases in a `when` expression:
when color is when color is
Red -> "stop!" Red -> "stop!"
Green -> "go!" Green -> "go!"
And to define a function:
increment : I64 -> I64
increment = \n -> n + 1
"### "###
); );