scalac

Adding a library dependency via an sbt plugin - per sub-project

痴心易碎 提交于 2019-12-05 04:21:01
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 inject(): State => State = { state => val extracted: Extracted = Project.extract(state) val enrichedLibDepSettings = extracted.structure.allProjectRefs map { projRef => val projectScalaVersion = (scalaBinaryVersion in projRef) libraryDependencies in projRef += compilerPluginOrg % (compilerPluginArtifact + "_" + projectScalaVersion.value) % compilerPluginVersion % "provided" } val newState = extracted

Why can't scalac optimize tail recursion in certain scenarios?

六眼飞鱼酱① 提交于 2019-12-04 03:20:47
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 == 1) acc else ifak(n-1, n*acc) } } > scalac foo.scala > jd-gui Foo.class import scala.ScalaObject; public class Foo implements ScalaObject { public int ifak(int n, int acc) { return ((n == 1) ? acc : ifak(n - 1, n * acc)); } } Methods that can be overridden can NOT be tail recursive. Try this: class Foo { private def ifak(n: Int, acc: Int): Int = { if (n == 1) acc else ifak(n-1, n*acc) } } Try this: class

How can I find a description of scala compiler flags/options?

大城市里の小女人 提交于 2019-12-03 06:34:51
问题 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 obtain the list of compiler flags with descriptions from scalac, or anything else? 回答1: The closest I have been able to find is the relevant source files for the compiler. Unfortunately the options are spread among several files. As of this writing, it breaks down like so: StandardScalaSettings (for

How can I find a description of scala compiler flags/options?

一笑奈何 提交于 2019-12-02 20:11:46
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 obtain the list of compiler flags with descriptions from scalac, or anything else? Christopher Currie The closest I have been able to find is the relevant source files for the compiler. Unfortunately the options are spread among several files. As of this writing, it breaks down like so: StandardScalaSettings (for basic flags) ScalaSettings (for advanced flags) These will of course be for the current

What is the order of the scala compiler phases?

时光总嘲笑我的痴心妄想 提交于 2019-11-30 06:21:45
问题 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 should affect my programming. Am I right in saying that the following things are the full list of what the compiler does? parse program types checked do erasure implicit conversion byte-code generated optimize If so, what is the order that it does these phases? How does this order affect the

What is the order of the scala compiler phases?

大兔子大兔子 提交于 2019-11-28 17:34:28
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 should affect my programming. Am I right in saying that the following things are the full list of what the compiler does? parse program types checked do erasure implicit conversion byte-code generated optimize If so, what is the order that it does these phases? How does this order affect the programmer, especially the type-level programmer? pedrofurla You see the phases, their order and explanation by

object scala in compiler mirror not found - running Scala compiler programmatically

守給你的承諾、 提交于 2019-11-28 03:08:23
问题 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 extends App { val compiler = new Global(new Settings()) val testFiles = List("Test.scala") val runner = new compiler.Run() val result = runner.compile(testFiles) println(result) } error error: error while loading Object, Missing dependency 'object scala in compiler mirror', required by /Library/Java

How do I disambiguate in Scala between methods with vararg and without

╄→尐↘猪︶ㄣ 提交于 2019-11-27 04:46:46
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 bundle, String... args) public JCommander(Object object, String... args) I want to to call the first constructor that takes no varargs. I tried: jCommander = new JCommander(cmdLineArgs) I get the error: error: ambiguous reference to overloaded definition, both constructor JCommander in class JCommander of type (x$1: Any,x$2: <repeated...>[java.lang.String])com.beust.jcommander.JCommander and constructor