Project transitively using macros needs an explicit dependency on Scala-reflect?

84 views
Skip to first unread message

Haoyi Li

unread,
Nov 1, 2015, 11:48:01 PM11/1/15
to scala-internals
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 =/

Johannes Rudolph

unread,
Nov 2, 2015, 3:12:04 AM11/2/15
to scala-i...@googlegroups.com
Hi Haoyi,

this looks related to https://github.com/scalamacros/paradise/issues/68

Johannes
> --
> You received this message because you are subscribed to the Google Groups
> "scala-internals" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to scala-interna...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



--
Johannes

-----------------------------------------------
Johannes Rudolph
http://virtual-void.net
Reply all
Reply to author
Forward
0 new messages