scala-compiler

Scala conditional compilation

自古美人都是妖i 提交于 2021-01-20 12:23:06
问题 I'm writing a Scala program and I want it to work with two version of a big library. This big library's version 2 changes the API very slightly (only one class constructor signature has an extra parameter). // Lib v1 class APIClass(a: String, b:Integer){ ... } // Lib v2 class APIClass(a: String, b: Integer, c: String){ ... } // And my code extends APIClass.. And I have no #IFDEF class MyClass() extends APIClass("x", 1){ // <-- would be APIClass("x", 1, "y") in library v2 ... } I really don't

Is there a type-class that checks for existence of at least one implicit of a type?

有些话、适合烂在心里 提交于 2020-12-05 11:48:25
问题 I have a trait Foo[T, U] and a type-level algorithm that given an L <: HList and a target type U , tells me whether there exists T in L such that there is an implicit Foo[T, U] in scope. This is implemented using the following type class: trait Search[L <: HList, U] object Search { def apply[L <: HList, U](implicit s: Search[L, U]): U = null ... } and we have the following: object Test { type L = Int :: String :: HNil implicit val foo: Foo[String, Boolean] = null Search[L, Boolean] //compiles

How to configure IntelliJ Scala Plugin to use Scala's native presentation compiler?

人走茶凉 提交于 2020-06-17 12:56:40
问题 Although IntelliJ Scala Plugin uses Scala compiler proper to generate the actual bytecode, it seems to use its own implementation of presentation compiler to provide real-time type-aware error highlighting in the editor: syntax highlighting feature that is implemented by Idea's Scala plugin and it requires immediate re-processing of all the files you change in a way similar but now exactly the same as what the real compiler does. This might be the reason why sometimes projects build

How does Scala's type erasure work for higher kinded type parameters?

喜夏-厌秋 提交于 2019-12-24 00:26:41
问题 I don't understand which generic type parameters Scala erases. I used to think that it should erase all generic type parameters, but this does not seem to be the case. Correct me if I'm wrong: if I instantiate an instance of type Map[Int, String] in the code, then at the runtime, the instance knows only that it is of type Map[_, _] , and does not know anything about its generic type parameters. This is why the following succeeds to compile and to execute without errors: val x: Map[Int, String

How to invoke the Scala compiler programmatically?

依然范特西╮ 提交于 2019-12-17 15:57:29
问题 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. 回答1: 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

Scalac hanging in phase typer

旧巷老猫 提交于 2019-12-13 07:17:38
问题 I am having a problem with 2.10.3 and code generated by Slick (Codegen). It seems very similar to Scalac hanging on phase typer of RegexParser Other files generated by Codegen work, but this one just hangs forever in "scalac: phase typer Foo.scala" The only difference I can see is the number of columns in the table resulting in lots of vals and large cons'ed lists like this def * = WordRootID :: WordID :: WordHeadID :: SynonymID :: PronunciationID :: Rank :: BNCFrequency :: CompassDifficulty

What is a ScalaSignature?

﹥>﹥吖頭↗ 提交于 2019-12-11 01:38:22
问题 When decompiling Scala files to Java code, one often comes across classes that are annotated with the ScalaSignature s. These seem to only have one annotation value, a somewhat encoded String. Why does the Scala Compiler create such an odd construct, instead of using custom Attribute s in the class file? 回答1: From Storage of pickled Scala signatures in class files: The legacy method for storing signatures as attributes is simultaneously more elegant, more compact (about 15%) and simpler than

Scalac hanging on phase typer of RegexParser

假如想象 提交于 2019-12-10 11:25:30
问题 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

Scalac hanging on phase typer of RegexParser

ε祈祈猫儿з 提交于 2019-12-06 08:51:40
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

Resolving the dependency of Scala Macros and Compiler Framework in SBT

陌路散爱 提交于 2019-12-06 06:43:58
问题 I am trying to write a framework to make writing Scala compiler plugins easier, what I am doing is writing a framework on top of the Scala quasiquotes. So my project depends on macros from macro-paradise and both scala-compiler and scala-reflect libraries. I wrote an SBT build script by following the instructions mentioned here: https://github.com/scalamacros/sbt-example-paradise/blob/master/project/Build.scala And used scalaVersion 2.11.0-SNAPSHOT, 2.10.3-SNAPSHOT, 2.10.3-RC1, 2.10.2 to