Skip to content

No unused value warning inside of if statement #22214

Closed as not planned
Closed as not planned
@OndrejSpanel

Description

@OndrejSpanel

Compiler version

3.5.2, 3.6.2

Minimized code

object Main {
  def fun(): String = ""
  def main(args: Array[String]): Unit = {
    fun() // warning here
    if (true) {
      fun() // no warning
    }
  }
}

Compile with -Wnonunit-statement

Output

C:\Dev\Sandbox\src\main\scala\Main.scala:4:8
unused value of type String
    fun()

Expectation

The warning should be given both on lines 4 and 6, but the discarded value on line 6 is silently ignored.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions