Add warnings for unused imported symbols #724
Labels
accepting contributions
Issues that are suitable to be worked on by anybody, not just maintainers
compiler
Changes related to the compiler
feature
New things to add to Inko, such as a new standard library module
Milestone
Description
When defining unused local variables, the compiler emits a warning. We should do the same for any unused symbols imported using the
import
statement.I'm not entirely sure yet how to best implement this, but I think it should be something along the lines of this:
When lowering to MIR, we keep track of used symbols using a
HashMap<types::Symbol, (LocationId, bool)>
(one such map per module, not per method).The
LocationId
is the MIR location ID at which the symbol import is defined (= the location at which the imported symbol is listed, i.e. thefoo
inimport std.whatever (foo)
).The
bool
defaults tofalse
and is set totrue
when referred to in a reachable block.At the end of a module we iterate over this map and add warnings for every
Symbol
where thebool
isfalse
, using theLocationId
to retrieve the line/column position, and using the current module file as the source file.Related work
No response
The text was updated successfully, but these errors were encountered: