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
50
views
How do I use this object "erasure" in Scala?
I'm trying to restore a project named Scala-IDE.
One of the scala files is JavaSig.scala:
package org.scalaide.core.internal.compiler
import org.scalaide.core.compiler.IScalaPresentationCompiler....
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):...
1
vote
0
answers
111
views
Getting `object scala in compiler mirror not found issue` while running the springboot application using jar but not with classpath
I have a multi-module application which has a java HTTP application (springboot, java 11) in one module and scala code in the second module.
The second module is included as a dependency in the first ...
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
1
answer
86
views
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 ...
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 = &...
2
votes
1
answer
275
views
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....
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....
2
votes
0
answers
97
views
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 ...
1
vote
1
answer
130
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 ...
1
vote
1
answer
210
views
How to use scala.js compiler as a compiler plugin, thus allowing it to integrate into Gradle or maven?
I have a Scala project that can only be compiled with Gradle, recently someone has asked it to be ported to Scala.js, ideally by cross-build.
When I read the code of Scala.js, I realised that the bulk ...
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 ...
0
votes
1
answer
151
views
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 ...
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 ...
1
vote
2
answers
203
views
Can a Scala compiler plugin transform the autogenerated accessor methods of scala case classes?
After the parser phase of the Scalac process, the following case class
case class ExampleCaseClass(var s:String, var i:Int) extends ContextuallyMutable
takes the intermediate form:
Clazz(case class ...
3
votes
1
answer
267
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. ...
2
votes
1
answer
92
views
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 {
...
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
1
answer
57
views
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) => ...
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 ...
2
votes
1
answer
358
views
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 ...
0
votes
1
answer
93
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
110
views
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 ...
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]...
2
votes
1
answer
176
views
In scala, is it possible to discourage the compiler from searching for Predef implicit first?
This post:
Where does Scala look for implicits?
described the implicit search precedence & algorithm used by modern scala compiler. In the above list, directly imported implicit functions should ...
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
1k
views
Write method to a class dynamically at runtime in scala and create a jar
I would like to understand is there a way to write a method to existing class at runtime and to create a jar dynamically in scala.
So far i tried to create a class dynamically and able to run it thru ...
1
vote
1
answer
283
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 ...
1
vote
0
answers
144
views
In scala, why does the compiler doesn't explain the error message "diverging implicit expansion" even if '-Xlog-implicits' is used?
I have a type class that has only 1 implementation:
class ConstDomain[N1, N2](
val a1: Const[N1],
val a2: Const[N2]
) {
...
}
object ConstDomain {
implicit def summon[N1, N2](
...
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. ...
2
votes
2
answers
1k
views
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 ...
3
votes
1
answer
867
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 ...
2
votes
3
answers
854
views
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 ...
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 ...
5
votes
3
answers
921
views
Can I inspect my scala codebase to find all warnings of type: "Comparing Unrelated types"?
I want to inspect my codebase to find both "Fruitless type test" warnings and "Comparing Unrelated types" warning
Basically had a pretty big bug in our codebase which could have been avoided had we ...
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(...
0
votes
1
answer
64
views
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 ...
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 <...
2
votes
1
answer
954
views
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 ...
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)...
4
votes
2
answers
638
views
Is there a type-class that checks for existence of at least one implicit of a type?
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 ...
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 ...
7
votes
1
answer
237
views
How does the Scala compiler perform implicit conversion?
I have a custom class, A, and I have defined some operations within the class as follows:
def +(that: A) = ...
def -(that: A) = ...
def *(that: A) = ...
def +(that: Double) = ...
def -(that: Double) ...
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 ...
1
vote
1
answer
276
views
Looking for existing scala combinator parsers
Is there a repository with parser written using scala combinators?
I am considering using scala combinators and it is dependent on finding existing parsers for popular languages (python, c, java, cpp, ...
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
0
answers
109
views
Scala Lower Bounds Error: value is not a member of type parameter
The scala compiler seems to give false type-errors for statements with multiple lower bounds.
Given class Foo with the method g using a lower bound for A and B
class Foo[A, B](a: A, b: B) {
def g[...
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 ...
0
votes
1
answer
74
views
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 ...