Skip to content

Instantly share code, notes, and snippets.

@mandubian
Last active August 29, 2015 13:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mandubian/10476640 to your computer and use it in GitHub Desktop.
Save mandubian/10476640 to your computer and use it in GitHub Desktop.
How to determine a Tree of type `Some[Int]` can be seen as weakTypeTag[Option[_]] in this macro?
// I have a macro
def macmac[M[_], T] = macro macmacImpl
def macmacImpl[M[_], T: c.WeakTypeTag](c: Context)
(body: c.Expr[T])
(implicit mw: c.WeakTypeTag[M[_]]): c.Expr[M[T]]
// somewhere in the macro, it's calling this function
def myFun[M[_], T](block: Tree)(mType: WeakTypeTag[M[_]], tType: WeakTypeTag[T]): Tree = {
...
val arg: Tree = // ... created a tree of type Some[Int] and I'm sure of this part
val stableRef = gen.mkAttributedStableRef(valDef.symbol).setType(arg.tpe).setPos(tree.pos)
...
println(stableRef.tpe weak_<:< mType.tpe) // => false ... WHY THAT????
...
}
// Naturally I call it with something like
macmac[Option, Int](...)
@mandubian
Copy link
Author

As this is just an extract of the code, it's not so easy for you to see exactly... sorry...

Here is what I can tell you:

println("expr:"+expr + " - tpe:"+ showRaw(expr.tpe)+" - mtype:"+showRaw(mType.tpe)+" b:"+(expr.tpe weak_<:< mType.tpe))

and it prints:

expr:xxx$macro$2 - tpe:TypeRef(ThisType(scala), scala.Some, List(TypeRef(ThisType(scala), scala.Int, List()))) - mtype:TypeRef(ThisType(scala), scala.Option, List()) b:false

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment