bug icon indicating copy to clipboard operation
bug copied to clipboard

Wnonunit-statement must specify match branch, etc

Open som-snytt opened this issue 3 years ago • 1 comments

Reproduction steps

Warning on a large match, where one of the cases has an interesting result, doesn't show which case(s) is interesting.

Problem

It's not usable on matches of appreciable size.

Also, it reports "result type" but not the tree shape; that is, perhaps under verbose flag, show the tree.

som-snytt avatar Sep 26 '22 02:09 som-snytt

Also it's not handling sb.append(x).append(y). I must have dreamt that.

Also p.asInstanceOf[T].m. Also p.synchronized.

Also nested unibranch if in result position.

That's from a pass over the code base.

som-snytt avatar Sep 28 '22 01:09 som-snytt

Perhaps Scala 3 will do better once it has -Wnonunit-statement at all :-)

SethTisue avatar Jan 13 '23 16:01 SethTisue

@SethTisue No, it has the same issue. (Or one of them.)

-- [E176] Potential Issue Warning: test/files/pos/t12653.scala:19:84 ---------------------------------------------------
19 |    buf.append("symbol table = " + (if (syms.length == 0) "<empty>" else "")).append(EOL)
   |    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |    unused value of type (buf : StringBuilder)
2 warnings found

So arguably it does better. Edit, no it's just failing to warn, such as:

test/files/pos/t12653.scala:25: warning: unused value of type C (add `: Unit` to discard silently)
  def morely(): Unit = new C().more("hello").more(", ").more("world")

som-snytt avatar Jun 12 '23 06:06 som-snytt