From 86169a85b6ed891eb2bb6376d7bcfeb57a71a24d Mon Sep 17 00:00:00 2001 From: Som Snytt Date: Tue, 4 Mar 2025 17:48:20 -0800 Subject: [PATCH 1/2] Rename on import is never wildcard [Cherry-picked 977232cf3d919ccb6bf7c3fb93eda4b9241dac53] --- compiler/src/dotty/tools/dotc/transform/CheckUnused.scala | 5 ++++- tests/warn/i15503a.scala | 7 +++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/compiler/src/dotty/tools/dotc/transform/CheckUnused.scala b/compiler/src/dotty/tools/dotc/transform/CheckUnused.scala index 22d27cb61c66..a0ad1abb9724 100644 --- a/compiler/src/dotty/tools/dotc/transform/CheckUnused.scala +++ b/compiler/src/dotty/tools/dotc/transform/CheckUnused.scala @@ -275,8 +275,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 From fdf7cdc254edf3408a8d910ab8f7150aad04072d Mon Sep 17 00:00:00 2001 From: Tomasz Godzik Date: Wed, 23 Apr 2025 18:27:24 +0200 Subject: [PATCH 2/2] bugfix: Adjust givens to old syntax --- tests/warn/i15503f.scala | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/warn/i15503f.scala b/tests/warn/i15503f.scala index 79ee0a1767d4..76badc659fb9 100644 --- a/tests/warn/i15503f.scala +++ b/tests/warn/i15503f.scala @@ -57,10 +57,10 @@ package givens: trait Y: def doY: String - given X: + given X with def doX = 7 - given X => Y: // warn protected param to given class + given (using X): Y with // warn protected param to given class def doY = "7" /* desugared. It is protected so that its type can be used in member defs without leaking. * possibly it should be protected only for named parameters. @@ -72,6 +72,6 @@ package givens: new givens.given_Y(using x$1)() */ - given namely: (x: X) => Y: // warn protected param to given class + given namely (using x: X): Y with // warn protected param to given class def doY = "8" end givens