mirror of
https://github.com/roc-lang/roc.git
synced 2025-12-15 21:23:57 +00:00
Report anonymous functions as "this function" rather than symbol name
Closes #2453 Thanks for the assist @chris-packett
This commit is contained in:
parent
1f45d13c67
commit
fdb79da5a8
4 changed files with 45 additions and 6 deletions
|
|
@ -136,12 +136,16 @@ pub fn can_problem<'b>(
|
|||
title = UNKNOWN_GENERATES_WITH.to_string();
|
||||
severity = Severity::RuntimeError;
|
||||
}
|
||||
Problem::UnusedArgument(closure_symbol, argument_symbol, region) => {
|
||||
Problem::UnusedArgument(closure_symbol, is_anonymous, argument_symbol, region) => {
|
||||
let line = "\". Adding an underscore at the start of a variable name is a way of saying that the variable is not used.";
|
||||
|
||||
doc = alloc.stack([
|
||||
alloc.concat([
|
||||
alloc.symbol_unqualified(closure_symbol),
|
||||
if is_anonymous {
|
||||
alloc.reflow("This function")
|
||||
} else {
|
||||
alloc.symbol_unqualified(closure_symbol)
|
||||
},
|
||||
alloc.reflow(" doesn't use "),
|
||||
alloc.symbol_unqualified(argument_symbol),
|
||||
alloc.text("."),
|
||||
|
|
@ -153,7 +157,11 @@ pub fn can_problem<'b>(
|
|||
alloc.reflow(", then you can just remove it. However, if you really do need "),
|
||||
alloc.symbol_unqualified(argument_symbol),
|
||||
alloc.reflow(" as an argument of "),
|
||||
alloc.symbol_unqualified(closure_symbol),
|
||||
if is_anonymous {
|
||||
alloc.reflow("this function")
|
||||
} else {
|
||||
alloc.symbol_unqualified(closure_symbol)
|
||||
},
|
||||
alloc.reflow(", prefix it with an underscore, like this: \"_"),
|
||||
alloc.symbol_unqualified(argument_symbol),
|
||||
alloc.reflow(line),
|
||||
|
|
|
|||
|
|
@ -10307,4 +10307,26 @@ All branches in an `if` must have the same type!
|
|||
@r###"
|
||||
"###
|
||||
);
|
||||
|
||||
test_report!(
|
||||
anonymous_function_does_not_use_param,
|
||||
indoc!(
|
||||
r#"
|
||||
(\x -> 5) 1
|
||||
"#
|
||||
),
|
||||
@r###"
|
||||
── UNUSED ARGUMENT ─────────────────────────────────────── /code/proj/Main.roc ─
|
||||
|
||||
This function doesn't use `x`.
|
||||
|
||||
4│ (\x -> 5) 1
|
||||
^
|
||||
|
||||
If you don't need `x`, then you can just remove it. However, if you
|
||||
really do need `x` as an argument of this function, prefix it with an
|
||||
underscore, like this: "_`x`". Adding an underscore at the start of a
|
||||
variable name is a way of saying that the variable is not used.
|
||||
"###
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue