Skip to content

Commit 86169a8

Browse files
som-snytttgodzik
authored andcommitted
Rename on import is never wildcard
[Cherry-picked 977232c]
1 parent 05fb7bc commit 86169a8

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

compiler/src/dotty/tools/dotc/transform/CheckUnused.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,8 +275,11 @@ class CheckUnused private (phaseMode: PhaseMode, suffix: String) extends MiniPha
275275
case sel :: sels =>
276276
val matches =
277277
if sel.isWildcard then
278+
// if name is different from sym.name, it must be a rename on import, not a wildcard selector
279+
!name.exists(_.toTermName != sym.name.toTermName)
278280
// the qualifier must have the target symbol as a member
279-
hasAltMember(sym.name) && {
281+
&& hasAltMember(sym.name)
282+
&& {
280283
if sel.isGiven then // Further check that the symbol is a given or implicit and conforms to the bound
281284
sym.isOneOf(GivenOrImplicit)
282285
&& (sel.bound.isEmpty || sym.info.finalResultType <:< sel.boundTpe)

tests/warn/i15503a.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,3 +321,10 @@ object Suppressed:
321321
object Suppressing:
322322
import Suppressed.* // no warn, see options
323323
def f = 42
324+
325+
package i22692:
326+
import javax.swing.*
327+
import javax.swing.event as swingEvent // no warn, regression test for warning in 3.6
328+
329+
type b = AbstractButton
330+
type t = swingEvent.AncestorListener

0 commit comments

Comments
 (0)