etorreborre/specs2

"possible missing interpolator: detected interpolated identifier" warning when using s2

yanns opened this issue ยท 12 comments

When using s2, the scalac compiler emits this warning:

possible missing interpolator: detected interpolated identifier

Example:

  def is = s2"""
  ChangeSubscription should
    ignore invalid messages                                 $invalidMessagesAreIgnored
  """

  def invalidMessagesAreIgnored: MatchResult[Any] = { ... }

produces:

possible missing interpolator: detected interpolated identifier `$invalidMessagesAreIgnored`

This happens when updating from 2.13.13 to 2.13.14.

I tried to reproduce this issue but this works for me. Can you reproduce this on a smaller project?

I have checked deeper, and I could find the specific scalac flags one needs to use to reproduce this behavior:

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

Thanks, I can reproduce it now. I have no idea on how to fix this though, this looks like a compiler bug because s2 is definitely specifiied. Would macros:before work for you? Because that one does not raise a warning.

Would macros:before work for you? Because that one does not raise a warning.

Sadly not, as it's marking lots of implicits as not used as they're being used in some derivation macros.

My current solution is that use:

  @nowarn("msg=possible missing interpolator")
  def is = s2"""

Not perfect. Let's see if the next scalac version fixes this false positive so that I can remove the @nowarn annotation.

Sorry about that. I left a question on the Discourse forum to see if I should create a scalac bug next.

I responded on the forum, but the new option -Wmacros:default (which is the new default) will probably work better (it is -Wmacros:before but also find more usages after expansion), and also turns off the lint during expansion (which was the previous behavior).

Thanks @som-snytt! I thought I had tested it, but it seems to work ok. @yanns would that work on your full project?

Yes it's an acceptable solution for me. Thanks to both of you!

This is maybe a possible solution when using -Wmacros:after: eed3si9n/expecty#161

@yanns at this stage, I don't think I will dare touching the old macro code ๐Ÿ’ฃ, unless there's really no way out :-).

I think the burden is on the user of -Wmacros to also -Wconf. (My tweak for expecty is a bit silly and niche.)