moduleClassOf[O.type]

101 views
Skip to first unread message

Jason Zaugg

unread,
Jan 24, 2013, 3:30:02 PM1/24/13
to scala-i...@googlegroups.com
scala> object O
defined module O

scala> def impl[T: c.WeakTypeTag](c: Context): c.Expr[Class[_]] = {import c.universe._; c.Expr[Class[_]](Literal(Constant(weakTypeOf[T])))}
impl: [T](c: scala.reflect.macros.Context)(implicit evidence$1: c.WeakTypeTag[T])c.Expr[Class[_]]

scala> def moduleClassOf[T <: Singleton]: Class[_] = macro impl[T]
moduleClassOf: [T <: Singleton]=> Class[_]

scala> moduleClassOf[O.type]
res5: Class[O.type] = class O$

I guess that it's something of an accident that this works, but I need to use this trick to fix SI-6259 in a manner more pleasing the the byte code verification police.

This also provides a tenable solution for SI-2453, where I just noticed my ponderings for last year:

> I wonder, could classOf be rewritten these days as a macro? 
> How about instanceClassOf / staticClassOf?
 
Hey, past me: it seems like `instanceClassOf` can!

-jason

Paul Phillips

unread,
Jan 24, 2013, 4:51:03 PM1/24/13
to scala-i...@googlegroups.com

On Thu, Jan 24, 2013 at 12:30 PM, Jason Zaugg <jza...@gmail.com> wrote:
Hey, past me: it seems like `instanceClassOf` can!

Hey, present me: following up on those comments of yours is what has hung up the return of my "classOf as a macro" pr. But where it also led me is back to this:


If you listen carefully, you can still hear "past me":

  "It would be VERY USEFUL if there was! was... was... was..."

Reply all
Reply to author
Forward
0 new messages