summaryrefslogblamecommitdiff
path: root/test/files/neg/t7166/Impls_Macros_1.scala
blob: 62a15657c366606f2dda581fe299964e004a71f6 (plain) (tree)

























                                                                                                                       
import scala.reflect.macros.Context
import language.experimental.macros

trait Complex[T]

class Foo

object Complex {
  def impl[T: c.WeakTypeTag](c: Context): c.Expr[Complex[T]] = {
    import c.universe._
    def shout(msg: String) = {
      val cannotShutMeUp = c.asInstanceOf[scala.reflect.macros.runtime.Context].universe.currentRun.currentUnit.error _
      cannotShutMeUp(c.enclosingPosition.asInstanceOf[scala.reflect.internal.util.Position], msg)
    }
    try {
      val complexOfT = appliedType(typeOf[Complex[_]], List(weakTypeOf[T]))
      val infiniteRecursion = c.inferImplicitValue(complexOfT, silent = true)
      shout("silent = true does work!")
    } catch {
      case ex: Exception => shout(ex.toString)
    }
    c.literalNull
  }

  implicit def genComplex[T]: Complex[T] = macro impl[T]
}