File tree 2 files changed +22
-3
lines changed
compiler/src/dotty/tools/dotc/transform
tests/neg-custom-args/fatal-warnings 2 files changed +22
-3
lines changed Original file line number Diff line number Diff line change @@ -351,16 +351,29 @@ object CheckUnused:
351
351
val used = usedInScope.pop().toSet
352
352
// used imports in this scope
353
353
val imports = impInScope.pop().toSet
354
- val kept = used.filter { t =>
354
+ val kept = used.filterNot { t =>
355
355
val (sym, isAccessible, optName) = t
356
356
// keep the symbol for outer scope, if it matches **no** import
357
- ! imports.exists { imp =>
357
+
358
+ // This is the first matching wildcard selector
359
+ var selWildCard : Option [ImportSelector ] = None
360
+
361
+ val exists = imports.exists { imp =>
358
362
sym.isInImport(imp, isAccessible, optName) match
359
363
case None => false
364
+ case optSel@ Some (sel) if sel.isWildcard =>
365
+ if selWildCard.isEmpty then selWildCard = optSel
366
+ // We keep wildcard symbol for the end as they have the least precedence
367
+ false
360
368
case Some (sel) =>
361
369
unusedImport -= sel
362
370
true
363
371
}
372
+ if ! exists && selWildCard.isDefined then
373
+ unusedImport -= selWildCard.get
374
+ true // a matching import exists so the symbol won't be kept for outer scope
375
+ else
376
+ exists
364
377
}
365
378
// if there's an outer scope
366
379
if usedInScope.nonEmpty then
Original file line number Diff line number Diff line change @@ -244,4 +244,10 @@ package foo.testing.rename.imports:
244
244
import collection .mutable .{Set => MutSet2 } // OK
245
245
import collection .mutable .{Set => MutSet3 } // error
246
246
type A [X ] = MutSet1 [X ]
247
- val a = MutSet2 (1 )
247
+ val a = MutSet2 (1 )
248
+
249
+ // -------------------------------------
250
+ package foo .testing .imports .precedence:
251
+ import scala .collection .immutable .{BitSet => _ , _ } // error
252
+ import scala .collection .immutable .BitSet // OK
253
+ def t = BitSet .empty
You can’t perform that action at this time.
0 commit comments