Questions tagged [scalac]
scalac - Compiler for the Scala 2 language
scalac
175
questions
53
votes
5
answers
4k
views
-Ywarn-unused-import triggering on play routes file
I want to be able to use -Xfatal-warnings and -Ywarn-unused-import, the problem is that the compiler is triggering an error on the file which contains the play routes for my application:
[error] /...
37
votes
3
answers
8k
views
How can I find a description of scala compiler flags/options?
How can I find all of the flags for the latest scalac version? After googling for hours I have found only outdated docs. (for example, they don't even mention "-feature" flag).
Is there any way to ...
32
votes
1
answer
2k
views
Log implicits only for "diverging implicit expansion"s
Other answers suggest using "-Xlog-implicits" option for debugging "diverging implicit expansion" errors. However, it also logs a lot of implicits in places unrelated to these errors. Is there some ...
25
votes
3
answers
2k
views
Extracting the complete call graph of a scala project (tough one)
I would like to extract from a given Scala project, the call graph of all methods which are part of the project's own source.
As I understand, the presentation compiler doesn't enable that, and it ...
24
votes
4
answers
4k
views
What is the order of the scala compiler phases?
I want to sharpen my picture of the phases of scala compilation. I know that certain things have to happen in the compiler, but don't really know the order in which they happen and how the order ...
24
votes
5
answers
9k
views
How do I disambiguate in Scala between methods with vararg and without
I'm trying to use the java jcommander library from Scala. The java JCommander class has multiple constructors:
public JCommander(Object object)
public JCommander(Object object, ResourceBundle ...
15
votes
2
answers
4k
views
sbt 0.12.4 - there were x feature warning(s); re-run with -feature for details
I get an error there were 15 feature warning(s); re-run with -feature for details :
$ /usr/local/sbt/bin/sbt
[info] Loading project definition from /home/alex/Documents/projects/my_app123/project
[...
14
votes
2
answers
2k
views
How do I turn off the Scala Fast Compilation server's (FSC) timeout?
I am using a Scala compilation server. This is probably not related to my IDE IntelliJ IDEA, but I will just inform you that I start the Scala compilation server through a special run configuration in ...
13
votes
1
answer
2k
views
How do I alias the scala setter method 'myvar_$eq(myval)' to something more pleasing when in java?
I've been converting some code from java to scala lately trying to teach myself the language.
Suppose we have this scala class:
class Person() {
var name:String = "joebob"
}
Now I want to access ...
13
votes
1
answer
212
views
Scala nondeterministic / caches classes?
I have a very simple goal: to compile a Scala class, and then load it from within another Scala script. The problem is that Scala seems to cache (not sure where) the classes that I create, and doesn'...
13
votes
1
answer
926
views
What is the performance impact of using the type class pattern in Scala
I'm currently making extensive use of the type class pattern in to be performance-relevant portions of my code. I made out at least two potential sources of inefficiency.
The implicit parameters get ...
13
votes
1
answer
2k
views
Add Scala 3.0 SDK to IntelliJ
Currently, the dotty compiler released its first Release Candidate and will be released in the next few months.
I updated the IntelliJ scala plugin to EarlyAccess to make it working with Scala 3.0, ...
12
votes
2
answers
4k
views
Implicit conversion from Int to Double in scala doesn't work
I have written some implicit code as shown below, and I am wondering why the i2d function implicit conversation isn't invoked.
object Test {
implicit def i2d(x: Int): Double = {
println("foo")
...
11
votes
4
answers
14k
views
object scala in compiler mirror not found - running Scala compiler programmatically
Running w/ a simple SBT project w/ Java 7 (details below) and invoking sbt run at the command line (no IntelliJ or anything)
source
import scala.tools.nsc.{ Global, Settings }
object Playground ...
10
votes
1
answer
5k
views
re-run with -feature for details, How to see scala feature warnings when building with gradle?
The gradle scala plugin adds the compileScala task to the project. But sometimes the scala compiler might report something like the following:
$ gradle compileScala
:compileJava UP-TO-DATE
:...
9
votes
2
answers
6k
views
How do I compile Scala Hello World application
I'm new to Scala, and I've never written or compiled a program in it before. I'm trying to simply run the following Hello World example, which I have saved in a file name scalaApp.scala
object ...
9
votes
1
answer
2k
views
How can I create a separate sbt Configuration or Task to compile with WartRemover?
WartRemover is a scalac plugin. Typically it is configured via an sbt plugin.
I'd like to be able to run WartRemover on my sbt project as a separate configuration or task without affecting the usual ...
9
votes
1
answer
4k
views
Scala: The `-` [dash, minus] command is deprecated in favor of `onFailure` and will be removed in 0.14.0
When I'm doing sbt compile -feature on my Scala project I get a mysterious warnings:
The `-` command is deprecated in favor of `onFailure` and will be removed in 0.14.0
I have no clue what that dash/...
8
votes
3
answers
567
views
Why can't scalac optimize tail recursion in certain scenarios?
Why doesn't scalac (the Scala compiler) optimize tail recursion?
Code and compiler invocations that demonstrates this:
> cat foo.scala
class Foo {
def ifak(n: Int, acc: Int):Int = {
if (n == ...
8
votes
2
answers
6k
views
Extract scala source code from jar
So I have a jar file that contains scala as the source code and I have lost the original code. Is there a way to convert the class files in the jar to scala functions and classes instead of the java ...
8
votes
1
answer
951
views
How can I find the source file that causes a Scalac Compiler crash
I am in the process of upgrading a large project to 2.10.4 to 2.11.4. I have gotten a compiler crash, is there anyway to display the name of source file that is causing the crash? I am able to get the ...
7
votes
2
answers
8k
views
maven "rerun with -feature" when compiling scala
I recently noticed Scala compiler warnings that maven was generating that looked like this:
[WARNING] warning: there were 4 deprecation warning(s); re-run with -deprecation for details
[WARNING] ...
7
votes
1
answer
2k
views
How to pass scalacOptions (Xelide-below) to sbt via command line
I am trying to call sbt assembly from the command line passing it a scalac compiler flag to elides (elide-below 1).
I have managed to get the flag working in the build.sbt by adding this line to the ...
7
votes
2
answers
166
views
What are <stable> and <accessor> when doing Scalac -Xprint:typer?
I've written a tiny bit of Scala
object SquareNumbers extends App {
val numbers = List(1,2,3,4,5)
val squares = numbers map (i => i * i)
println (squares)
}
And run it through scalac as so:
...
7
votes
1
answer
229
views
How does the Scala compiler perform implicit conversion?
I have a custom class, A, and I have defined some operations within the class as follows:
def +(that: A) = ...
def -(that: A) = ...
def *(that: A) = ...
def +(that: Double) = ...
def -(that: Double) ...
7
votes
1
answer
714
views
Adding a library dependency via an sbt plugin - per sub-project
I am trying to add a library dependency through an sbt plugin. The dependency should be added to each sub-project per its binary scala version, so I iterate through each subproject.
private def ...
6
votes
1
answer
434
views
Pass closure to Scala compiler plugin
I'm trying to write a Scala compiler plugin that will allow extremely general code generation: something like the generality of the C preprocessor, but a bit more typesafe (I'm not sure if this is a ...
6
votes
3
answers
329
views
Splitting scalac plugin into multiple files
I'd like to split my scalac plugin into multiple files. This sounds easy but I haven't managed to pull it off due to path-dependent type issues stemming from the import global._ line.
Here's Lex ...
6
votes
2
answers
3k
views
scalac missing closing brace error reports with weird line number
As I've been learning Scala I'm often reminded of g++ compiler errors when reading the cryptic output from scalac. However, today I came across something I doubt would happen even in the g++ universe.
...
6
votes
0
answers
99
views
Scala compilation time report
I've got a project that isn't a crazy number of lines of code, but its compilation time is really long on a clean compile. I have the feeling there are some hotspots, but I don't know how to find them....
5
votes
2
answers
794
views
Scala compiler optimization for immutability
Does the scala compiler optimize for memory usage by removing refs to vals used only once within a block?
Imagine an object holding in aggregate some huge data - reaching a size where cloning data ...
5
votes
1
answer
1k
views
scala does not warn about unused computation or value
I have this little scala example:
object Test {
def add(x: Int, y: Int) = {
val z = x - y
x match {
case 0 => 0 - y
case 1 => 1 - y
case _ => x - y
}
x + ...
5
votes
1
answer
3k
views
What is a ScalaSignature?
When decompiling Scala files to Java code, one often comes across classes that are annotated with the ScalaSignatures. These seem to only have one annotation value, a somewhat encoded String. Why does ...
5
votes
1
answer
1k
views
Scala compilation error: not found: type _$1
I am researching about existential types in Scala 2.12.x. For that I'm testing the following code:
trait Parent
class ChildA extends Parent
class ChildB extends Parent
def whatIsInside(opt: Option[_ &...
5
votes
1
answer
1k
views
How do I run a Fast Scala Compiler remote server?
I want to set an fsc process running on a box that I can then access remotely.
I understand I need to share a temp directory.
However, I'm struggling to even get it going on my laptop.
I'm trying:
...
5
votes
0
answers
346
views
What is the 8-bit simulator in scala compiler and how to launch it?
I was reading this question and saw:
scalac includes an 8-bit simulator of a fully armed and operational battle station, viewable using the magic key combination CTRL-ALT-F12 during the GenICode ...
5
votes
0
answers
211
views
How do types flow through pattern matches in Scala?
This gist (a partial Scala port of this Haskell tagless interpreter) compiles with scalac 2.11.1, but fails with the newer 2.11.6:
typechecker.scala:55: error: type mismatch;
found : Expr[B] ...
4
votes
3
answers
2k
views
Scala Range contains(elem: Any) method
Apparently Range has a method that checks if it contains a value of type Any. I understand that it is from SeqLike, but causes some problems.
For instance, i was matching hours from joda.DateTime:
...
4
votes
3
answers
3k
views
Java Void to Scala Unit
I have a java library method requiring a class of Void as a parameter. for example, in com.mongodb.async.client.MongoCollection:
void insertOne(TDocument document, SingleResultCallback<Void> ...
4
votes
1
answer
4k
views
How to properly use scalac -Xlint
scalax -Xlint help provides the following info:
$ scalac -Xlint:help
Enable or disable specific warnings
adapted-args Warn if an argument list is modified to match the receiver.
...
4
votes
2
answers
2k
views
Display exact scala command issued from SBT build
When I build my (relatively complex) SBT project against a local version of Scala, I am getting the following error:
scalac error: bad option: '-Ydelambdafy:method'
This is potentially a bug in ...
4
votes
1
answer
176
views
Unable to resolve path dependent type class evidence w/o having value type accessible
I got stuck for like an hour to discover this fact:
class Foo {
trait TypeClass[X]
object TypeClass {
implicit val gimme = new TypeClass[Int]{}
}
def foo[X : TypeClass](p: X): Unit = ...
4
votes
1
answer
118
views
Why does wrapping a method in another method stop type mismatch in Scala - using underscore in type parameter in pattern match?
In the following block of code (with both scala 2.11 and 2.12) the method apply does not compile, while applyInlined does.
package blar
trait Bar[T]
class A
class B
class C
trait Exploder[T] {
//...
4
votes
1
answer
177
views
Why does scalac need to box an `Int` in a method expecting an `Any`
Consider the following class:
package test
class Test {
def main(args: Array[String]): Unit = {
val i: Int = 0
println(i)
}
}
The bytecode of main is:
public main([Ljava/lang/String;)V
...
4
votes
1
answer
138
views
Why does space in backtick constructor params break the compiler?
A certain combination of whitespace and ordering together with backticks in parameter names where the backticked name has the same leading chars as another param seems to mislead the compiler into ...
4
votes
2
answers
221
views
Fields interfering with method resolution for Scala Dynamic trait?
As my first foray into Dynamic Scala land, I thought that I'd try accessing bean properties via applyDynamic.
My first very rough cut is
trait BeanProperties extends Dynamic {
def applyDynamic(...
4
votes
1
answer
62
views
Scalac bug or misunderstanding on my part?
I set the -Xfatal-warnings compiler flag in my SBT build and sure enough this code doesn't compile:
package example
sealed trait Errors
object Errors {
case class BadFirstName(name: String) ...
4
votes
0
answers
374
views
How can I tell scalac to suppress warnings is macro-generated code?
I'm currently using a macro (ZIO's @mockable) whose generated code is causing a compilation error that is causing my build to fail:
[error] /home/me/xxx/backend/<macro>:5:204: parameter value ...
4
votes
0
answers
198
views
Breakpoints in Eclipse for Lagom or Akka code
We are using Eclipse to remote debug Lagom and Akka applications, but Eclipse is not allowing us to put breakpoints in the code.
I am able to put breakpoints in my Scala code, but not in the Akka ...
3
votes
4
answers
427
views
Scala recursive val behaviour
What do you think prints out?
val foo: String = "foo" + foo
println(foo)
val foo2: Int = 3 + foo2
println(foo2)
Answer:
foonull
3
Why? Is there a part in specification that describes/explains ...