From db9c00ec1ec48e8adfed756fbbaf7ed37134d7ab Mon Sep 17 00:00:00 2001 From: Lunarmagpie Date: Thu, 22 Dec 2022 21:00:58 -0500 Subject: [PATCH 1/4] update docs to better explain -> operator --- crates/reporting/tests/test_reporting.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/crates/reporting/tests/test_reporting.rs b/crates/reporting/tests/test_reporting.rs index da3db9af29..de74eaf394 100644 --- a/crates/reporting/tests/test_reporting.rs +++ b/crates/reporting/tests/test_reporting.rs @@ -5645,11 +5645,16 @@ All branches in an `if` must have the same type! 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 Red -> "stop!" Green -> "go!" + + And defining functions: + + increment = \n -> n + 1 + "### ); From 3265a786a5300cdcb59c1b99385c628593366c42 Mon Sep 17 00:00:00 2001 From: Lunarmagpie Date: Fri, 23 Dec 2022 11:01:50 -0500 Subject: [PATCH 2/4] make changes suggested by folkertdev --- crates/reporting/src/error/parse.rs | 6 ++++-- crates/reporting/tests/test_reporting.rs | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/crates/reporting/src/error/parse.rs b/crates/reporting/src/error/parse.rs index 2b4f33caf3..674ae02663 100644 --- a/crates/reporting/src/error/parse.rs +++ b/crates/reporting/src/error/parse.rs @@ -279,8 +279,8 @@ fn to_expr_report<'a>( alloc.reflow("The arrow "), alloc.parser_suggestion("->"), alloc.reflow(" is only used to define cases in a "), - alloc.keyword("when"), - alloc.reflow("."), + alloc.keyword("`when`"), + alloc.reflow("expression:"), ]), alloc .vcat(vec![ @@ -289,6 +289,8 @@ fn to_expr_report<'a>( alloc.text("Green -> \"go!\"").indent(4), ]) .indent(4), + alloc.reflow("And to define a function:"), + alloc.reflow("increment = \\n -> n + 1").indent(4), ])] } }, diff --git a/crates/reporting/tests/test_reporting.rs b/crates/reporting/tests/test_reporting.rs index de74eaf394..b8524d110d 100644 --- a/crates/reporting/tests/test_reporting.rs +++ b/crates/reporting/tests/test_reporting.rs @@ -5651,7 +5651,7 @@ All branches in an `if` must have the same type! Red -> "stop!" Green -> "go!" - And defining functions: + And to define a function: increment = \n -> n + 1 From f932bb66a06559afab76870a5d1cd4a0e6f1adf7 Mon Sep 17 00:00:00 2001 From: Lunarmagpie Date: Fri, 23 Dec 2022 11:07:57 -0500 Subject: [PATCH 3/4] Add function binding to error message --- crates/reporting/src/error/parse.rs | 5 ++++- crates/reporting/tests/test_reporting.rs | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/crates/reporting/src/error/parse.rs b/crates/reporting/src/error/parse.rs index 674ae02663..e099dc87fc 100644 --- a/crates/reporting/src/error/parse.rs +++ b/crates/reporting/src/error/parse.rs @@ -290,7 +290,10 @@ fn to_expr_report<'a>( ]) .indent(4), alloc.reflow("And to define a function:"), - alloc.reflow("increment = \\n -> n + 1").indent(4), + alloc.vcat(vec![ + alloc.text("increment : I64 -> I64"), + alloc.text("increment = \\n -> n + 1"), + ]).indent(4) ])] } }, diff --git a/crates/reporting/tests/test_reporting.rs b/crates/reporting/tests/test_reporting.rs index b8524d110d..452b009380 100644 --- a/crates/reporting/tests/test_reporting.rs +++ b/crates/reporting/tests/test_reporting.rs @@ -5653,6 +5653,7 @@ All branches in an `if` must have the same type! And to define a function: + increment : I64 -> I64 increment = \n -> n + 1 "### From 439befcc3808f00f2ae5af451ed688a0b1bbf80d Mon Sep 17 00:00:00 2001 From: Folkert Date: Fri, 23 Dec 2022 17:19:54 +0100 Subject: [PATCH 4/4] run `cargo fmt` --- crates/reporting/src/error/parse.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/crates/reporting/src/error/parse.rs b/crates/reporting/src/error/parse.rs index e099dc87fc..8da55ccc68 100644 --- a/crates/reporting/src/error/parse.rs +++ b/crates/reporting/src/error/parse.rs @@ -290,10 +290,12 @@ fn to_expr_report<'a>( ]) .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) + alloc + .vcat(vec![ + alloc.text("increment : I64 -> I64"), + alloc.text("increment = \\n -> n + 1"), + ]) + .indent(4), ])] } },