Skip to content

WarnUnused false positive when imported literal integer is narrowed #17318

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
WojciechMazur opened this issue Apr 19, 2023 · 0 comments · Fixed by #20894
Closed

WarnUnused false positive when imported literal integer is narrowed #17318

WojciechMazur opened this issue Apr 19, 2023 · 0 comments · Fixed by #20894
Labels
area:linting Linting warnings enabled with -W or -Xlint itype:bug
Milestone

Comments

@WojciechMazur
Copy link
Contributor

Compiler version

3.3.0-RC4
3.3.1-RC1-bin-20230418-bd0858e-NIGHTLY

Minimized code

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

object events {
  final val POLLIN = 0x001 
}

def withShort(v: Short): Unit = ???
def withInt(v: Int): Unit = ???

def usage() = 
  import events.POLLIN // reports unused
  def v: Short = POLLIN
  println(v)

def usage2() = 
  import events.POLLIN // reports unused
  withShort(POLLIN)

def usage3() =
  import events.POLLIN // does not report unused
  withInt(POLLIN) 

Output

Compiling project (Scala 3.3.0-RC4, JVM)
[warn] ./test.scala:12:17
[warn] unused import
[warn]   import events.POLLIN // reports unused
[warn]                 ^^^^^^
[warn] ./test.scala:17:17
[warn] unused import
[warn]   import events.POLLIN // reports unused
[warn]                 ^^^^^^
Compiled project (Scala 3.3.0-RC4, JVM)

Expectation

Should not report as unsued

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

Successfully merging a pull request may close this issue.

1 participant