Skip to content

WarnUnused false positive when imported literal integer is narrowed #17318

Closed
@WojciechMazur

Description

@WojciechMazur

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:lintingLinting warnings enabled with -W or -Xlintitype:bug

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions