I'm facing a compiler crash in pprint
The odd thing is, adding a dependency on scala-reflect in the downstream project seems to make the problem go away.
The crash is:
[error] /Users/haoyi/Dropbox (Personal)/Workspace/demo/Main.scala:13: exception during macro expansion:
[error] scala.ScalaReflectionException: class scala.reflect.macros.Aliases in compiler mirror not found.
[error] at scala.reflect.internal.Mirrors$RootsBase.staticClass(Mirrors.scala:123)
[error] at scala.reflect.internal.Mirrors$RootsBase.staticClass(Mirrors.scala:22)
[error] at pprint.Internals$LowerPriPPrint$$anon$1$$typecreator1$1.apply(PPrint.scala:394)
[error] at scala.reflect.api.TypeTags$WeakTypeTagImpl.tpe$lzycompute(TypeTags.scala:232)
[error] at scala.reflect.api.TypeTags$WeakTypeTagImpl.tpe(TypeTags.scala:232)
[error] at scala.reflect.api.TypeTags$class.weakTypeOf(TypeTags.scala:335)
[error] at scala.reflect.api.Universe.weakTypeOf(Universe.scala:61)
[error] at derive.Derive.typeclassFor(Derive.scala:39)
[error] at derive.Derive.derive$Derive$$implicited$1(Derive.scala:119)
[error] at derive.Derive.deriveType(Derive.scala:121)
[error] at derive.Derive.derive(Derive.scala:58)
[error] at pprint.Internals$LowerPriPPrint$.liftedTree1$1(PPrint.scala:398)
[error] at pprint.Internals$LowerPriPPrint$.FinalRepr(PPrint.scala:398)
[error] pprintln(??? : Stmt)
[error] ^
The line being referred to is:
def FinalRepr[T: c0.WeakTypeTag](c0: derive.ScalaVersionStubs.Context) = c0.Expr[PPrint[T]] {
import c0.universe._
val t = weakTypeTag[T]
val d = new Deriver {
val c: c0.type = c0
def typeclass = c.weakTypeTag[pprint.PPrint[_]] // This is the line referred to in the stack trace
}
...
}
The thing I don't understand, is how is it the end-user of the library needs a provided dependency on scala-reflect? Shouldn't it be pulled in automatically by the compiler when I'm using macros? If I make it a "normal" dependency then it would get pulled into runtime jars, which is not what I want.
Anyone have insight into this kind of problem? I have no idea why it's behaving this way =/