scala-compiler

create an ambiguous low priority implicit

坚强是说给别人听的谎言 提交于 2019-12-05 16:47:07
问题 Consider the default codec as offered in the io package. implicitly[io.Codec].name //res0: String = UTF-8 It's a "low priority" implicit so it's easy to override without ambiguity. implicit val betterCodec: io.Codec = io.Codec("US-ASCII") implicitly[io.Codec].name //res1: String = US-ASCII It's also easy to raise its priority level. import io.Codec.fallbackSystemCodec implicit val betterCodec: io.Codec = io.Codec("US-ASCII") implicitly[io.Codec].name //won't compile: ambiguous implicit values

create an ambiguous low priority implicit

泪湿孤枕 提交于 2019-12-04 02:23:11
Consider the default codec as offered in the io package. implicitly[io.Codec].name //res0: String = UTF-8 It's a "low priority" implicit so it's easy to override without ambiguity. implicit val betterCodec: io.Codec = io.Codec("US-ASCII") implicitly[io.Codec].name //res1: String = US-ASCII It's also easy to raise its priority level. import io.Codec.fallbackSystemCodec implicit val betterCodec: io.Codec = io.Codec("US-ASCII") implicitly[io.Codec].name //won't compile: ambiguous implicit values But can we go in the opposite direction? Can we create a low level implicit that disables ("ambiguates

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

“scala.runtime in compiler mirror not found” but working when started with -Xbootclasspath/p:scala-library.jar

江枫思渺然 提交于 2019-11-29 03:45:26
I'm trying to run a Scala application packed as JAR (including dependencies) but this fails until the Scala library is added by using the -Xbootclasspath/p option. Failing invocation: java -jar /path/to/target/scala-2.10/application-assembly-1.0.jar After the application did some of its intended output, the console shows: Exception in thread "main" scala.reflect.internal.MissingRequirementError: object scala.runtime in compiler mirror not found. at scala.reflect.internal.MissingRequirementError$.signal(MissingRequirementError.scala:16) at scala.reflect.internal.MissingRequirementError$

Scala - How to compile code from an external file at runtime?

天涯浪子 提交于 2019-11-28 19:19:59
问题 I want to design a Scala program that accepts Scala files as parameters which can customize the execution of the program. In particular, I want to supply at runtime files that contain implementations of methods that will be invoked by the program. How can I properly depend on external files and invoke their methods dynamically at runtime? Ideally, I would also like those files to be able to depend on methods and classes in my program. Example Scenario: I have a function that contains the line

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 to invoke the Scala compiler programmatically?

拈花ヽ惹草 提交于 2019-11-27 20:42:12
I want my Scala code to take a Scala class as input, compile and execute that class. How can I programmatically invoke a Scala compiler? I will be using the latest Scala version, i.e. 2.10. ToolBox I think the proper way of invoking the Scala compiler is doing it via Reflection API documented in Overview . Specifically, Tree Creation via parse on ToolBoxes section in 'Symbols, Trees, and Types' talks about parsing String into Tree using ToolBox . You can then invoke eval() etc. scala.tools.nsc.Global But as Shyamendra Solanki wrote, in reality you can drive scalac's Global to get more done. I

“scala.runtime in compiler mirror not found” but working when started with -Xbootclasspath/p:scala-library.jar

佐手、 提交于 2019-11-27 17:49:38
问题 I'm trying to run a Scala application packed as JAR (including dependencies) but this fails until the Scala library is added by using the -Xbootclasspath/p option. Failing invocation: java -jar /path/to/target/scala-2.10/application-assembly-1.0.jar After the application did some of its intended output, the console shows: Exception in thread "main" scala.reflect.internal.MissingRequirementError: object scala.runtime in compiler mirror not found. at scala.reflect.internal