- Notifications
You must be signed in to change notification settings - Fork3.1k
Add-quickfix compiler option to apply quickfixes to source files#10482
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
a7bd1db to3505209CompareWith 2.13.12 the compiler starts providing quick fixes with certainwarnings and errors. Typically these are presented in IDEs, howeverit can also be practical to have the compiler directly patch the sourcefiles.From `-quickfix:help`:```Apply quick fixes provided by the compiler for warnings and errors to source files.Syntax: -quickfix:<filter>,...,<filter><filter> syntax is the same as for configurable warnings, see `-Wconf:help`. Examples: -quickfix:any apply all available quick fixes -quickfix:msg=Auto-application apply quick fixes where the message contains "Auto-application"Use `-Wconf:any:warning-verbose` to display applicable message filters with each warning.```
-quickfix compiler option to apply quick fixes to source files-quickfix compiler option to apply quick fixes to source files-quickfix compiler option to apply quickfixes to source filesdongjoon-hyun pushed a commit to apache/spark that referenced this pull requestSep 30, 2023
### What changes were proposed in this pull request?This pr aims to upgrade Scala from 2.13.11 to 2.13.12.Additionally, this pr adds ``-Wconf:msg=legacy-binding:s`` to suppress similar compiler warnings as below:```[ERROR] /Users/yangjie01/SourceCode/git/spark-mine-13/core/src/main/scala/org/apache/spark/deploy/client/StandaloneAppClient.scala:171: reference to stop is ambiguous;it is both defined in the enclosing class StandaloneAppClient and inherited in the enclosing class ClientEndpoint as method stop (defined in trait RpcEndpoint, inherited through parent trait ThreadSafeRpcEndpoint)In Scala 2, symbols inherited from a superclass shadow symbols defined in an outer scope.Such references are ambiguous in Scala 3. To continue using the inherited symbol, write `this.stop`.Or use `-Wconf:msg=legacy-binding:s` to silence this warning. [quickfixable]Applicable -Wconf / nowarn filters for this fatal warning: msg=<part of the message>, cat=other, site=org.apache.spark.deploy.client.StandaloneAppClient.ClientEndpoint.receive```### Why are the changes needed?The new version bring some regression fixes:-scala/scala#10422-scala/scala#10424And a new feature: Quickfixes```For some errors and warnings, the compiler now suggests an edit that could fix the issue. Tooling such as IDEs can then offer the edits, or the compiler itself will make the change if run again with -quickfix.```-scala/scala#10406-scala/scala#10482-scala/scala#10484The release notes as follows:-https://github.com/scala/scala/releases/tag/v2.13.12### Does this PR introduce _any_ user-facing change?Yes, Scala version changed.### How was this patch tested?Pass Github### Was this patch authored or co-authored using generative AI tooling?NOCloses#43185 from LuciferYang/SPARK-45331.Authored-by: yangjie01 <yangjie01@baidu.com>Signed-off-by: Dongjoon Hyun <dhyun@apple.com>
rtyley added a commit to guardian/tagmanager that referenced this pull requestOct 22, 2024
…`()` is deprecatedScala 2.13 deprecates (with PRscala/scala#8833) the old behaviour of Scala that zero-parameter methods could be called with either one or zero pairs of parenthesis - ie if you have a method `def foo()` you could call it as `foo()` or just `foo`. With Scala 3, you have to match the number of brackets *used in the method declaration* when you call it - so you'd _have_ to use `foo()` or you'd get an error like this:```[error] ~/code/presence-indicator/app/actor/OpenSocketActor.scala:79:7: Auto-application to `()` is deprecated. Supply the empty argument list `()` explicitly to invoke method sender,[error] or remove the empty argument list from its definition (Java-defined methods are exempt).[error] In Scala 3, an unapplied method like this will be eta-expanded into a function. [quickfixable][error] sender ! Map(serverId -> (LiveActors(connectionPing, subscription)))[error] ^```Java methods are exempt from this restriction - you can call either `hashCode()` (which, in Java, is how the method _has_ to be defined, with empty brackets) or just `hashCode` (which is how that method would have been declared if it was declared in Scala, in Scala methods with no side-effects should be declared without brackets:https://docs.scala-lang.org/style/method-invocation.html#arity-0).## Automatically fixing this code issueThere are two possible ways of automating this code fix - in this small project, they both produce the same code changes:### Fixing if the project is already on Scala 2.13 - use `-quickfix` in `scalac`You can use the `-quickfix` support added to Scala 2.13.12 withscala/scala#10482:Add either of these to the `scalacOptions` in `build.sbt`:* `"-quickfix:any"` ...to apply *all* available quick fixes* `"-quickfix:msg=Auto-application"` ...to apply quick fixes where the message contains "Auto-application"Then run `compile` on the sbt console - the first compile will still fail, but it will subtly change the error message to say `[rewritten by -quickfix]` - your files have been edited to receive the fix:```[error] /Users/Roberto_Tyley/code/presence-indicator/app/actor/OpenSocketActor.scala:79:7: [rewritten by -quickfix] Auto-application to `()` is deprecated. Supply the empty argument list `()` explicitly to invoke method sender,[error] or remove the empty argument list from its definition (Java-defined methods are exempt).[error] In Scala 3, an unapplied method like this will be eta-expanded into a function.[error] sender ! Map(serverId -> (LiveActors(connectionPing, subscription)))[error] ^```...run `compile` a second time, and compiler will be much happier.Examples of other PRs using `-quickfix` to fix this code issue:*guardian/ophan#5719### Fixing while still on Scala 2.12 - use ScalafixFixing this everywhere in a project can be tedious, but thankfully there is a `ExplicitNonNullaryApply` Scalafix rule to fix this in thehttps://github.com/lightbend-labs/scala-rewrites project.The Scalafix rule needs to be run while the project is still on Scala 2.12, not Scala 2.13 (otherwise sbt will say: "Error downloading ch.epfl.scala:sbt-scalafix;sbtVersion=1.0;scalaVersion=2.13:0.13.0").Once the Scalafix plugin is made available to sbt (by adding `addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.13.0")`to either `project/plugins.sbt` or `~/.sbt/1.0/plugins.sbt`), you can run these commands on the sbt prompt to automatically generate the changes in this PR:```scalafixEnablescalafixAll dependency:fix.scala213.ExplicitNonNullaryApply@org.scala-lang:scala-rewrites:0.1.5```Examples of other PRs using Scalafix to fix this code issue:*guardian/mobile-apps-api#2728*guardian/presence-indicator#196See also:*scalacenter/scalafix#204*lightbend-labs/scala-rewrites#14
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
With 2.13.12 the compiler starts providing quick fixes with certain warnings and errors. Typically these are presented in IDEs, however it can also be practical to have the compiler directly patch the source files.
From
-quickfix:help: