From 0a0bc897f6f01fceab1a5d352f8589c5f7cc0b9d Mon Sep 17 00:00:00 2001 From: Anton-4 <17049058+Anton-4@users.noreply.github.com> Date: Thu, 26 Sep 2024 20:17:35 +0200 Subject: [PATCH] add final expression tip --- crates/compiler/load/tests/test_reporting.rs | 8 ++++++++ crates/reporting/src/error/parse.rs | 16 +++++++++++++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/crates/compiler/load/tests/test_reporting.rs b/crates/compiler/load/tests/test_reporting.rs index 6d964dcd12..7f6da75474 100644 --- a/crates/compiler/load/tests/test_reporting.rs +++ b/crates/compiler/load/tests/test_reporting.rs @@ -4339,6 +4339,14 @@ mod test_reporting { However, I already saw the final expression in that series of definitions. + + Tip: An expression like `4`, `"hello"`, or `functionCall MyThing` is + like `return 4` in other programming languages. To me, it seems like + you did `return 4` followed by more code in the lines after, that code + would never be executed! + + Tip: If you are working with `Task`, this error can happen if you + forgot a `!` somewhere. "### ); diff --git a/crates/reporting/src/error/parse.rs b/crates/reporting/src/error/parse.rs index 20ec3cce56..c4524a2c70 100644 --- a/crates/reporting/src/error/parse.rs +++ b/crates/reporting/src/error/parse.rs @@ -653,9 +653,19 @@ fn to_expr_report<'a>( r"and this line is indented as if it's intended to be part of that expression:", ), alloc.region_with_subregion(lines.convert_region(surroundings), region, severity), - alloc.concat([alloc.reflow( - "However, I already saw the final expression in that series of definitions.", - )]), + alloc.reflow( + "However, I already saw the final expression in that series of definitions." + ), + alloc.tip().append( + alloc.reflow( + "An expression like `4`, `\"hello\"`, or `functionCall MyThing` is like `return 4` in other programming languages. To me, it seems like you did `return 4` followed by more code in the lines after, that code would never be executed!" + ) + ), + alloc.tip().append( + alloc.reflow( + "If you are working with `Task`, this error can happen if you forgot a `!` somewhere." + ) + ) ]); Report {