Skip to content

Commit

Permalink
Fix WUnused for accessible symbols that are renamed (#17177)
Browse files Browse the repository at this point in the history
Fixes #17117
  • Loading branch information
Kordyjan authored Apr 12, 2023
2 parents 2297d25 + e72c020 commit e940957
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
4 changes: 3 additions & 1 deletion compiler/src/dotty/tools/dotc/transform/CheckUnused.scala
Original file line number Diff line number Diff line change
Expand Up @@ -603,11 +603,13 @@ object CheckUnused:
case (sel, sym) if dealias(sym) == dealiasedSym => sel
}.headOption else None
def wildcard = sels.find(sel => sel.isWildcard && ((sym.is(Given) == sel.isGiven) || sym.is(Implicit)))
if qualHasSymbol && !isAccessible && sym.exists then
if qualHasSymbol && (!isAccessible || sym.isRenamedSymbol(symName)) && sym.exists then
selector.orElse(dealiasedSelector).orElse(wildcard) // selector with name or wildcard (or given)
else
None

private def isRenamedSymbol(symNameInScope: Option[Name])(using Context) =
sym.name != nme.NO_NAME && symNameInScope.exists(_.toSimpleName != sym.name.toSimpleName)

private def dealias(symbol: Symbol)(using Context): Symbol =
if(symbol.isType && symbol.asType.denot.isAliasType) then
Expand Down
14 changes: 14 additions & 0 deletions tests/neg-custom-args/fatal-warnings/i15503i.scala
Original file line number Diff line number Diff line change
Expand Up @@ -287,3 +287,17 @@ package foo.test.i17156:
package c:
import b.Xd
trait Z derives Xd

package foo.test.i17117:
package example {
object test1 {
val test = "test"
}

object test2 {

import example.test1 as t1

val test = t1.test
}
}

0 comments on commit e940957

Please sign in to comment.