Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add warnings for unused imported symbols #724

Open
yorickpeterse opened this issue Jun 19, 2024 · 1 comment
Open

Add warnings for unused imported symbols #724

yorickpeterse opened this issue Jun 19, 2024 · 1 comment
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

Comments

@yorickpeterse
Copy link
Collaborator

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. the foo in import std.whatever (foo)).

The bool defaults to false and is set to true 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 the bool is false, using the LocationId to retrieve the line/column position, and using the current module file as the source file.

Related work

No response

@yorickpeterse yorickpeterse added accepting contributions Issues that are suitable to be worked on by anybody, not just maintainers feature New things to add to Inko, such as a new standard library module compiler Changes related to the compiler labels Jun 19, 2024
@yorickpeterse
Copy link
Collaborator Author

Note that when a symbol is aliased as part of an import, the LocationId should point to the location of the alias, instead of the location of the original symbol name.

@yorickpeterse yorickpeterse added this to the 0.17.0 milestone Aug 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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
Projects
None yet
Development

No branches or pull requests

1 participant