Questions tagged [scala-compiler]

135 questions
2
votes
1 answer

scala compile server stopped due to inactivity | intellijIDEA

This never happened as I never turn off my pc. Seeing this message after recent update. IntelliJ IDEA 2022.3 (Community Edition) Build #IC-223.7571.182, built on November 29, 2022 Runtime version: 17.0.5+1-b653.14 amd64 VM: OpenJDK 64-Bit Server VM…
2
votes
1 answer

How can I run generated code during script runtime?

During the running of a scala script, I would like it to generate some code and execute this. I thought I had found two examples online that might work, but they aren't successful import scala.reflect.runtime.universe._ import…
user13800089
2
votes
0 answers

How to compile code from an external file at runtime in Scala3?

I have the same question as this previously asked question, but I want to achieve this in Scala 3. I have searched for the libraries used in the first answer for Scala 3, but I couldn't find them. How can I do it?
2
votes
2 answers

What's the "-Ydebug-error" option in scala 2? it should print every stack traces of each compilation error

When I'm debugging a complex scala plugin, I sometimes encounter unknown errors, I want the compiler to print out the stacktrace that triggers each error, to make sure that those errors are not caused by my pluin. In scala 3 this option can be…
tribbloid
  • 4,026
  • 14
  • 64
  • 103
2
votes
1 answer

Can I control the order in which macros are compiled in Scala 3?

Suppose I want to use macros in Scala 3 to count the number of places a certain method doSomething() was used in the code: // Macros.scala import scala.quoted.{Expr, Quotes} object Macros { private var count: Int = 0 inline def doSomething()…
Otavio Macedo
  • 1,542
  • 1
  • 13
  • 34
2
votes
1 answer

How to declare in scala a default param in a method of an implicit class

In order to use infix notation, I have the following example of scala code. implicit class myclass(n:Int ){ private def mapCombineReduce(map : Int => Double, combine: (Double,Double) => Double, zero: Double )(a:Int, b:Double): Double = if( a…
f_s
  • 113
  • 10
2
votes
2 answers

Pattern matching - value is not a member on a bound variable

I am working my way through Scala (ver. 2.13.2), and here I've defined a simple linked list with a trait ListSeq. Also, I wanted to override a toString method for pretty-printing. For this, I decided to use pattern-matching. The desired result can…
2
votes
1 answer

In scala 2, can macro or any language feature be used to rewrite the abstract type reification mechanism in all subclasses? How about scala 3?

It is known in scala 2 that macros are strictly local and are only executed once, when the class is defined. This feature seems particularly weak when combining with abstract type, as the process to convert abstract types into concrete one generally…
tribbloid
  • 4,026
  • 14
  • 64
  • 103
2
votes
2 answers

Scala conditional compilation

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,…
sscarduzio
  • 5,938
  • 5
  • 42
  • 54
2
votes
3 answers

How can I view the code that Scala uses to automatically generate the apply function for case classes?

When defining a Scala case class, an apply function is automatically generated which behaves similarly to the way the default constructor in java behaves. How can I see the code which automatically generates the apply function? I presume the code is…
2
votes
0 answers

Scala 2.13.1 error when compiling en "java.lang.NoClassDefFoundError: scala/collection/TraversableOnce"

I'm switching from Scala 2.12 to 2.13.1. When I compile the project in sbt I get this error: [error] java.lang.NoClassDefFoundError: scala/collection/TraversableOnce [error] java.lang.Class.forName0(Native Method) [error]…
M.G.
  • 369
  • 1
  • 14
2
votes
1 answer

How to compile and run Scala code programmatically

I have the following code and I would like to compile it on the fly and run it. object HelloWorld { def main(args: Array[String]): Unit = { println("Hello, world!") } } So far I have tried something like below: import…
Vishal
  • 19,879
  • 23
  • 80
  • 93
2
votes
1 answer

Scala: Multiple flatMap definitions for for-comprehension type-inference issue

I have something like this: case class Box[A](x: A) { def flatMap[B](f: A => GenTraversableOnce[B]): GenTraversableOnce[B] = f(x) def flatMap[B](f: A => Box[B]): Box[B] = f(x) def map[B](f: A => B): Box[B] = Box(f(x)) } object…
pathikrit
  • 32,469
  • 37
  • 142
  • 221
2
votes
2 answers

Strange behavior of Scala compiler when initializing a class with a lazy argument

How possible that the first is correct Scala code but the second won't even compile? The one that does compile object First { class ABC(body: => Unit) { val a = 1 val b = 2 println(body) } def main(args: Array[String]): Unit = { …
tartakynov
  • 2,768
  • 3
  • 26
  • 23
2
votes
2 answers

Dynamic compilation with scala 2.12 - from sbt test

I want to test a tool I write which transforms some scala source code, I want to check that the transformed code compiles from a sbt test (using scalatest). I'd like to call programmatically the scala compiler on a String with my source (all is in a…
Michel Daviot
  • 206
  • 1
  • 10
1 2 3
8 9