Regression with macro and interpolation linting

There seems to be a bug with undue warnings after an upgrade from Scala 2.13.13 to 2.13.14.

With the following scalacOptions

Seq(
  "-Wmacros:after",
  "-Xlint:missing-interpolator",
)

Then the specs2 functions using the s2 interpolator (implemented as a macro) now display a warning:

possible missing interpolator: detected interpolated identifier `$invalidMessagesAreIgnored`

(see the full details here: "possible missing interpolator: detected interpolated identifier" warning when using s2 · Issue #1237 · etorreborre/specs2 · GitHub).

My question is: do you think it is really a bug that I should report to GitHub - scala/bug: Scala 2 bug reports only. Please, no questions — proper bug reports only. or is there something that should be done on the library side?

Thanks.

Thanks for asking!

-Wmacros gets a default mode (the default in 2.13.14) for “unused definitions” that means “examine the unexpanded tree that the user wrote for definitions and usages, but also look at the expanded tree for more usages.”

$ scalac -Wmacros:help
Usage: -Wmacros:<mode> where <mode> choices are none, before, after, both, default (default: default).
  none     Do not inspect expansions or their original trees when generating unused symbol warnings.
  before   Only inspect unexpanded user-written code for unused symbols.
  after    Only inspect expanded trees when generating unused symbol warnings.
  both     Inspect both user-written code and expanded trees when generating unused symbol warnings.
  default  Only inspect unexpanded user-written code for unused symbols but include usages in expansions.

Incidentally, -Wmacros:after also makes -Xlint:missing-interpolator look at trees during macro expansion. That is new behavior. Normally, if there are open macros, the lint is turned off.

The beginner sample for specs2 after expansion looks like:

QuickStartSpec.this.s2(
"\n\n  This is my first specification\n    it is working $ok\n    really working! $ok\n\n  \"\"\"\n}",

where ok is a term in scope. So that is what it is linting.

Probably -Wmacros:default (which is the default) is the desired setting.

I think -Wmacros:after would be useful for verifying that a macro is working correctly, rather than verifying user code.

If for some reason default mode results in false positives (for example, a definition must be available to a macro but isn’t used in code, similar to how scala.language imports work), then -Wmacros:none turns off the linting for both unexpanded and expanded trees.

Finally, maybe consulting -Wmacros during linting is a bad idea. There is a ticket (which I will close) suggesting “lints should respect -Wmacros”, but that was speculative. If this discussion doesn’t resolve your user issue, then a ticket would be welcome, proposing to undo that change.

1 Like

Thank you for the detailed answer :slightly_smiling_face: