Skip to content

Commit 4cdc72f

Browse files
szymon-rdKordyjan
authored andcommitted
Check if import contains transparent inline in registerImport
1 parent 3969ba9 commit 4cdc72f

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}
@@ -360,7 +360,7 @@ object CheckUnused:
360360

361361
/** Register an import */
362362
def registerImport(imp: tpd.Import)(using Context): Unit =
363-
if !tpd.languageImport(imp.expr).nonEmpty && !imp.isGeneratedByEnum then
363+
if !tpd.languageImport(imp.expr).nonEmpty && !imp.isGeneratedByEnum && !isTransparentAndInline(imp) then
364364
impInScope.top += imp
365365
unusedImport ++= imp.selectors.filter { s =>
366366
!shouldSelectorBeReported(imp, s) && !isImportExclusion(s)
@@ -426,19 +426,6 @@ object CheckUnused:
426426
exists
427427
}
428428

429-
// not report unused transparent inline imports
430-
for {
431-
imp <- imports
432-
sel <- imp.selectors
433-
} {
434-
if unusedImport.contains(sel) then
435-
val tpd.Import(qual, _) = imp
436-
val importedMembers = qual.tpe.member(sel.name).alternatives.map(_.symbol)
437-
val isTransparentAndInline = importedMembers.exists(s => s.is(Transparent) && s.is(Inline))
438-
if isTransparentAndInline then
439-
unusedImport -= sel
440-
}
441-
442429
// if there's an outer scope
443430
if usedInScope.nonEmpty then
444431
// we keep the symbols not referencing an import in this scope
@@ -513,6 +500,18 @@ object CheckUnused:
513500
end getUnused
514501
//============================ HELPERS ====================================
515502

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

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)