This is a simplified version of my code that is failing to compile:
object CompileFail {
import org.apache.spark.sql.{ Encoder, SparkSession }
case class Foo(x: Int)
def run(spark: SparkSession): Int => Int = {
import spark.implicits._
add(bar(encode[Foo]))
}
def bar(f: => Int): Int = 0
def encode[A : Encoder]: Int = 0
def add(a: Int)(b: Int) = a + b
}
It is failing with following non sensical message:
[error] Error while emitting CompileFail.scala
[error] value $u
[error] one error found
[error] Compilation failed
I am on Scala 2.12.15 and Spark 3.1.2 (but it fails on older Spark versions too).
Interesting to note:
- If I change
add(a)(b)toadd(a, b)it compiles - If I change
bar(f: => Int)tobar(f: Int)it compiles - If I change
add(bar(encode[Foo]))toadd(bar(encode[String]))it compiles
What am I doing wrong?