Skip to content

Commit 48c5885

Browse files
Backport "Fix false positive in WUnused for renamed path-dependent imports (2)" to LTS (#20690)
Backports #18617 to the LTS branch. PR submitted by the release tooling. [skip ci]
2 parents 13168d8 + f92118b commit 48c5885

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ object CheckUnused:
337337
* - usage
338338
*/
339339
private class UnusedData:
340-
import collection.mutable.{Set => MutSet, Map => MutMap, Stack => MutStack}
340+
import collection.mutable.{Set => MutSet, Map => MutMap, Stack => MutStack, ListBuffer => MutList}
341341
import UnusedData.*
342342

343343
/** The current scope during the tree traversal */
@@ -346,7 +346,7 @@ object CheckUnused:
346346
var unusedAggregate: Option[UnusedResult] = None
347347

348348
/* IMPORTS */
349-
private val impInScope = MutStack(MutSet[tpd.Import]())
349+
private val impInScope = MutStack(MutList[tpd.Import]())
350350
/**
351351
* We store the symbol along with their accessibility without import.
352352
* Accessibility to their definition in outer context/scope
@@ -449,7 +449,7 @@ object CheckUnused:
449449
def pushScope(newScopeType: ScopeType): Unit =
450450
// unused imports :
451451
currScopeType.push(newScopeType)
452-
impInScope.push(MutSet())
452+
impInScope.push(MutList())
453453
usedInScope.push(MutSet())
454454

455455
def registerSetVar(sym: Symbol): Unit =

tests/pos/i18366.scala

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
//> using options -Xfatal-warnings -Wunused:all
2+
3+
trait Builder {
4+
def foo(): Unit
5+
}
6+
7+
def repro =
8+
val builder: Builder = ???
9+
import builder.{foo => bar}
10+
bar()

0 commit comments

Comments
 (0)