139 questions
0
votes
0
answers
28
views
staging.Compiler for experimental code in Scala 3
Consider the following code. When I run it, I see Flag -experimental set repeatedly message (the functionality seems correct otherwise). What should I do so it won't be displayed? (without (using ...
0
votes
1
answer
44
views
Inject call to base class method in trait with Scala compiler plugin
I'm trying to write a compiler plugin that would inject a call to a base class method in a trait in Scala. For the following input source:
class Component {
def valCallback[T](ref: T, name: String):...
0
votes
2
answers
2k
views
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 =...
0
votes
0
answers
91
views
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 = &...
1
vote
1
answer
811
views
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....
1
vote
1
answer
132
views
How to fix the problem "Fatal error: java.lang.Object is missing called from core module analyzer" in ScalaJS Linking
I'm trying to defer ScalaJS Linking to runtime, which allows multi-stage compilation to be more flexible and less dependent on sbt.
The setup looks like this:
Instead of using scalajs-sbt plugin, I ...
0
votes
1
answer
136
views
[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 ...
2
votes
2
answers
87
views
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 ...
3
votes
1
answer
269
views
Scala 2 Append A Method To Class Body (Metaprogramming)
I have been stuck on this issue for a week and don't seem to be getting anywhere. I am trying to copy some methods and fields from one class to another.
I have two phases that are involved in this. ...
5
votes
1
answer
1k
views
Scala compilation error: not found: type _$1
I am researching about existential types in Scala 2.12.x. For that I'm testing the following code:
trait Parent
class ChildA extends Parent
class ChildB extends Parent
def whatIsInside(opt: Option[_ &...
2
votes
2
answers
313
views
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 ...
0
votes
1
answer
94
views
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(...
0
votes
0
answers
700
views
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]...
1
vote
1
answer
104
views
Scala Compiler Plugin - Determine whether method is overridden
I am writing a Scala Compiler Plugin with a component the executes after the "jvm" phase where there is need to know that a method is overridden. Here is a distilled version of a test case I ...
1
vote
1
answer
285
views
Scala compiler-plugin, finding an annotation
I would like this plugin to fetch the contents of an annotation (@Typestate(filename)).
But at the moment even if I print out the entire tree I can't find the annotation anywhere.
How to get an ...
3
votes
1
answer
145
views
Scala Implicit Method Compilation when Method Tries to Access Non-Existing Case Class Members
I did run into an scala compiler issue with implicit methods. The scenario is quite easy. The task of the implicit method is to turn an object of the case class A into an object of the case class B. ...
3
votes
1
answer
868
views
How to configure IntelliJ Scala Plugin to use Scala's native presentation compiler?
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 ...
0
votes
0
answers
381
views
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 ...
2
votes
0
answers
2k
views
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(...
1
vote
1
answer
283
views
How to compile output of a compiler phase?
Using -Xprint flag in scalac we get output of different compiler phases, for example given the following Foo.scala
object Foo {
val x = 42
}
then scalac -Xprint:jvm Foo.scala outputs
package <...
0
votes
2
answers
214
views
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)...
0
votes
0
answers
116
views
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 ...
11
votes
2
answers
1k
views
create an ambiguous low priority implicit
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 ...
4
votes
1
answer
122
views
Why does wrapping a method in another method stop type mismatch in Scala - using underscore in type parameter in pattern match?
In the following block of code (with both scala 2.11 and 2.12) the method apply does not compile, while applyInlined does.
package blar
trait Bar[T]
class A
class B
class C
trait Exploder[T] {
//...
1
vote
1
answer
75
views
Compile Scala Object using NSC
Could someone give a simple example of how I'd use scala.tools.nsc to compile a Scala class during runtime from within a JVM? I'm experimenting with some dynamic behavior where I want to be able to ...