Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Suppress "discarded non-Unit value" warning

I have added the scalac command line argument -Ywarn-value-discard to my build because this would have caught a subtle bug that I just found in my code. However, I now get some warnings for "discarded non-Unit value" that are about intentional discards, not bugs. How do I suppress those warnings?

like image 999
Robin Green Avatar asked Nov 16 '12 11:11

Robin Green


1 Answers

You suppress these warning by explictly returning unit (that is ()). By example turn this:

def method1() = {    println("Hello")    "Bye" } def method2() {   method1() // Returns "Bye", which is implicitly discarded } 

into:

def method1() = {    println("Hello")    "Bye" } def method2() {   method1()   () // Explicitly return unit } 
like image 60
Régis Jean-Gilles Avatar answered Oct 01 '22 01:10

Régis Jean-Gilles