-
Notifications
You must be signed in to change notification settings - Fork 21
Closed as not planned
Description
reproduction steps
using Scala 2.13.2,
$ scala -Wunused
Welcome to Scala 2.13.2 (OpenJDK 64-Bit Server VM, Java 1.8.0_252).
Type in expressions for evaluation. Or try :help.
scala> :paste
// Entering paste mode (ctrl-D to finish)
val optA: Option[Int] = Option(42)
val optB: Option[Int] = Option(0)
val x1: Option[Int] = for {
a <- optA
b <- optB
if a != b
} yield a
// Exiting paste mode, now interpreting.
b <- optB
^
<pastie>:6: warning: parameter value b in anonymous function is never used
val optA: Option[Int] = Some(42)
val optB: Option[Int] = Some(0)
val x1: Option[Int] = Some(42)
problem
It gives the warning because b
is not used in yield. Still, it is used in if a != b
. I guess that for comprehension is desugared more or less in:
optA.flatMap { a =>
optB.withFilter(b => a != b).map(b => a)
}
Instead it should be desugared in the following one in order not to get the warning:
optA.flatMap { a =>
optB.withFilter(b => a != b).map(_ => a)
}
gabro
Metadata
Metadata
Assignees
Labels
No labels