How to prevent Intellij from treating Scala warning as error? - scala

I'm trying out Intellij on a mixed Java/Scala project. Build is failing with errors like this:
Error: scala:
/home/kevin/ij/backend/srctest/com/example/package/DoStuffTest.java:35:
warning: [deprecation] OldStuffList in com.example.package has been
deprecated
I'm not able to find any setting related to treating warning as errors. I'd like these to be reported as warnings (because indeed, they are warnings), but not prevent the build from completing.

In the scala compiler settings, check that there is no -Xfatal-warnings
This option makes scalac treat warning as error.
Note that I had this problem after a colleague added this option in the build.sbt of an sbt project. Intellij then added it to its scala compiler settings.

If you hit alt-enter on the highlighted error, it should at least give you a dropdown option called "Disable inspection" which should let you turn that off for that instance or all Deprecated errors. This doesn't really solve your problem, but it might at least get you past it.

Related

Scala compiler other than 2.12 not working in Eclipse

I just set up a Scala project in Eclipse (Oxygen 4.7.3a, on Ubuntu 18.04) with the Scala-IDE plugin (4.7.0.v-2_12-201709291352-71a28d0) with a simple HelloWorld object. If I set "Properties -> Scala Compiler" to 2.12 everything works as expected: the project compiles and runs. But if I choose any other version (for instance, "Latest 2.10 bundle (dynamic)" I get prompted to do a full rebuild (as expected) but when I go to "Project -> Build" nothing happens. If I have errors in my code, the editor underlines them, but they won't show in "Problems". If I try to run it I get a class not found error.
I get the feeling that it is not actually compiling. Any ideas on what I need to configure differently?
I finally solved it by removing openjdk-11 and installing openjdk-8. After doing that and reinstalling Eclipse and Scala-IDE everything works fine.
It would have been helpful having some feedback from Eclipse regarding what was not working. I figured it out because I tried to build with SBT and the error lead to this SO question: Failed to initialize compiler: object java.lang.Object in compiler mirror not found
I tried the update-alternatives option (also changing the Java path in eclipse.ini) but then I got the "object java.lang.Object in compiler mirror not found" error in Eclipse problems. Since I didn't need openjdk-11 anyway I simply switched to openjdk-8.

Intellij IDEA 2017 Scala code inspection problems

I am using IDEA 2017.2.5 to develop in Scala with the SBT plugin. I've been unable to get Scala's code inspection to work correctly. I get lots of seemingly arbitrary errors on valid Scala code, such as "Cannot resolve symbol" or "Type mismatch". Also, lots of imports which I'm definitely using are marked as unused and grayed out.
For example, the following code resolves to " world" but produces a "Cannot resolve symbol toLowerCase" error:
val s = "Hello, World".split(",").last.toLowerCase
I have tried File -> Invalidate Caches / Restart, reinstalling the SBT plugin, using different Scala versions, with no luck. Turning off type-aware highlighting makes some of the errors go away, but not all of them.
The following SO posts seem similar:
at scala project, compiler error - Cannot resolve symbol List?
Scala (Breeze) + Intellij: "Cannot resolve symbol *"
How can I resolve this?
If you only recently upgraded your project after using IntelliJ for some time, you might want to force it to regenerate its index by removing your .idea folder and re-importing the project. I've had some luck in the past with this trick.
If you want to make sure not to mess anything up, rename the folder instead of removing it:
> cd /path/to/project
> mv .idea .idea-backup
In case of problems, you can always rename .idea-backup back into .idea.

How to see scala compilation error on the project tree?

I can see java compilation error immediately on the project tree, but for scala code, I could not see that. Anyone know how to achieve that ?

Scala warnings, IntelliJ and compiler flags

I'm currently giving the IntelliJ Scala plugin a spin and one thing is bugging me a wee-bit. I get 3 warnings when compiling.
Warning: scala: Recompiling 4 files
Warning: scala:
Warning: scala: there were 1 deprecation warnings; re-run with -deprecation for details
Why does it give me warnings that files are being recompiled? Can that be turned off? And finally, what's with the empty warning? :D
In IntelliJ 14:
Bring up preferences Intellij IDEA > Preferences or cmd + ,
Look up Scala Compiler. Alternatively, it's under Build, Execution, Deployment > Compiler > Scala Compiler
Check the option for Deprecation warnings
Rebuild your project!
I would like to add few words about warnings and errors reported by IntelliJ IDEa.
JetBrains uses it's own scala analyzer to identify and report errors. Sometimes it reports fake errors or warnings. I think this is because scala is much more complicated language from compilers point of view then much of other languages. Even if all official scala specification was implemented there are some cases which have been omited (read: There always are some bugs). If you find something reported as error/warning by your IntelliJ IDEa which is ok for scalac compiler you can always try to report it as a bug (IntelliJ IDEa supports reporting bugs). Guys from JetBrains will fix it.
More over some scala libraries use macros that are compiler extentions which adds some extra compiler behaviour. If IDE did know their specification it wouldn't identify these non standard codes as errors. It's better to be aware of that. I think the same touches Eclipse scala IDE.
Summarizing all above:
Do not trust all warnings and errors that IntelliJ or other IDE is telling you unless it compiles well using scalac.
JVM parameters isn't compiler parameters -- first are used to actually run your code, later used to just compile it to bytecode. You need to open project settings and adjust options there:

Scala Compiler doesn't compile in ScalaIDE

I'm trying to develop on the Scala compiler project with the help of ScalaIDE. I followed this guide to set up the development environment. When I now try to build the mentioned projects, the reflect project won't get built. Instead, I get the following error via the console output:
uncaught exception during compilation: scala.reflect.internal.MissingRequirementError reflect Unknown Scala Problem
Having tried the provided ANT script of the project via the console, everything seems to work fine.
Does anyone know if I'm missing a hidden compiler flag, dependency or something like this?
Thanks!
With the IDE for Scala 2.10 you can only build the 2.10.x branch of the Scala compiler. If you want to work on master, you need to install a 2.11-based version of the IDE. We don't publicise IDE for 2.11 nightlies yet, but they are available at:
http://download.scala-ide.org/nightly/scala-ide-master-2.11.0-SNAPSHOT/