Skip to content

surprising unused warnings due to for comprehension desugaring #10287

@aryairani

Description

@aryairani

in 2.12.1 (and 2.11):

$ scala -Ywarn-unused
cat: /release: No such file or directory
Welcome to Scala 2.12.1 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_121).
Type in expressions for evaluation. Or try :help.

scala> object Foo {
     |   for {
     |     x <- Some(1 -> 2)
     |     y = 3
     |     (a, b) = x
     |   } yield (a + b)
     | }
<console>:14: warning: local val in value $anonfun is never used
           (a, b) = x
            ^
<console>:14: warning: local val in value $anonfun is never used
           (a, b) = x
               ^
defined object Foo

I get a warning that neither a nor b are used, although they are clearly used. No warning is issued for y, which is indeed unused.

In 2.12.2, no warnings are issued for a or b (yay) or y (boo). I acknowledge I may be doin' it wrong!

21:34 lawn-128-61-43-99:~/opensource/rho (master)$ scala -Ywarn-unused:_
Welcome to Scala 2.12.2 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_121).
Type in expressions for evaluation. Or try :help.

scala> object Foo {
     |   for {
     |     x <- Some(1 -> 2)
     |     y = 3
     |     (a, b) = x
     |   } yield (a + b)
     | }
defined object Foo

Side note, I would love to be able omit x altogether and use

object Foo {
  for {
    (a, b) <- MyObjectHavingFlatmap(1 -> 2)
  } yield (a + b)
}

without calling .filter, which is a bit scary to me.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions