Skip to content

Commit f90da34

Browse files
committed
Check if import contains transparent inline in registerImport
1 parent 2230a07 commit f90da34

File tree

3 files changed

+17
-18
lines changed

3 files changed

+17
-18
lines changed

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

+14-15
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import dotty.tools.dotc.core.Decorators.{em, i}
1010
import dotty.tools.dotc.core.Flags.*
1111
import dotty.tools.dotc.core.Phases.Phase
1212
import dotty.tools.dotc.core.StdNames
13-
import dotty.tools.dotc.{ast, report}
13+
import dotty.tools.dotc.report
1414
import dotty.tools.dotc.reporting.Message
1515
import dotty.tools.dotc.typer.ImportInfo
1616
import dotty.tools.dotc.util.{Property, SrcPos}
@@ -365,7 +365,7 @@ object CheckUnused:
365365

366366
/** Register an import */
367367
def registerImport(imp: tpd.Import)(using Context): Unit =
368-
if !tpd.languageImport(imp.expr).nonEmpty && !imp.isGeneratedByEnum then
368+
if !tpd.languageImport(imp.expr).nonEmpty && !imp.isGeneratedByEnum && !isTransparentAndInline(imp) then
369369
impInScope.top += imp
370370
unusedImport ++= imp.selectors.filter { s =>
371371
!shouldSelectorBeReported(imp, s) && !isImportExclusion(s)
@@ -431,19 +431,6 @@ object CheckUnused:
431431
exists
432432
}
433433

434-
// not report unused transparent inline imports
435-
for {
436-
imp <- imports
437-
sel <- imp.selectors
438-
} {
439-
if unusedImport.contains(sel) then
440-
val tpd.Import(qual, _) = imp
441-
val importedMembers = qual.tpe.member(sel.name).alternatives.map(_.symbol)
442-
val isTransparentAndInline = importedMembers.exists(s => s.is(Transparent) && s.is(Inline))
443-
if isTransparentAndInline then
444-
unusedImport -= sel
445-
}
446-
447434
// if there's an outer scope
448435
if usedInScope.nonEmpty then
449436
// we keep the symbols not referencing an import in this scope
@@ -518,6 +505,18 @@ object CheckUnused:
518505
end getUnused
519506
//============================ HELPERS ====================================
520507

508+
509+
/**
510+
* Checks if import selects a def that is transparent and inline
511+
*/
512+
private def isTransparentAndInline(imp: tpd.Import)(using Context): Boolean =
513+
(for {
514+
sel <- imp.selectors
515+
} yield {
516+
val qual = imp.expr
517+
val importedMembers = qual.tpe.member(sel.name).alternatives.map(_.symbol)
518+
importedMembers.exists(s => s.is(Transparent) && s.is(Inline))
519+
}).exists(identity)
521520
/**
522521
* Heuristic to detect synthetic suffixes in names of symbols
523522
*/

tests/neg-custom-args/fatal-warnings/i15503f.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ val default_int = 1
55

66
def f1(a: Int) = a // OK
77
def f2(a: Int) = 1 // OK
8-
def f3(a: Int)(using Int) = a // error
8+
def f3(a: Int)(using Int) = a // OK
99
def f4(a: Int)(using Int) = default_int // error
1010
def f6(a: Int)(using Int) = summon[Int] // OK
1111
def f7(a: Int)(using Int) = summon[Int] + a // OK

tests/neg-custom-args/fatal-warnings/i15503g.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ val default_int = 1
55

66
def f1(a: Int) = a // OK
77
def f2(a: Int) = default_int // error
8-
def f3(a: Int)(using Int) = a // error
9-
def f4(a: Int)(using Int) = default_int // error // error
8+
def f3(a: Int)(using Int) = a // OK
9+
def f4(a: Int)(using Int) = default_int // OK
1010
def f6(a: Int)(using Int) = summon[Int] // error
1111
def f7(a: Int)(using Int) = summon[Int] + a // OK
1212

0 commit comments

Comments
 (0)