Closed
Description
Scala 2 allows to discard non-unit value using : Unit
, however this behaviour seems to be missing in Scala 3.
Compiler version
All Scala 3 versions
Minimized code
//> using options -Wvalue-discard -Wnonunit-statement
object Tests {
class Assertion(assert: => Any){
def shouldPass(): Assertion = ???
}
def Test: Assertion = {
new Assertion("").shouldPass(): Unit
new Assertion("another").shouldPass()
}
}
Output
[warn] ./test.scala:8:5
[warn] discarded non-Unit value of type Tests.Assertion
[warn] new Assertion("").shouldPass(): Unit
[warn] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expectation
Should ignore non-uni statements with explicit :Unit
When : Unit
is missing compiler should hint how to silence the warning similarly as it's done in Scala 2
Compiling project (Scala 2.13.14, JVM (17))
[warn] ./test.scala:9:5
[warn] unused value of type Tests.Assertion (add `: Unit` to discard silently)
[warn] new Assertion("").shouldPass()
[warn] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^