Skip to content

-Wunused: false positive for pure expressions in for-yield #16823

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
hejfelix opened this issue Feb 3, 2023 · 10 comments
Closed

-Wunused: false positive for pure expressions in for-yield #16823

hejfelix opened this issue Feb 3, 2023 · 10 comments
Labels
area:linting Linting warnings enabled with -W or -Xlint itype:bug
Milestone

Comments

@hejfelix
Copy link

hejfelix commented Feb 3, 2023

Compiler version

3.3.0-RC2

Minimized code

  for
    x <- List(1,2,3) // unused pattern variable warning
    y = x * 2
  yield y

Expectation

no warning since the pattern variable is used in the pure expression

@hejfelix hejfelix added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Feb 3, 2023
@mbovel mbovel added area:reporting Error reporting including formatting, implicit suggestions, etc and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Feb 5, 2023
@SethTisue
Copy link
Member

same as scala/bug#10287 perhaps? cc @som-snytt

@som-snytt
Copy link
Contributor

The comment on the feature PR (at some point) was that fidelity of representation should make analysis easier in Scala 3, so hopefully this ticket is not as discouraging.

@hejfelix
Copy link
Author

hejfelix commented Feb 9, 2023

same as scala/bug#10287 perhaps? cc @som-snytt

Doesn't seem to be exactly the same, but could be same root cause?

@jchyb jchyb added area:linting Linting warnings enabled with -W or -Xlint and removed area:reporting Error reporting including formatting, implicit suggestions, etc labels Feb 12, 2023
@SethTisue
Copy link
Member

SethTisue commented Feb 13, 2023

What compiler settings are needed to reproduce this? I'm not able to reproduce it with:

//> using scala "3.3.0-RC2"
//> using option "-Wunused:all"

object O:
  for
    x <- List(1,2,3)
    y = x * 2
  yield y

@som-snytt
Copy link
Contributor

@SethTisue not sure how output works, but

➜   ./bin/scala -Wunused:privates
Welcome to Scala 3.3.1-RC1-bin-SNAPSHOT-git-8c616bf (19, Java OpenJDK 64-Bit Server VM).
Type in expressions for evaluation. Or try :help.

scala> class C { private def f = 42 }
Formatted members List()
// defined class C

scala>
➜  ./bin/scalac -Wunused:privates -d /tmp c.scala
-- Warning: c.scala:2:22 -----------------------------------------------------------------------------------------------
2 |class C { private def f = 42 }
  |                      ^
  |                      unused private member
1 warning found

@SethTisue
Copy link
Member

same result (no warning) with -Wunused:privates (which one would hope -Wunused:all would include, anyway)

@som-snytt
Copy link
Contributor

I intended to show that if REPL reporter doesn't report, it's conceivable that the command runner reporter doesn't report, so possibly only scalac reports? and maybe metals?

@hejfelix
Copy link
Author

I tried to minimize it, but I can't seem to provoke it now. I'll see if it persists in my larger project.

@hejfelix
Copy link
Author

hejfelix commented Feb 14, 2023

It seems to happen in cross-projects:

// plugins.sbt
addSbtPlugin("org.scala-js"              % "sbt-scalajs"              % "1.13.0")
addSbtPlugin("org.portable-scala"        % "sbt-scalajs-crossproject" % "1.2.0")


// build.sbt
val scala3Version = "3.3.0-RC2"

lazy val root = crossProject(JSPlatform,JVMPlatform)
  .in(file("."))
  .settings(
    name := "wunused-repro",
    version := "0.1.0-SNAPSHOT",
    scalaVersion := scala3Version,
    scalacOptions ++= Seq("-Wunused:unsafe-warn-patvars")
  )

// jvm/src/main/scala/Main.scala

@main def run = println("HEY")

val xs =
  for 
    x <- List(1,2,3) // unused pattern variable
    y = x * 2
  yield y

@szymon-rd
Copy link
Contributor

Fixed with #17020

@Kordyjan Kordyjan modified the milestones: 3.3.0 backports, 3.3.0 Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:linting Linting warnings enabled with -W or -Xlint itype:bug
Projects
None yet
Development

No branches or pull requests

7 participants