Questions tagged [scala-compiler]
135 questions
6
votes
1 answer
Pass closure to Scala compiler plugin
I'm trying to write a Scala compiler plugin that will allow extremely general code generation: something like the generality of the C preprocessor, but a bit more typesafe (I'm not sure if this is a terrible idea, but it's a fun exercise). My ideal…

emchristiansen
- 3,550
- 3
- 26
- 40
5
votes
1 answer
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[_ <: Parent]): String = {
opt match {
case _:…

Nicolas Schejtman
- 433
- 2
- 17
5
votes
3 answers
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 not ignored this warning.
We want to now inspect…

Rahil Shah
- 183
- 1
- 4
5
votes
1 answer
Higher kinded type constructor with upper type bounds doesn't work if bound is abstract type member
I want to define a trait that is parameterized by an upper bound R and a higher kinded type constructor F[_] that accepts only arguments that are subtypes of R. I want that this trait implements a polymorphic apply that can transform any F[A] into…

Andrey Tyukin
- 43,673
- 4
- 57
- 93
5
votes
2 answers
Scala compiler optimization for immutability
Does the scala compiler optimize for memory usage by removing refs to vals used only once within a block?
Imagine an object holding in aggregate some huge data - reaching a size where cloning data or derivatives of it may well scratch the maximum…

matanster
- 15,072
- 19
- 88
- 167
5
votes
1 answer
What is a ScalaSignature?
When decompiling Scala files to Java code, one often comes across classes that are annotated with the ScalaSignatures. These seem to only have one annotation value, a somewhat encoded String. Why does the Scala Compiler create such an odd construct,…

Clashsoft
- 11,553
- 5
- 40
- 79
5
votes
1 answer
Scala parser cuts last bracket
Welcome to Scala 2.12.1 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_121).
Type in expressions for evaluation. Or try :help.
scala> :paste
// Entering paste mode (ctrl-D to finish)
import scala.reflect.runtime._
import…

Andrzej Jozwik
- 14,331
- 3
- 59
- 68
5
votes
1 answer
Obtain the symbol that a "super" call refers to in Scala
I'm writing a Scala compiler plugin for the refchecks phase.
How do I access the symbol that a "super" call refers to, given the symbol of the callsite?
For example, in
trait A {
def m() {}
}
trait B extends A {
def m() { super.m() }
}
knowing…

amaurremi
- 777
- 1
- 5
- 11
4
votes
2 answers
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 implemented using the following type class:
trait…

jbwheatley
- 83
- 7
4
votes
1 answer
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] {
// Removing explode and changing Foo so that
//…

samthebest
- 30,803
- 25
- 102
- 142
4
votes
0 answers
Recursively wrapping method invocations with compiler plugins/macros
OUTLINE
I have an API that looks something like this:
package com.example
object ExternalApi {
def create[T <: SpecialElement](elem: T): TypeConstructor[T] =
TypeConstructor(elem)
def create1[T <: SpecialElement](elem: T):…

mikołak
- 9,605
- 1
- 48
- 70
4
votes
1 answer
Scala implicit conversion of container nested types
Consider the following example:
case class A()
case class B()
object Conversions {
implicit def aToB(a: A): B = B()
implicit def convert[U, T](seq: Seq[U])(implicit converter: U => T): Seq[T] = {
seq.map(converter)
}
}
object Main {
…

andrii.ilin
- 55
- 4
4
votes
3 answers
Java Void to Scala Unit
I have a java library method requiring a class of Void as a parameter. for example, in com.mongodb.async.client.MongoCollection:
void insertOne(TDocument document, SingleResultCallback callback);
I'm accessing this method from scala. Scala…

Luciano
- 2,388
- 1
- 22
- 33
4
votes
1 answer
How to properly use scalac -Xlint
scalax -Xlint help provides the following info:
$ scalac -Xlint:help
Enable or disable specific warnings
adapted-args Warn if an argument list is modified to match the receiver.
nullary-unit Warn when nullary methods…

pedrorijo91
- 7,635
- 9
- 44
- 82
4
votes
2 answers
Scala signature error for Scala module in IntelliJ Idea Maven project
Disclaimer: I am new to Scala and trying to create a sample Scala Maven project using simple scala archtype in IntelliJ IDEA. IntelliJ version is 14.1.2
Below is my pom file, I did change the Scala version to 2.11.6 from 2.7 which the archetype…

user4606322
- 71
- 2
- 6