Questions tagged [scala-compiler]
135 questions
0
votes
2 answers
Missing dependency ‘object scala.native in compiler mirror’
I used scala-compiler.jar to compile an embedded Scala program
This scala program imports a class written using jni
The code is as follows
class test{
def test(ctx: ContractContext): ActionResult = {
val s = new DllTest
s.loadLibrary()
…

tony
- 21
- 3
0
votes
1 answer
In Scala 2, what are possible ways to write a shortcut of a partial function without triggering unchecked warning?
This is a follow-up question of:
In Scala 3: Why runtime pattern matching can't work reliably on duck type using JVM reflection?
I'm trying to create a pattern matching implementation in Scala that is more resilient to type erasure. It should still…

tribbloid
- 4,026
- 14
- 64
- 103
0
votes
0 answers
In Scala 3.2, what's the most efficient method for eta-expanding a function or a class constructor with names and default argument(s)?
During my involvement of an project that heavily relies on type-checked binding with Schematic data. I found many of the existing code share the following pattern:
case class Datum1(
col1: String = "default",
col2: Double = 0
... (over 40…

tribbloid
- 4,026
- 14
- 64
- 103
0
votes
1 answer
[Scala Toolbox]: Compile a Case Class at run-time and then instantiate it
I'm trying to define a case class using Scala Reflection Toolbox and to instantiate it. What is the best way to do it?
At the moment I do
val codeToCompile = q"""case class Authentication(email:String)"""
val tree = toolbox.parse(codeToCompile)
val…

user3476509
- 171
- 10
0
votes
1 answer
pure java project with unit tests written using scalatest having compiler compatibility issue
We have a simple java project with unit tests written in scalatest:
no scala library in compile scope (autoScalaLibrary := false)
scala-compiler added to test scope to compile unit tests written in scala using scalatest
scala-library, scalatest…

mogli
- 1,549
- 4
- 29
- 57
0
votes
1 answer
Is there scala compiler option that makes ` Option[T](t).map(x => null)` return None instead of Some(null)
I've enterprise polyglot codebase which is made of java and scala.
We have lot of places where we do map function on Option[T] and the mapping function is legacy code which returns null.
Option(2).map(x => null) returns Some(null). when another…

user51
- 8,843
- 21
- 79
- 158
0
votes
0 answers
How can I test a Scala 3 compiler plugin in the same project?
I have a project that is a Scala 3 plugin. Right now I publishLocal and run another project that imports my plugin for every test. Not very convenient.
How can I set up my plugin project so I can test my code in the same project (the plugin…

Greg
- 10,696
- 22
- 68
- 98
0
votes
0 answers
Scala fatal warnings but excluding deprecations flag not work
According to https://alexn.org/blog/2020/05/26/scala-fatal-warnings.html
"-Wconf:cat=deprecation:ws,any:e"
Will turn warnings into errors, except for deprecations. But it gives this:
[error] bad option: '-Wconf:cat=deprecation:ws,any:e'
[error]…

samthebest
- 30,803
- 25
- 102
- 142
0
votes
0 answers
What's the possible cause of this error? "java.io.NotSerializableException: scala.Unit$"
I deployed a Spark application and encounter this error:
org.apache.spark.SparkException: Job aborted due to stage failure: Failed to serialize task 602, not attempting to retry it. Exception during serialization: java.io.NotSerializableException:…

tribbloid
- 4,026
- 14
- 64
- 103
0
votes
1 answer
Will the compiler optimise calls to instance methods into static ones where it can?
Lets say I have something like:
case class StringList(list: List[String]) {
final def isEmpty(): Boolean = list.isEmpty
}
Theoretically, the Scala compiler could optimise calls to the method isEmpty() and make them static...so that I don't have…

Cheetah
- 13,785
- 31
- 106
- 190
0
votes
2 answers
Does the Scala compiler try to reduce object creation between several sequential maps and flatmaps
This is a question about the Scala compiler.
Let's say I have a List, and that I transform that list through several maps and flatMaps.
val myList = List(1,2,3,4,5)
val transformed = myList.map(_+1).map(_*2).flatmap(x=>List(x-1,x,x+1))
Let's say I…

Allen Han
- 1,163
- 7
- 16
0
votes
0 answers
Why does this Scala inner class, which does not use the outer class, still get a reference to it?
When I debug, I see that the inner class here gets a reference to its outer class, even though it's not using any values from the outer class. The only reason the inner class is an inner class is so it can reference the types of the outer…

KeyboardDrummer
- 577
- 5
- 21
0
votes
1 answer
What may have caused the following operator overloading to swap operands?
I'm using scala language to define 2 operators: :++ and ++: that serves as the exact mirror of each other: a :++ b == b ++: a, they are obviously not commutative: a :++ b != a ++: b.
This is my scala code for testing:
import…

tribbloid
- 4,026
- 14
- 64
- 103
0
votes
1 answer
Exception while compiling scala code from Java program
I have the following code to compile scala code at runtime in a Java program
Settings s = new Settings();
Global g = new Global(s);
Global.Run run = g.new Run();
List files = new LinkedList<>();
…

user9024779
- 87
- 8
0
votes
1 answer
How to compile and run scala code at runtime from a java program?
I already have a program that uses JavaCompiler api for compiling Java code at runtime. Can I use the same compiler for scala code? If not, what is the best way to compile scala code in a Java program?
Thanks

user9024779
- 87
- 8