diff --git a/compiler/src/dotty/tools/dotc/transform/CheckUnused.scala b/compiler/src/dotty/tools/dotc/transform/CheckUnused.scala index ade55138e15d..6b2a987dca8c 100644 --- a/compiler/src/dotty/tools/dotc/transform/CheckUnused.scala +++ b/compiler/src/dotty/tools/dotc/transform/CheckUnused.scala @@ -284,8 +284,11 @@ class CheckUnused private (phaseMode: PhaseMode, suffix: String) extends MiniPha case sel :: sels => val matches = if sel.isWildcard then + // if name is different from sym.name, it must be a rename on import, not a wildcard selector + !name.exists(_.toTermName != sym.name.toTermName) // the qualifier must have the target symbol as a member - hasAltMember(sym.name) && { + && hasAltMember(sym.name) + && { if sel.isGiven then // Further check that the symbol is a given or implicit and conforms to the bound sym.isOneOf(GivenOrImplicit) && (sel.bound.isEmpty || sym.info.finalResultType <:< sel.boundTpe) diff --git a/tests/warn/i15503a.scala b/tests/warn/i15503a.scala index 40b6c75983bf..3707b18d316e 100644 --- a/tests/warn/i15503a.scala +++ b/tests/warn/i15503a.scala @@ -321,3 +321,10 @@ object Suppressed: object Suppressing: import Suppressed.* // no warn, see options def f = 42 + +package i22692: + import javax.swing.* + import javax.swing.event as swingEvent // no warn, regression test for warning in 3.6 + + type b = AbstractButton + type t = swingEvent.AncestorListener