Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 31 additions & 31 deletions compiler/src/dotty/tools/dotc/transform/CheckUnused.scala
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ class CheckUnused private (phaseMode: PhaseMode, suffix: String) extends MiniPha
if matches then sel else loop(sels)
case nil => null
loop(info.selectors)
end matchingSelector

def checkMember(ctxsym: Symbol): Boolean =
ctxsym.isClass && sym.owner.isClass
Expand All @@ -407,38 +408,37 @@ class CheckUnused private (phaseMode: PhaseMode, suffix: String) extends MiniPha
val cur = ctxs.next()
if cur.owner.userSymbol == sym && !sym.is(Package) then
enclosed = true // found enclosing definition, don't record the reference
if isLocal then
if cur.owner eq sym.owner then
done = true // for local def, just checking that it is not enclosing
else
if cur.isImportContext then
val sel = matchingSelector(cur.importInfo.nn)
if sel != null then
if cur.importInfo.nn.isRootImport then
if precedence.weakerThan(OtherUnit) then
precedence = OtherUnit
candidate = cur
importer = sel
done = true
else if sel.isWildcard then
if precedence.weakerThan(Wildcard) then
precedence = Wildcard
candidate = cur
importer = sel
else
if precedence.weakerThan(NamedImport) then
precedence = NamedImport
candidate = cur
importer = sel
else if checkMember(cur.owner) then
if sym.is(Package) || sym.srcPos.sourcePos.source == ctx.source then
precedence = Definition
candidate = cur
importer = null // ignore import in same scope; we can't check nesting level
if cur.isImportContext then
val sel = matchingSelector(cur.importInfo.nn)
if sel != null then
if cur.importInfo.nn.isRootImport then
if precedence.weakerThan(OtherUnit) then
precedence = OtherUnit
candidate = cur
importer = sel
done = true
else if precedence.weakerThan(OtherUnit) then
precedence = OtherUnit
candidate = cur
else if sel.isWildcard then
if precedence.weakerThan(Wildcard) then
precedence = Wildcard
candidate = cur
importer = sel
else
if precedence.weakerThan(NamedImport) then
precedence = NamedImport
candidate = cur
importer = sel
else if isLocal then
if cur.owner eq sym.owner then
done = true // local def or param
else if checkMember(cur.owner) then
if sym.is(Package) || sym.srcPos.sourcePos.source == ctx.source then
precedence = Definition
candidate = cur
importer = null // ignore import in same scope; we can't check nesting level
done = true
else if precedence.weakerThan(OtherUnit) then
precedence = OtherUnit
candidate = cur
end while
// record usage and possibly an import
if !enclosed then
Expand Down
20 changes: 20 additions & 0 deletions tests/warn/i24633.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//> using options -Werror -Wunused:imports

object foo {
val min = 0
val max = 1
}

def test(max: Int) = {
import foo.{max as _, *}
s"$min - $max"
}

def local =
val max = 42
import foo.{max as _, *}
s"$min - $max"

class Limit(max: Int):
import foo.{max as _, *}
def test = s"$min - $max"
Loading