NonNull, scala.reflect

Previous Topic Next Topic
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

NonNull, scala.reflect

Judson, Ross
I've seen recent checkins on Scala2 for a NonNull -- did a few quick
checks and it seems like a _very_ useful new feature!  


trait Node extends NonNull;
case class Tree(left: Node, right: Node) extends Node;
case class Leaf(val v: String) extends Node;
case object EmptyNode extends Node;

It is legal to write:

val legal = Tree(Tree(EmptyNode, Leaf("Steve")), Leaf("Something"));

But not legal to write:

val illegal = Tree(Tree(null, Leaf("Steve")), Leaf("Arrgh"));

I'm sure this will find its way into many programs.  I am a bit curious
about the status of the scala.reflect package.  I believe that the
overall intent is that attributes (metadata) attached to Scala elements
will be visible through the scala.reflect package.  Right now the
Codification/Reify phase in the compiler is not used, and the attributes
are not generated into the resulting program.  The pickled ScalaSig has
them (I think), but the unpickler is part of the compiler and not
accessible at runtime.  It looks like the unpickler is fairly
specialized in any case so it can participate in the full compiler
framework.  Only a subset of the pickled information is needed to
satisfy scala reflection requirements.

My guess is that the reflect.Symbol class will eventually contain an
attributes field in addition to owner, name and type, and that
programmer-defined attributes will make their way there.  It's
interesting to note that generated attributes could also be added to a
symbol (by a code generator like GenJVM), and these would also be
visible to a running program.