Check inline expansion for exclusion
Fixes #23018
Preserve attachments on literals, check inline expansions for them, and avoid warning about purity when an inline expansion is a constant unit literal (such as assert(true) and similar reductions).
(The lint for "non-unit value in statement position" specifically does not warn. However, the purity check still warns for explicit parens, since they may have been intended as part of an application.)
Scala 2 warns at refchecks and at that time drills into the tree shapes that may have the attachment.
~The test shows status quo, where 42: Unit incorrectly warns, ironically.~
Already 😮! Thank you @som-snytt!
In scala 2, these checks are all pushed to refchecks. (I may have intended to follow up with that here.)
Also https://github.com/scala/scala3/pull/20408
This is a good one.
[warn] 282 | assert(6 * ChunkBits == ScalaFlagEnd)
[warn] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[warn] | A pure expression does nothing in statement position