Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImplicitNotFound message creates undue warning #9763

Closed
scabug opened this issue Apr 20, 2016 · 12 comments
Closed

ImplicitNotFound message creates undue warning #9763

scabug opened this issue Apr 20, 2016 · 12 comments
Milestone

Comments

@scabug
Copy link

scabug commented Apr 20, 2016

The following code creates a spurious warning (because of the concatenated string):

@implicitNotFound("not found ${H}”+".") trait X[H]
possible missing interpolator: detected an interpolated expression
[warn] @implicitNotFound("not found ${H}"+".") trait X[H]

The warning disappears if we write

@implicitNotFound("not found ${H}.") trait X[H]

In my original code I broke the message in 2 because it was too long.

@scabug
Copy link
Author

scabug commented Apr 20, 2016

Imported From: https://issues.scala-lang.org/browse/SI-9763?orig=1
Reporter: @etorreborre
See #7411

@scabug
Copy link
Author

scabug commented Apr 20, 2016

@som-snytt said:
Related:

milessabin/shapeless@312b405

in case it didn't get an issue.

@scabug
Copy link
Author

scabug commented Apr 21, 2016

@milessabin said:
It didn't get an issue because it wasn't clear at the time whether this was a shapeless bug, a compiler bug or "in a macro, so undefined behaviour". Given that we can tickle the problem without either shapeless or macros involved blaming the compiler seems a lot more reasonable.

@scabug
Copy link
Author

scabug commented Apr 21, 2016

@paulp said:
This is #7411.

@scabug
Copy link
Author

scabug commented Apr 21, 2016

@som-snytt said:
Slight progressive mitigation:

$ scala -Xlint
Welcome to Scala 2.11.8 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_60).
Type in expressions for evaluation. Or try :help.

scala> import annotation._
import annotation._

scala> @implicitNotFound("No ${A}" + " at all") class C[A]
<console>:14: warning: possible missing interpolator: detected an interpolated expression
       @implicitNotFound("No ${A}" + " at all") class C[A]
                         ^
defined class C

scala> :quit
$ scalam -Xlint
Welcome to Scala 2.12.0-M4 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_60).
Type in expressions for evaluation. Or try :help.

scala> import annotation._
import annotation._

scala> @implicitNotFound("No ${A}" + " at all") class C[A]
defined class C

scala> :pa
// Entering paste mode (ctrl-D to finish)

object A
@implicitNotFound("No ${A}" + " at all") class C[A]

// Exiting paste mode, now interpreting.

<console>:15: warning: possible missing interpolator: detected an interpolated expression
       @implicitNotFound("No ${A}" + " at all") class C[A]
                         ^
defined object A
defined class C

It still warns if there is a value with the name of your type param.

@scabug
Copy link
Author

scabug commented Aug 10, 2016

@milessabin said:
@SethTisue While this is related to #7411 I don't think it's a duplicate. That ticket is calling for a general cleanup in the area, but isn't reporting a bug as such. This ticket on the other hand is reporting a very specific bug.

@scabug
Copy link
Author

scabug commented Aug 10, 2016

@som-snytt said:
I was going to comment similarly: current state of the art tries to avoid the undue warning. Apologies to the word "art".

It occurs to me that one fix for the other ticket is, if the "expected type" is an interpolated string (there is no such notion now), then apply an appropriate interpolator. A macro interpolator should be allowed to guide interpretation of holes (such as type args) (no such notion either).

@scabug
Copy link
Author

scabug commented Aug 11, 2016

@milessabin said:
Seeing as it's not just me I'll reopen and unduplicate. @SethTisue reclose if you disagree.

@scabug
Copy link
Author

scabug commented Aug 11, 2016

@etorreborre said:
Thanks Miles, I agree too.

@scabug
Copy link
Author

scabug commented Aug 11, 2016

@SethTisue said:
just testing y'all ;-)

@scabug
Copy link
Author

scabug commented Aug 11, 2016

@paulp said:
I guess I meant "this is SI-7411" in the sort of grandiose this-bug-wouldn't-even-be-possible-if-we-did-that way you've come to expect.

@som-snytt
Copy link

som-snytt commented Jan 15, 2020

Closing with the caveat there are two issues with the annotation:

  1. the lint is limited in detecting that it is in an ImplicitNotFound (what paulp said)
  2. the other lint for checking well-formedness is limited by ability to fetch the msg arg, see AnnotationInfos.

The interpolation here is legal and resonable but warns for reason 2:

// Missing argument `msg` on implicitNotFound annotation.
class C {
  final val A = "thing"
  @implicitNotFound(s"not found ${A}") trait T[B]
}
class D {
  final val A = "thing"
  @implicitNotFound("not found " + A) trait T[B]
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants