Skip to content

Commit 8ff4754

Browse files
committed
Check if import contains transparent inline in registerImport
1 parent c36965c commit 8ff4754

File tree

3 files changed

+17
-18
lines changed

3 files changed

+17
-18
lines changed

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

Lines changed: 14 additions & 15 deletions
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}
@@ -368,7 +368,7 @@ object CheckUnused:
368368

369369
/** Register an import */
370370
def registerImport(imp: tpd.Import)(using Context): Unit =
371-
if !tpd.languageImport(imp.expr).nonEmpty && !imp.isGeneratedByEnum then
371+
if !tpd.languageImport(imp.expr).nonEmpty && !imp.isGeneratedByEnum && !isTransparentAndInline(imp) then
372372
impInScope.top += imp
373373
unusedImport ++= imp.selectors.filter { s =>
374374
!shouldSelectorBeReported(imp, s) && !isImportExclusion(s)
@@ -433,19 +433,6 @@ object CheckUnused:
433433
exists
434434
}
435435

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

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

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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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 // error
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)