From db45a20cfa6c11c10a3908f4a63bdb09de95091d Mon Sep 17 00:00:00 2001 From: Szymon Rodziewicz Date: Fri, 29 Sep 2023 12:25:50 +0200 Subject: [PATCH] Fix false positive in WUnused for renamed path-dependent imports (attempt 2) [Cherry-picked cde97d8adbef89111bd20c760edeb5cc2617b5c8] --- .../src/dotty/tools/dotc/transform/CheckUnused.scala | 6 +++--- tests/pos/i18366.scala | 10 ++++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) create mode 100644 tests/pos/i18366.scala diff --git a/compiler/src/dotty/tools/dotc/transform/CheckUnused.scala b/compiler/src/dotty/tools/dotc/transform/CheckUnused.scala index 730ef9a32d2e..3b397d8be746 100644 --- a/compiler/src/dotty/tools/dotc/transform/CheckUnused.scala +++ b/compiler/src/dotty/tools/dotc/transform/CheckUnused.scala @@ -337,7 +337,7 @@ object CheckUnused: * - usage */ private class UnusedData: - import collection.mutable.{Set => MutSet, Map => MutMap, Stack => MutStack} + import collection.mutable.{Set => MutSet, Map => MutMap, Stack => MutStack, ListBuffer => MutList} import UnusedData.* /** The current scope during the tree traversal */ @@ -346,7 +346,7 @@ object CheckUnused: var unusedAggregate: Option[UnusedResult] = None /* IMPORTS */ - private val impInScope = MutStack(MutSet[tpd.Import]()) + private val impInScope = MutStack(MutList[tpd.Import]()) /** * We store the symbol along with their accessibility without import. * Accessibility to their definition in outer context/scope @@ -449,7 +449,7 @@ object CheckUnused: def pushScope(newScopeType: ScopeType): Unit = // unused imports : currScopeType.push(newScopeType) - impInScope.push(MutSet()) + impInScope.push(MutList()) usedInScope.push(MutSet()) def registerSetVar(sym: Symbol): Unit = diff --git a/tests/pos/i18366.scala b/tests/pos/i18366.scala new file mode 100644 index 000000000000..698510ad13a2 --- /dev/null +++ b/tests/pos/i18366.scala @@ -0,0 +1,10 @@ +//> using options -Xfatal-warnings -Wunused:all + +trait Builder { + def foo(): Unit +} + +def repro = + val builder: Builder = ??? + import builder.{foo => bar} + bar() \ No newline at end of file