- 
                Notifications
    You must be signed in to change notification settings 
- Fork 1.1k
Closed
Labels
area:lintingLinting warnings enabled with -W or -XlintLinting warnings enabled with -W or -Xlintitype:bug
Description
Compiler version
3.7.0
Minimized example
@main
def make: IndexedSeq[FalsePositive] =
  for {
    i <- 1 to 2
    given Int = i
    fp = FalsePositive()
  } yield fp
class FalsePositive(using Int):
  def usage(): Unit =
    println(summon[Int])Output Error/Warning message
[warn] -- [E198] Unused Symbol Warning: /<path>/main/src/main/scala/FalsePositive.scala:5:4 
[warn] 5 |    given Int = i
[warn]   |    ^^^^^^^^^
[warn]   |    unused pattern variable
[warn] one warning foundWhy this Error/Warning was not helpful
The message was unhelpful because the given Int is actually used - this is a "false positive".
Suggested improvement
The issue is with how code is structured in for-comprehension. If for-comprehension gets restructured to:
  for {
    i <- 1 to 2
    given Int = i
  } yield FalsePositive() // <=== notice that initialization happens without intermediate variableThe warning is not triggered any more!
Metadata
Metadata
Assignees
Labels
area:lintingLinting warnings enabled with -W or -XlintLinting warnings enabled with -W or -Xlintitype:bug