How to skip error checking when compiling Scala files in IDEA? - scala

The run config option Make, no error check in IntelliJ IDEA does not skip Scala errors that result in ambiguous ClassDefNotFound errors upon running a project.
How do I skip error checking when compiling Scala files?
My end goal is for the program to fail at runtime when the classes with errors are accessed, not before runtime preventing the whole program from running.

As the name suggests, "Make, no error check" will just pretend compile errors don't matter. Then obviously you end up with an incomplete class path, not containing any classes that produce compiler errors. As a consequence, when you run that project, you should not be surprised to find class-not-found errors.
I don't know how this "feature" interacts with the incremental Scala compiler. I wouldn't expect "Make, no error check" to produce any useful results.
If you want to skip parts of your code that currently don't compile, a good solution is to use the ??? "hole" value, i.e. a placeholder of type Nothing that you can plug into any position where you would have incomplete code. E.g.
def myMethod: String = ??? // implement later
This allows these things to be compiled and will only produce runtime errors when hit during runtime.

Related

How to ignore some classes during scala compilation

I am running sbt in my console where i can enter commands compile run test ...
But as a default these commands always compile every single class they see in your project. The thing is sometimes you want just to ignore certain classes because you know they contain errors and don't want to focus on that now.
How do i specify what class(es) i want to be part of the compilation process when i enter one of these commands so that i don't see the unuseful errors from other classes every time?

Eclipse giving error when compiler does not

I've come up against an odd issue in Eclipse while using the Stanford CoreNLP API. I've written a custom implementation of the Annotator interface, which amongst other things specifies two methods with the type signature Set<Class<? extends CoreAnnotation>>.
I've implemented those methods, but Eclipse is showing an error telling me that the type signature is incorrect. Specifically, it reports, The return type is incompatible with Annotator.requires(). The recommended fix suggests changing the return type to exactly the same type I already have written, but still leaves the error:
As you can see, the supposed `incorrect' type is exactly the same as the type given in the interface.
The project compiles correctly using mvn compile, so this isn't an actual compiler problem. Has anyone seen this before, and can you advise as to how to make those errors go away?
Edit: added screenshot showing the error
Edit2: added details of the error message in Eclipse

Scalac hanging on phase typer of RegexParser

I have a scala program which among other things has a parser-combinator. This is done by extending scala.util.parsing.combinator.RegexParsers. I had developed it using Scala 2.10 and all was working fine.
Yesterday I upgraded my system to Scala 2.11.4, together with IntelliJ 14.02 (not that it matters).
However, whenever I try to compile this program now, scalac hangs during this phase:
scalac: phase typer on MyParser.scala
I changed absolutely nothing to this code, I can't understand why it is hanging or from where I should start. IntelliJ had a warning about postfix operators for parser expressions like constants_def? or structure_def*, where the ? and * follow the token, and I added this line, because of the SIP: Language Modularization Features:
import scala.language.postfixOps
It didn't really have any effect and the problem is still the same.
How can I troubleshoot what is going on? I can't figure out from where to start understanding why the phase typer is just hanging indefinitely.
It looks like a workaround is to add an explicit type:
def da_gd : Parser[Expression with TimedCondition] =
pref_timed_gd | da_gd_conjunction |
(empty_temporal: Parser[Expression with TimedCondition])
A stack dump shows that it's figuring out the type of the expr, and -Ytyper-debug shows the vicinity.
Since nothing good happens after midnight, I'll stop there.

How can I use JDT compiler programmatically?

I use JDT to compile my java classes. BatchCompiler returns a string but I need an array of problems/errors with their column and row information. compiler.compile(units); prints the error to its printwriter, compiler.resolve(unit) does exactly what I want but it can compile only one java file.
I created a compiler object in this way:
Compiler compiler = new Compiler(env, DefaultErrorHandlingPolicies.exitAfterAllProblems(), new CompilerOptions(), requestor, new DefaultProblemFactory());
And create CompilationUnits that contains filenames and file contents to the compiler.
CompilationUnit[] units = project.toCompilationUnit();
AFAIK, there are 2 ways to compile, one of them is compile(units) method that returns void and prints errors and problems to its PrintWriter, because it doesn't return column information it's not useful for me. The other way is resolve(unit) method but it can work with only one CompilationUnit.
compiler.resolve(units[index], true, true, true);
Does anyone know how I can use JDT compiler programmatically to compile multiple files?
org.eclipse.jdt.internal.compiler.Compiler is internal API. According to the JavaDoc of its resolve method: Internal API used to resolve a given compilation unit. Can run a subset of the compilation process.
Instead, the official way of compiling Java files and determining the compilation problems is described here. Basically, you create a Java project and invoke Eclipse's builder on it, then query the project's Java problem markers.

netbeans 7.0 and scala results in stackoverflow

I'm experiencing some rather annoying problems with scala. The problem is, that I can compile small scala project perfectly, but when the projects are bigger, the compiler crashes with an StackOverflowException.
Clearly, I have to increase the stack size for the compiler, however, that's probably my main problem here, I don't know how.
I'm starting netbeans with these parameters:
netbeans_default_options="-J-client -J-Xmx512m -J-Xss8m -J-Xms512m -J-XX:PermSize=128m -J-XX:MaxPermSize=512m -J-Dapple.laf.useScreenMenuBar=true -J-Dapple.awt.graphics.UseQuartz=true -J-Dsun.java2d.noddraw=true"
So, as far as I'm aware, -J-Xss8m should increase the thread stack size to 8 mb. However, that doesn't seem to affect the compiler. So I tried to pass the same parameter to the compiler directly, using the compiler flags, which I can set in netbeans, resulting in this:
-deprecation -J-Xss8m
But again, that doesn't help, I'm still getting the exception. I searched through the netbeans documentation, but all I found was the netbeans startup parameters, which I had already set. I hope somebody here can give me further information on how to handle this problem.
Further information:
So, after a day I finally had the chance to try everything out on a different machine. I used the same settings and same compiler, but to my surprise, I didn't get the same result. Meaning, on his machine the compiler compiles the whole code without any exception.
The only difference between mine computer and his is, that his has more RAM and CPU power, but that shouldn't make the deal since we both use netbeans with the same startup options.
By now, I even tried out the RC of the 2.9 scala compiler, it didn't help much. Also, I checked if I have the correct scala plugin installed, since there might be problems when using the 2.8 plugin with the 2.9 compiler and vice versa. However, I'm using the 2.9 plugin and 2.9 compiler, so that's fine.
The problem of giving the Scala compiler more stack space is similar to specifying more heap space. Both of these options must be specified as custom JVM arguments when running the Scala compiler. However Netbeans lacks any sort of documentation on how to do it, so here it is.
The way to specify custom JVM arguments for the Scala compiler with Netbeans is by customizing build.xml for each project.
Open nbproject/build-impl.xml in the project's folder.
Search for "scalac" and you will find the following target: -init-macrodef-scalac.
Copy the whole target definition, paste it into your build.xml, and save it.
Close nbproject/build-impl.xml, from now on you will work with build.xml.
In the target you just copied, locate the <scalac> tag, the nesting will be as follows: target.macrodef.sequential.scalac
Add a custom "jvmargs" attribute to the scalac tag, it will look as follows: <scalac jvmargs="-Xss2048k -Xmx2000m" ... >
Save the build.xml. Now whenever you compile your project with netbeans, the compiler will be run with the custom jvm arguments.