etorreborre / specs2

Software Specifications for Scala
http://specs2.org
Other
734 stars 215 forks source link

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

Closed yanns closed 4 months ago

yanns commented 4 months ago

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`
yanns commented 4 months ago

This happens when updating from 2.13.13 to 2.13.14.

etorreborre commented 4 months ago

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

yanns commented 4 months ago

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",
)
etorreborre commented 4 months ago

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.

yanns commented 4 months ago

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.

etorreborre commented 4 months ago

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

som-snytt commented 4 months ago

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

etorreborre commented 4 months ago

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

yanns commented 4 months ago

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

yanns commented 4 months ago

This is maybe a possible solution when using -Wmacros:after: https://github.com/eed3si9n/expecty/pull/161

etorreborre commented 4 months ago

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

som-snytt commented 4 months ago

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