From 6c4e2c873801dc48c3e1f73c6313d83313f7e771 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Wed, 16 Nov 2022 23:11:47 -0500 Subject: [PATCH] Revise wording on unnecessary wildcard warning My concern with the previous wording is that: - Beginners will be confused by "these are always open" - Users advanced enough to understand what that actually means won't benefit from seeing it in this warning message! --- crates/reporting/src/error/canonicalize.rs | 15 +++++++++++++-- crates/reporting/tests/test_reporting.rs | 13 +++++++++---- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/crates/reporting/src/error/canonicalize.rs b/crates/reporting/src/error/canonicalize.rs index 3188c21738..b5b26e4125 100644 --- a/crates/reporting/src/error/canonicalize.rs +++ b/crates/reporting/src/error/canonicalize.rs @@ -1017,9 +1017,20 @@ pub fn can_problem<'b>( } Problem::UnnecessaryOutputWildcard { region } => { doc = alloc.stack([ - alloc.reflow("I see you annotated a wildcard in a place where it's not needed:"), + alloc.concat([ + alloc.reflow("This type annotation has a wildcard type variable ("), + alloc.keyword("*"), + alloc.reflow(") that isn't needed."), + ]), alloc.region(lines.convert_region(region)), - alloc.reflow("Tag unions that are constants, or the return values of functions, are always inferred to be open by default! You can remove this annotation safely."), + alloc.concat([ + alloc.reflow("Annotations for tag unions which are constants, or which are returned from functions, work the same way with or without a "), + alloc.keyword("*"), + alloc.reflow(" at the end. (The "), + alloc.keyword("*"), + alloc.reflow(" means something different when the tag union is an argument to a function, though!)"), + ]), + alloc.reflow("You can safely remove this to make the code more concise without changing what it means."), ]); title = "UNNECESSARY WILDCARD".to_string(); severity = Severity::Warning; diff --git a/crates/reporting/tests/test_reporting.rs b/crates/reporting/tests/test_reporting.rs index ab79c82024..56d0e73105 100644 --- a/crates/reporting/tests/test_reporting.rs +++ b/crates/reporting/tests/test_reporting.rs @@ -11772,14 +11772,19 @@ All branches in an `if` must have the same type! @r###" ── UNNECESSARY WILDCARD ────────────────────────────────── /code/proj/Main.roc ─ - I see you annotated a wildcard in a place where it's not needed: + This type annotation has a wildcard type variable (`*`) that isn't + needed. 4│ f : {} -> [A, B]* ^ - Tag unions that are constants, or the return values of functions, are - always inferred to be open by default! You can remove this annotation - safely. + Annotations for tag unions which are constants, or which are returned + from functions, work the same way with or without a `*` at the end. (The + `*` means something different when the tag union is an argument to a + function, though!) + + You can safely remove this to make the code more concise without + changing what it means. "### );