Skip to content
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

Wunused: Only use type treverser for checking refinements in refined type trees #17929

Merged
merged 1 commit into from
Jun 27, 2023
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
10 changes: 7 additions & 3 deletions compiler/src/dotty/tools/dotc/transform/CheckUnused.scala
Original file line number Diff line number Diff line change
Expand Up @@ -229,15 +229,15 @@ class CheckUnused private (phaseMode: CheckUnused.PhaseMode, suffix: String, _ke
pushInBlockTemplatePackageDef(tree)
traverseChildren(tree)(using newCtx)
popOutBlockTemplatePackageDef()
case t:tpd.ValDef =>
case t: tpd.ValDef =>
prepareForValDef(t)
traverseChildren(tree)(using newCtx)
transformValDef(t)
case t:tpd.DefDef =>
case t: tpd.DefDef =>
prepareForDefDef(t)
traverseChildren(tree)(using newCtx)
transformDefDef(t)
case t:tpd.TypeDef =>
case t: tpd.TypeDef =>
prepareForTypeDef(t)
traverseChildren(tree)(using newCtx)
transformTypeDef(t)
Expand All @@ -248,6 +248,10 @@ class CheckUnused private (phaseMode: CheckUnused.PhaseMode, suffix: String, _ke
prepareForAssign(t)
traverseChildren(tree)
case _: tpd.InferredTypeTree =>
case [email protected](tpt, refinements) =>
//! DIFFERS FROM MINIPHASE
typeTraverser(unusedDataApply).traverse(t.tpe)
traverse(tpt)(using newCtx)
case [email protected]() =>
//! DIFFERS FROM MINIPHASE
typeTraverser(unusedDataApply).traverse(t.tpe)
Expand Down
34 changes: 34 additions & 0 deletions tests/pos-special/fatal-warnings/i17631.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// scalac: -Wunused:all

object foo {
type Bar
}

import foo.Bar

def Test = {

type Person = { val name: String }

def good: Person = ???
def bad1: { val name: String } = ???
def bad2 = (good: { val name: String })
def justIs: { val bar: Bar } = ???
(bad1, bad2, justIs)
}

class Record(elems: (String, Any)*) extends Selectable:
private val fields = elems.toMap
def selectDynamic(name: String): Any = fields(name)

object Main {

type Person = Record { val name: String; val age: Int }

locally {
def good: Person = ???
def bad1: Record { val name: String; val age: Int } = ???
def bad2 = (good: Record { val name: String; val age: Int })
(bad1, bad2)
}
}