Report anonymous functions as "this function" rather than symbol name

Closes #2453

Thanks for the assist @chris-packett
This commit is contained in:
Ayaz Hafiz 2022-08-10 15:26:52 -07:00
parent 1f45d13c67
commit fdb79da5a8
No known key found for this signature in database
GPG key ID: 0E2A37416A25EF58
4 changed files with 45 additions and 6 deletions

View file

@ -1184,7 +1184,10 @@ fn canonicalize_closure_body<'a>(
) -> (ClosureData, Output) {
// The globally unique symbol that will refer to this closure once it gets converted
// into a top-level procedure for code gen.
let symbol = opt_def_name.unwrap_or_else(|| scope.gen_unique_symbol());
let (symbol, is_anonymous) = match opt_def_name {
Some(name) => (name, false),
None => (scope.gen_unique_symbol(), true),
};
let mut can_args = Vec::with_capacity(loc_arg_patterns.len());
let mut output = Output::default();
@ -1245,7 +1248,12 @@ fn canonicalize_closure_body<'a>(
for (sub_symbol, region) in bound_by_argument_patterns {
if !output.references.has_value_lookup(sub_symbol) {
// The body never referenced this argument we declared. It's an unused argument!
env.problem(Problem::UnusedArgument(symbol, sub_symbol, region));
env.problem(Problem::UnusedArgument(
symbol,
is_anonymous,
sub_symbol,
region,
));
} else {
// We shouldn't ultimately count arguments as referenced locals. Otherwise,
// we end up with weird conclusions like the expression (\x -> x + 1)

View file

@ -35,8 +35,9 @@ pub enum Problem {
ExposedButNotDefined(Symbol),
UnknownGeneratesWith(Loc<Ident>),
/// First symbol is the name of the closure with that argument
/// Bool is whether the closure is anonymous
/// Second symbol is the name of the argument that is unused
UnusedArgument(Symbol, Symbol, Region),
UnusedArgument(Symbol, bool, Symbol, Region),
PrecedenceProblem(PrecedenceProblem),
// Example: (5 = 1 + 2) is an unsupported pattern in an assignment; Int patterns aren't allowed in assignments!
UnsupportedPattern(BadPattern, Region),