Skip to content

Instantly share code, notes, and snippets.

@edmundnoble
Last active June 16, 2017 00:26
Show Gist options
  • Save edmundnoble/290cc83ed3c2c3fbe9316164b1ee1e4a to your computer and use it in GitHub Desktop.
Save edmundnoble/290cc83ed3c2c3fbe9316164b1ee1e4a to your computer and use it in GitHub Desktop.
Scalac crash
package scalaz
package data
import scalaz.meta.Ops
import scala.reflect.macros.whitebox.Context
import scala.language.experimental.macros
final class IdOps[A](self: A) extends Ops {
type O = IdOpsImpls.type
def squared: (A, A) = macro Ops.inline0
}
object IdOpsImpls {
@inline final def squared[A](self: A): (A, A) =
(self, self)
}
package scalaz
package meta
import scala.reflect.macros.whitebox.Context
import scala.language.experimental.macros
import scala.reflect.macros.whitebox
// Originally inspired by http://typelevel.org/blog/2013/10/13/spires-ops-macros.html
trait Ops {
type O
}
object Ops {
def inline0(c: Context): c.Tree = {
import c.universe._
val q"new ${cl: TypeTree}($p)" = c.prefix.tree
val moduleTySym = cl.tpe.member(TypeName("O")).typeSignature
val module = Ident(moduleTySym.termSymbol)
val pre = c.prefix
val appName = c.macroApplication.symbol.name.toString
println(module)
q"$module.${TermName(appName)}($p)"
}
}
object Test {
new scalaz.data.IdOps(1).squared
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment