You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This isn't under a flag. It doesn't do anything with Object#equals.
scala> def f = { 1 + 1 ; 2 }
^
warning: a pure expression does nothing in statement position; multiline expressions might require enclosing parentheses
def f: Int
scala> def f = { 1 == 1 ; 2 }
^
warning: a pure expression does nothing in statement position; multiline expressions might require enclosing parentheses
def f: Int
scala> def f = { "" == "" ; 2 }
def f: Int
Here, "pure" means "looks like a constant", IIRC. It could special case equals for String, or string equality for constants could be constant-folded, etc.
The heuristic could be improved, and maybe add a strict option that would be more like detecting value discard.
-Wunused only means a symbol that was introduced but not referenced. (For imports, a selector was never used to look up a symbol.)
-Wvalue-discard warns that value discard conversion was applied. That's not in the middle of a block, in "statement position", but only at the end, in "result position", when Unit is expected.
The heuristic could be improved, and maybe add a strict option that would be more like detecting value discard.
reproduction steps
using Scala 2.13.2,
With these compiler options:
problem
The compiler does not catch that the first two expressions are unused.
The text was updated successfully, but these errors were encountered: