Skip to content

Fix unused module name warning#5982

Open
jtdowney wants to merge 2 commits into
gleam-lang:mainfrom
jtdowney:fix-unused-module-name
Open

Fix unused module name warning#5982
jtdowney wants to merge 2 commits into
gleam-lang:mainfrom
jtdowney:fix-unused-module-name

Conversation

@jtdowney

Copy link
Copy Markdown
Member

This fixes an incorrect unused imported module warning when one imports local name matches another imports full module name.

For example

import wibble/wobble
import wobble as my_wobble

pub fn main() {
  wobble.hello()
  my_wobble.hello()
}

Both imports are used, but the compiler reported wibble/wobble as unused.

The type checker resolved wobble.hello() to wibble/wobble correctly. The reference tracker then recorded the use by looking up the string wobble again.

That lookup accepted two different kinds of names:

  • A local module name or alias, such as wobble or my_wobble
  • A full module name, such as wibble/wobble or wobble

Because the second import's full name was wobble, the reference tracker attached the use to the wrong import. Type checking and generated code were correct. Only the usage graph and the warning were wrong.

I also noticed and fixed a similar but different bug related to an import with a discard alias.

Closes #5975

  • The changes in this PR have been discussed beforehand in an issue
  • The issue for this PR has been linked
  • Tests have been added for new behaviour
  • The changelog has been updated for any user-facing changes

@lpil lpil left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fab, thank you! One tiny note inline

Comment thread compiler-core/src/reference.rs Outdated
@jtdowney
jtdowney force-pushed the fix-unused-module-name branch from df376c8 to c46a638 Compare July 17, 2026 14:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Probably incorrect report of "imported module is never used"

2 participants