Skip to content

warn unused regression involving refutability check in for comprehension #10763

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

Closed
adriaanm opened this issue Mar 8, 2018 · 4 comments
Closed
Assignees
Milestone

Comments

@adriaanm
Copy link
Contributor

adriaanm commented Mar 8, 2018

Looks like scala/scala#6190 regressed linting for unused stuff a local val captured in a CBN closure is not seen as used:

class Test {
  def timed[T](body: => T) = body

  def run(): Boolean = {
    val grouped = List(("bla","bla"))


    val (_, _) = timed {
      for ((kind, paths) <- grouped) {
        println("")
      }
      (1, 2)
    }
    
    false
  }
}

nok:

➜  Desktop sbt 'set resolvers += "pr-integration" at "https://scala-ci.typesafe.com/artifactory/scala-integration"' 'set scalaVersion := "2.12.5-bin-56918e4"' 'set scalacOptions ++= Seq("-Xfatal-warnings", "-Xlint:unused")' compile
[info] Compiling 1 Scala source to /Users/adriaan/Desktop/target/scala-2.12/classes...
[error] /Users/adriaan/Desktop/unused_captured.scala:5: local val grouped in method run is never used
[error]     val grouped = List(("bla","bla"))
[error]         ^
[error] one error found
[error] (compile:compileIncremental) Compilation failed
[error] Total time: 2 s, completed Mar 8, 2018 11:25:25 AM

ok:

➜  Desktop sbt 'set resolvers += "pr-integration" at "https://scala-ci.typesafe.com/artifactory/scala-integration"' 'set scalaVersion := "2.12.5-bin-f78f517"' 'set scalacOptions ++= Seq("-Xfatal-warnings", "-Xlint:unused")' compile
[info] Compiling 1 Scala source to /Users/adriaan/Desktop/target/scala-2.12/classes...
[success] Total time: 3 s, completed Mar 8, 2018 11:25:49 AM
@adriaanm adriaanm added this to the 2.12.5 milestone Mar 8, 2018
@adriaanm adriaanm self-assigned this Mar 8, 2018
@som-snytt
Copy link

Can I get a Scala/Center t-shirt with stripes in blocker red for Scala and regression orange for Center?

@som-snytt
Copy link

som-snytt commented Mar 8, 2018

@adriaanm There's also a weird error in which it refuses to create /tmp/Test.class. This is fresh 2.12.x on MacOS.

$ scalac -d /tmp -Xlint  oops.scala
oops.scala:3: warning: type parameter T defined in method timed shadows trait T defined in package <empty>. You may want to rename your type parameter, or possibly remove it.
  def timed[T](body: => T) = body
            ^
one warning found
$ skalac -d /tmp -Xlint  oops.scala
oops.scala:3: warning: type parameter T defined in method timed shadows trait T defined in package <empty>. You may want to rename your type parameter, or possibly remove it.
  def timed[T](body: => T) = body
            ^
oops.scala:6: warning: local val grouped in method run is never used
    val grouped = List(("bla","bla"))
        ^
error: error writing Test: Can't create directory /tmp; there is an existing (non-directory) file in its path
two warnings found
one error found

@adriaanm adriaanm changed the title warn unused regression with local val captured by closure (in for comprehension?) warn unused regression involving refutability check in for comprehension Mar 9, 2018
@adriaanm
Copy link
Contributor Author

adriaanm commented Mar 9, 2018

Smaller version (fits on a t-shirt sleeve):

class Test {
  def xsUnused = {
    val xs: List[Int] = List(0)

    for (refute@1 <- xs) {} // xs is reported as unused when it's hidden in a synthetic withFilter call?
  }
}

@lrytz
Copy link
Member

lrytz commented Mar 12, 2018

scala/scala#6404

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants