Skip to content

Fix WUnused with idents in derived code #17095

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 15, 2023
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Fix for formatting and traverse call of inlined tree in wunused
  • Loading branch information
szymon-rd committed Mar 14, 2023
commit fab5e7b53b060ef8140c6801aa62684b515aa95c
12 changes: 7 additions & 5 deletions compiler/src/dotty/tools/dotc/transform/CheckUnused.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package dotty.tools.dotc.transform

import dotty.tools.dotc.ast.tpd
import dotty.tools.dotc.ast.tpd.TreeTraverser
import dotty.tools.dotc.ast.tpd.{Inlined, TreeTraverser}
import dotty.tools.dotc.ast.untpd
import dotty.tools.dotc.ast.untpd.ImportSelector
import dotty.tools.dotc.config.ScalaSettings
Expand Down Expand Up @@ -59,6 +59,7 @@ class CheckUnused extends MiniPhase:
// ========== SETUP ============

override def prepareForUnit(tree: tpd.Tree)(using Context): Context =
println(tree)
val data = UnusedData()
val fresh = ctx.fresh.setProperty(_key, data)
fresh
Expand All @@ -75,15 +76,16 @@ class CheckUnused extends MiniPhase:
traverser.traverse(tree)
ctx

def prepareForInlined(tree: Inlined)(using Context): Context =
traverser.traverse(tree.call)
ctx

override def prepareForIdent(tree: tpd.Ident)(using Context): Context =
if tree.symbol.exists then
val prefixes = LazyList.iterate(tree.typeOpt.normalizedPrefix)(_.normalizedPrefix).takeWhile(_ != NoType)
.take(10) // Failsafe for the odd case if there was an infinite cycle
for {
prefix <- prefixes
} {
for prefix <- prefixes do
unusedDataApply(_.registerUsed(prefix.classSymbol, None))
}
unusedDataApply(_.registerUsed(tree.symbol, Some(tree.name)))
else if tree.hasType then
unusedDataApply(_.registerUsed(tree.tpe.classSymbol, Some(tree.name)))
Expand Down