I have found that scala compiler report compile error differently depends on whether it is used in compile-time or run-time.
E.g. for a simple implicit not found case, in compile time the report is:
newSource1.scala:6: error: type mismatch;
L|R
f(new L)
^
In runtime, when the same code was evaluated and the error message was captured directly:
class TestCase(code: String, extra: String) {
def toolbox(extra: String): ToolBox[universe.type] = {
ToolBox(cm).mkToolBox(options = s"$opts $extra")
}
def compile(): Any = {
import SpecHelpers._
val tb = toolbox(extra)
tb.eval(tb.parse(code))
}
def compileError(): String =
Try(compile()) match {
case Failure(ee) =>
ee match {
case te: ToolBoxError =>
te.message.linesIterator.toList.drop(2).mkString("\n")
case t =>
throw t
}
case Success(_) =>
sys.error("compiling succeeded")
}
}
the line number and location cursor is omitted:;
implicit error;
!I e: F[Arg]
Is there a way to add the missing part back?