mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-03 00:24:34 +00:00
Merge pull request #4800 from Lunarmagpie/improve-arrow-error-message
Update error message to better explain `->`
This commit is contained in:
commit
25aeab943a
2 changed files with 16 additions and 3 deletions
|
@ -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),
|
||||||
])]
|
])]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -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
|
||||||
|
|
||||||
"###
|
"###
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue