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
route file compilation warning ("-Ywarn-unused"): local val in method at is never used #6302
Comments
This might be related to SI-9158. If you look at the generated code, it seems like all the vals are being used. |
Looking at the generated code in routes/main/controllers/ReverseRoutes.scala (method at) the culprit might be the implicit value
even though it is being used.. |
The warnings still occur - I just tested with Play 2.6.0-M5 which uses Scala 2.12.2 - even though SI-9158 is fixed now. Seems like we have to wait even longer until this gets addressed in Scala. |
Having an identical experience to @mkurz's. |
@mkurz and @michaelahlers can you confirm this is still happening with RC2, after #7259? |
@marcospereira Still getting the warning using this test project https://github.com/mkurz/play-route-file-warnings:
|
Fixed half of them with #7538 -- the implicit
are coming from
and the So it's possible to remove the implicit val by collapsing reverseRouter.scala.twirl into a single line with an explicit import, but I'd far rather mark this with an annotation saying that the compiler should ignore the "unused" flag here. |
As far as I can tell, there is not an annotation or a flag option to ignore a line of code, or to suppress unused checks in a package or file. Closest I can find is scala/bug#7934 |
There is the option of running the generated code through scalafix (which would remove unused imports but not the implicit vals) or setting up a subproject which contained twirl code and then passing through the binary dependency... but those are hacks. The best answer I can give right now is to use the routing DSL, which uses macros internally and so isn't exposed to scala flags in the same way. |
This is pretty unfortunate, with |
@godenji see https://github.com/ghik/silencer as a possible option |
The only use of playframework/framework/src/play/src/main/scala/play/api/controllers/Assets.scala Line 606 in 7d40b7e
and it looks to me like it's only current purpose is to handle a specific case of adding a path variable for Asset routing. Since the _rrc variable is introduced for every route that has fixed parameters (not just this specific case), it would be unused in the general case.
It seems to me like only introducting
Does this seem like a workable approach? |
Since it wasn't too much work, I implemented something similar to the above here: #7838. It doesn't change the definition of |
They added |
For reference: scala/scala#8373 |
Generally I add the following to "-Wconf:cat=unused&src=routes/.*:s", // silence unused errors in generated routes files
"-Wconf:cat=unused&src=twirl/.*:s", // silence unused errors in generated twirl template files So one possibility is to automate adding these options in some way, or at least make it easy for users to mix that into their existing scala compiler options. One caveat here is that if Play adds to We might also explore using |
Has anyone experiences in working around this with Play3 and Scala3? Since the |
Yes, see https://www.youtube.com/watch?v=4EUpiCTVM1c&t=999s 😉 You probably have to wait for Hopefully it's merged and released soon 😉 @henricook have you come up with a workaround (I see you commented in scala/scala3#18782) |
Thanks for the tag @mkurz. I was using sbt-tpolecat for warnings as errors and found this blocking as a result. Seeing the scala ticket you've linked I decided to relax my warnings-as-errors requirement until it was released. This is fine for me on a brand new side project but I appreciate it won't be ideal for anyone with an existing project.
|
Also on Scala 2, unused import warning has an "origin" corresponding to the import selector.
but
That tweak was specifically because a top-level import isn't amenable to nowarn. |
Play Version (2.5.4 / 2.4.3 / 2.4.6 - not tested on other versions) - scala
Operating System (MacOS 10.10 - and probably all other OS's)
JDK (Oracle 1.8.0_72, OpenJDK 1.8.x, Azul Zing)
Behaviour
On my play app, I have a routes file with routes for public files. Recently I added the -Ywarn-unused compiler flag, and I'm getting some unexpected warnings.
Reproducible Test Case
activator new testingScalac
(choose play-scala from the template list)build.sbt
the flag withscalacOptions ++= Seq("-Ywarn-unused")
Am I doing something wrong on the routes file, or is it a playframework/compiler bug (I looked in github and couldn't find anything related to this)?
The text was updated successfully, but these errors were encountered: