From cae2bb26745465eabe4a5a86178f35895bea9399 Mon Sep 17 00:00:00 2001 From: Szymon Rodziewicz Date: Mon, 4 Sep 2023 15:28:01 +0200 Subject: [PATCH] Revert Fix false positive in WUnused for renamed path-dependent imports --- .../src/dotty/tools/dotc/transform/CheckUnused.scala | 6 ++---- tests/pos-special/fatal-warnings/i18366.scala | 10 ---------- 2 files changed, 2 insertions(+), 14 deletions(-) delete mode 100644 tests/pos-special/fatal-warnings/i18366.scala diff --git a/compiler/src/dotty/tools/dotc/transform/CheckUnused.scala b/compiler/src/dotty/tools/dotc/transform/CheckUnused.scala index f40993314257..0eeec0f3cbec 100644 --- a/compiler/src/dotty/tools/dotc/transform/CheckUnused.scala +++ b/compiler/src/dotty/tools/dotc/transform/CheckUnused.scala @@ -661,10 +661,8 @@ object CheckUnused: val simpleSelections = qual.tpe.member(sym.name).alternatives val typeSelections = sels.flatMap(n => qual.tpe.member(n.name.toTypeName).alternatives) val termSelections = sels.flatMap(n => qual.tpe.member(n.name.toTermName).alternatives) - val sameTermPath = qual.isTerm && sym.exists && sym.owner.isType && qual.tpe.typeSymbol == sym.owner.asType val selectionsToDealias = typeSelections ::: termSelections - val renamedSelection = if sameTermPath then sels.find(sel => sel.imported.name == sym.name) else None - val qualHasSymbol = simpleSelections.map(_.symbol).contains(sym) || (simpleSelections ::: selectionsToDealias).map(_.symbol).map(dealias).contains(dealiasedSym) || renamedSelection.isDefined + val qualHasSymbol = simpleSelections.map(_.symbol).contains(sym) || (simpleSelections ::: selectionsToDealias).map(_.symbol).map(dealias).contains(dealiasedSym) def selector = sels.find(sel => (sel.name.toTermName == sym.name || sel.name.toTypeName == sym.name) && symName.map(n => n.toTermName == sel.rename).getOrElse(true)) def dealiasedSelector = if(isDerived) sels.flatMap(sel => selectionsToDealias.map(m => (sel, m.symbol))).collect { case (sel, sym) if dealias(sym) == dealiasedSym => sel @@ -674,7 +672,7 @@ object CheckUnused: else None def wildcard = sels.find(sel => sel.isWildcard && ((sym.is(Given) == sel.isGiven && sel.bound.isEmpty) || sym.is(Implicit))) if qualHasSymbol && (!isAccessible || sym.isRenamedSymbol(symName)) && sym.exists then - selector.orElse(dealiasedSelector).orElse(givenSelector).orElse(wildcard).orElse(renamedSelection) // selector with name or wildcard (or given) + selector.orElse(dealiasedSelector).orElse(givenSelector).orElse(wildcard) // selector with name or wildcard (or given) else None diff --git a/tests/pos-special/fatal-warnings/i18366.scala b/tests/pos-special/fatal-warnings/i18366.scala deleted file mode 100644 index bd25d607e897..000000000000 --- a/tests/pos-special/fatal-warnings/i18366.scala +++ /dev/null @@ -1,10 +0,0 @@ -// scalac: -Wunused:all - -trait Builder { - def foo(): Unit -} - -def repro = - val builder: Builder = ??? - import builder.{foo => bar} - bar() \ No newline at end of file