Skip to content

Fix WUnused false positive in for #17176

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 3 commits into from
Apr 13, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
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 @@ -358,7 +358,8 @@ object CheckUnused:
usedInScope.top += ((sym, sym.isAccessibleAsIdent, name, isDerived))
usedInScope.top += ((sym.companionModule, sym.isAccessibleAsIdent, name, isDerived))
usedInScope.top += ((sym.companionClass, sym.isAccessibleAsIdent, name, isDerived))
name.map(n => usedInPosition += ((sym.sourcePos, n)))
if sym.sourcePos.exists then
name.map(n => usedInPosition += ((sym.sourcePos, n)))

/** Register a symbol that should be ignored */
def addIgnoredUsage(sym: Symbol)(using Context): Unit =
Expand Down Expand Up @@ -473,6 +474,7 @@ object CheckUnused:
if ctx.settings.WunusedHas.explicits then
explicitParamInScope
.filterNot(d => d.symbol.usedDefContains)
.filterNot(d => usedInPosition.exists { case (pos, name) => d.span.contains(pos.span) && name == d.symbol.name})
.filterNot(d => containsSyntheticSuffix(d.symbol))
.map(d => d.namePos -> WarnTypes.ExplicitParams).toList
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class Revaluing(u: Int) { def f = u } // OK

case class CaseyKasem(k: Int) // OK

case class CaseyAtTheBat(k: Int)(s: String) // error
case class CaseyAtTheBat(k: Int)(s: String) // ok

trait Ignorance {
def f(readResolve: Int) = answer // error
Expand Down
14 changes: 12 additions & 2 deletions tests/neg-custom-args/fatal-warnings/i15503i.scala
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ package foo.test.possibleclasses:
k: Int, // OK
private val y: Int // OK /* Kept as it can be taken from pattern */
)(
s: Int, // error /* But not these */
s: Int,
val t: Int, // OK
private val z: Int // error
)
Expand Down Expand Up @@ -131,7 +131,7 @@ package foo.test.possibleclasses.withvar:
k: Int, // OK
private var y: Int // OK /* Kept as it can be taken from pattern */
)(
s: Int, // error /* But not these */
s: Int,
var t: Int, // OK
private var z: Int // error
)
Expand Down Expand Up @@ -287,3 +287,13 @@ package foo.test.i17156:
package c:
import b.Xd
trait Z derives Xd

package foo.test.i17175:
val continue = true
def foo =
for {
i <- 1.until(10) // OK
if continue
} {
println(i)
}