diff options
author | Eugene Burmako <xeno.by@gmail.com> | 2014-01-27 22:47:36 +0300 |
---|---|---|
committer | Eugene Burmako <xeno.by@gmail.com> | 2014-02-14 13:24:48 +0100 |
commit | ad7983b70a43ba9033a491c00ad22691e7a0a7b4 (patch) | |
tree | fded601a5fa3c4d7cea23d742e30e15f1ace7404 /src/compiler | |
parent | 3293d60531615f4accdee886fba52ddda0929b31 (diff) | |
download | scala-ad7983b70a43ba9033a491c00ad22691e7a0a7b4.tar.gz scala-ad7983b70a43ba9033a491c00ad22691e7a0a7b4.tar.bz2 scala-ad7983b70a43ba9033a491c00ad22691e7a0a7b4.zip |
additional class tags for reflection API
Introduces a test that iterates all abstract types in reflection API
and makes sure that every one of them has an associated class tag.
After being introduced, the test has immediately failed exposing
the lack of tags for TreeCopier, Mirror and RuntimeClass, which has been
subsequently fixed in this commit.
Diffstat (limited to 'src/compiler')
-rw-r--r-- | src/compiler/scala/tools/nsc/Global.scala | 5 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/ast/Trees.scala | 2 | ||||
-rw-r--r-- | src/compiler/scala/tools/reflect/ReflectGlobal.scala | 8 |
3 files changed, 15 insertions, 0 deletions
diff --git a/src/compiler/scala/tools/nsc/Global.scala b/src/compiler/scala/tools/nsc/Global.scala index 1617db7517..1098766a07 100644 --- a/src/compiler/scala/tools/nsc/Global.scala +++ b/src/compiler/scala/tools/nsc/Global.scala @@ -15,6 +15,7 @@ import scala.collection.{ mutable, immutable } import io.{ SourceReader, AbstractFile, Path } import reporters.{ Reporter, ConsoleReporter } import util.{ ClassPath, MergedClassPath, StatisticsInfo, returning, stackTraceString } +import scala.reflect.ClassTag import scala.reflect.internal.util.{ OffsetPosition, SourceFile, NoSourceFile, BatchSourceFile, ScriptSourceFile } import scala.reflect.internal.pickling.{ PickleBuffer, PickleFormat } import scala.reflect.io.VirtualFile @@ -49,11 +50,15 @@ class Global(var currentSettings: Settings, var reporter: Reporter) override def isCompilerUniverse = true override val useOffsetPositions = !currentSettings.Yrangepos + type RuntimeClass = java.lang.Class[_] + implicit val RuntimeClassTag: ClassTag[RuntimeClass] = ClassTag[RuntimeClass](classOf[RuntimeClass]) + class GlobalMirror extends Roots(NoSymbol) { val universe: self.type = self def rootLoader: LazyType = new loaders.PackageLoader(classPath) override def toString = "compiler mirror" } + implicit val MirrorTag: ClassTag[Mirror] = ClassTag[Mirror](classOf[GlobalMirror]) lazy val rootMirror: Mirror = { val rm = new GlobalMirror diff --git a/src/compiler/scala/tools/nsc/ast/Trees.scala b/src/compiler/scala/tools/nsc/ast/Trees.scala index 7a7d4ac0b2..d33ea5bb5c 100644 --- a/src/compiler/scala/tools/nsc/ast/Trees.scala +++ b/src/compiler/scala/tools/nsc/ast/Trees.scala @@ -6,6 +6,7 @@ package scala.tools.nsc package ast +import scala.reflect.ClassTag import scala.reflect.internal.Flags.BYNAMEPARAM import scala.reflect.internal.Flags.DEFAULTPARAM import scala.reflect.internal.Flags.IMPLICIT @@ -102,6 +103,7 @@ trait Trees extends scala.reflect.internal.Trees { self: Global => def InjectDerivedValue(tree: Tree, arg: Tree): InjectDerivedValue def TypeTreeWithDeferredRefCheck(tree: Tree): TypeTreeWithDeferredRefCheck } + implicit val TreeCopierTag: ClassTag[TreeCopier] = ClassTag[TreeCopier](classOf[TreeCopier]) def newStrictTreeCopier: TreeCopier = new StrictTreeCopier def newLazyTreeCopier: TreeCopier = new LazyTreeCopier diff --git a/src/compiler/scala/tools/reflect/ReflectGlobal.scala b/src/compiler/scala/tools/reflect/ReflectGlobal.scala index 6f369212ad..ac63232967 100644 --- a/src/compiler/scala/tools/reflect/ReflectGlobal.scala +++ b/src/compiler/scala/tools/reflect/ReflectGlobal.scala @@ -37,5 +37,13 @@ class ReflectGlobal(currentSettings: Settings, reporter: Reporter, override val // (each mirror has its own set package symbols, because of the peculiarities of symbol loading in scala), // that `Predef` symbol only has a single owner, and this messes up visibility, which is calculated based on owners, not scopes. override def runtimeMirror(cl: ClassLoader): Mirror = rootMirror + + // Mirror and RuntimeClass come from both Global and reflect.runtime.SymbolTable + // so here the compiler needs an extra push to help decide between those (in favor of the latter) + import scala.reflect.ClassTag + override type Mirror = JavaMirror + override implicit val MirrorTag: ClassTag[Mirror] = ClassTag[Mirror](classOf[Mirror]) + override type RuntimeClass = java.lang.Class[_] + override implicit val RuntimeClassTag: ClassTag[RuntimeClass] = ClassTag[RuntimeClass](classOf[RuntimeClass]) } |