scala3 icon indicating copy to clipboard operation
scala3 copied to clipboard

Check inline expansion for exclusion

Open som-snytt opened this issue 7 months ago • 4 comments

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.~

som-snytt avatar Apr 19 '25 19:04 som-snytt

Already 😮! Thank you @som-snytt!

ahoy-jon avatar Apr 19 '25 21:04 ahoy-jon

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

som-snytt avatar Apr 29 '25 16:04 som-snytt

This is a good one.

[warn] 282 |    assert(6 * ChunkBits == ScalaFlagEnd)
[warn]     |    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[warn]     |    A pure expression does nothing in statement position

som-snytt avatar Jun 02 '25 17:06 som-snytt