Last active
June 16, 2017 00:26
-
-
Save edmundnoble/290cc83ed3c2c3fbe9316164b1ee1e4a to your computer and use it in GitHub Desktop.
Scalac crash
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)" | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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