Skip to content

Conversation

@lihaoyi
Copy link
Contributor

@lihaoyi lihaoyi commented Jan 10, 2026

Attempts to fix #24582. One-shot vibe coded

Root Cause: In CheckShadowing.scala, the isAnImportedType method had a bug at line 280:

val simpleSelections = qual.tpe.member(sym.name).alternatives

This looked up the type parameter's name (S) directly on the import qualifier (scala.compiletime.ops.int) regardless of what was actually imported. Even when only + was imported (import int.+), it would still find S in the int object and report it as shadowed.

Fix: Only perform this lookup when there's a wildcard import:

val hasWildcard = sels.exists(_.isWildcard)
val simpleSelections = if hasWildcard then qual.tpe.member(sym.name).alternatives else Nil

Test cases verify:

  1. Specific import (import int.+) does NOT warn for unrelated type params - fixed
  2. Wildcard import (import MyModule.*) DOES warn - still works
  3. Explicit type import (import MyModule.A) DOES warn - still works
  4. Renamed import (import MyModule.{A => RenamedA}) does NOT warn for original name - still works
  5. Multiple selectors work correctly - still works

@som-snytt
Copy link
Contributor

This is on my list because it is an occasion to refactor.

@Gedochao Gedochao requested a review from som-snytt January 13, 2026 09:50
@Gedochao
Copy link
Contributor

This is on my list because it is an occasion to refactor.

Or just refactor for refactor's sake, separately 😅
Since it's been on your mind, thoughts on this solution?

@som-snytt
Copy link
Contributor

Thanks, another way to say it is that this is an excuse to look at that code!

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.

Spurious shadowing warning with -Wshadow:type-parameter-shadow

3 participants