diff --git a/derive/shared/src/main/scala/derive/Derive.scala b/derive/shared/src/main/scala/derive/Derive.scala index 3f092550e..d6682cc0f 100644 --- a/derive/shared/src/main/scala/derive/Derive.scala +++ b/derive/shared/src/main/scala/derive/Derive.scala @@ -10,10 +10,11 @@ import language.higherKinds * default string which is the full-name of that class/field. */ class key(s: String) extends StaticAnnotation -trait DeriveApi[M[_]]{ +trait DeriveApi{ val c: Context import c.universe._ - def typeclass: c.WeakTypeTag[M[_]] + def typeclassFor[T: c.WeakTypeTag]: Type + def typeclassFor(t: Type): Type = typeclassFor(c.WeakTypeTag(t)) def wrapObject(obj: Tree): Tree def wrapCase0(companion: Tree, targetType: c.Type): Tree def wrapCase1(companion: Tree, arg: String, default: Tree, typeArgs: Seq[c.Type], argTypes: Type, targetType: c.Type): Tree @@ -23,7 +24,7 @@ trait DeriveApi[M[_]]{ def fallbackDerivation(t: Type): Option[Tree] = None } -abstract class Derive[M[_]] extends DeriveApi[M]{ +abstract class Derive extends DeriveApi{ case class TypeKey(t: c.Type) { override def equals(o: Any) = t =:= o.asInstanceOf[TypeKey].t } @@ -33,24 +34,8 @@ abstract class Derive[M[_]] extends DeriveApi[M]{ case None => c.abort(c.enclosingPosition, s) case Some(tree) => tree } - def typeclassFor(t: Type) = { -// println("typeclassFor " + weakTypeOf[M[_]](typeclass)) - - weakTypeOf[M[_]](typeclass) match { - case TypeRef(a, b, _) => - TypeRef(a, b, List(t)) - case ExistentialType(_, TypeRef(a, b, _)) => - TypeRef(a, b, List(t)) - case x => - println("Dunno Wad Dis Typeclazz Is " + x) - println(x) - println(x.getClass) - ??? - } - } def freshName = c.fresh[TermName]("derive") - def derive[T: c.WeakTypeTag] = { val tpe = weakTypeTag[T].tpe // println(Console.YELLOW + "derive " + tpe + Console.RESET) diff --git a/pprint/shared/src/main/scala/pprint/PPrint.scala b/pprint/shared/src/main/scala/pprint/PPrint.scala index c89f2308e..6e457eea4 100644 --- a/pprint/shared/src/main/scala/pprint/PPrint.scala +++ b/pprint/shared/src/main/scala/pprint/PPrint.scala @@ -391,7 +391,8 @@ object Internals { val t = weakTypeTag[T] val d = new Deriver { val c: c0.type = c0 - def typeclass = c.weakTypeTag[pprint.PPrint[_]] + def typeclassFor[T: c0.WeakTypeTag]: c0.universe.Type = + c.weakTypeTag[pprint.PPrint[T]].tpe } // Fallback manually in case everything fails @@ -413,7 +414,7 @@ object Internals { } } - abstract class Deriver extends Derive[pprint.PPrint]{ + abstract class Deriver extends Derive{ import c._ import c.universe._ diff --git a/upickle/shared/src/main/scala/upickle/Macros.scala b/upickle/shared/src/main/scala/upickle/Macros.scala index 946b8838a..a279ebe59 100644 --- a/upickle/shared/src/main/scala/upickle/Macros.scala +++ b/upickle/shared/src/main/scala/upickle/Macros.scala @@ -16,7 +16,7 @@ import language.existentials * types you don't have a Reader/Writer in scope for. */ object Macros { - abstract class Reading[M[_]] extends Derive[M]{ + abstract class Reading extends Derive{ val c: Context import c.universe._ def wrapObject(t: c.Tree) = q"${c.prefix}.SingletonR($t)" @@ -62,7 +62,7 @@ object Macros { def knot(t: Tree) = q"${c.prefix}.Knot.Reader(() => $t)" } - abstract class Writing[M[_]] extends Derive[M]{ + abstract class Writing extends Derive{ val c: Context import c.universe._ def wrapObject(obj: c.Tree) = q"${c.prefix}.SingletonW($obj)" @@ -119,9 +119,10 @@ object Macros { (implicit e1: c0.WeakTypeTag[T], e2: c0.WeakTypeTag[R[_]]): c0.Expr[R[T]] = { import c0.universe._ - val res = new Reading[R]{ + val res = new Reading{ val c: c0.type = c0 - def typeclass = e2 + + def typeclassFor[T: this.c.WeakTypeTag]: this.c.universe.Type = c.weakTypeOf[R[T]] }.derive[T] c0.Expr[R[T]](res) } @@ -130,9 +131,9 @@ object Macros { (implicit e1: c0.WeakTypeTag[T], e2: c0.WeakTypeTag[W[_]]): c0.Expr[W[T]] = { import c0.universe._ - val res = new Writing[W]{ + val res = new Writing{ val c: c0.type = c0 - def typeclass = e2 + def typeclassFor[T: this.c.WeakTypeTag]: this.c.universe.Type = c.weakTypeOf[W[T]] }.derive[T] // println(res) c0.Expr[W[T]](res)