diff options
author | Eugene Burmako <xeno.by@gmail.com> | 2014-01-27 20:39:04 +0300 |
---|---|---|
committer | Eugene Burmako <xeno.by@gmail.com> | 2014-02-14 13:24:47 +0100 |
commit | 3293d60531615f4accdee886fba52ddda0929b31 (patch) | |
tree | 59f4cf0ab64fe7413ede01e05d89ca2570a52e02 /test/files/run/t7096.scala | |
parent | 356839e9f33db50d3c25d68ee1f371a1994b0f90 (diff) | |
download | scala-3293d60531615f4accdee886fba52ddda0929b31.tar.gz scala-3293d60531615f4accdee886fba52ddda0929b31.tar.bz2 scala-3293d60531615f4accdee886fba52ddda0929b31.zip |
SI-8190 erasure identities for types in reflection API
Makes sure that almost every abstract type declared in reflection API
erases to a unique class, so that they can be adequately used for
method overloading to the same extent that tags allow them to be used
in pattern matching.
The only two exceptions from this rule are the types whose implementations
we do not control: FlagSet that is implemented as Long and RuntimeClass
that is implemented as java.lang.Class[_].
Diffstat (limited to 'test/files/run/t7096.scala')
-rw-r--r-- | test/files/run/t7096.scala | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/test/files/run/t7096.scala b/test/files/run/t7096.scala index 2495102899..f36f99db95 100644 --- a/test/files/run/t7096.scala +++ b/test/files/run/t7096.scala @@ -3,6 +3,53 @@ */ import scala.tools.partest._ import scala.tools.nsc._ +import scala.reflect.runtime.{universe => ru} +import scala.language.implicitConversions + +// necessary to avoid bincompat with scala-partest compiled against the old compiler +abstract class CompilerTest extends DirectTest { + def check(source: String, unit: global.CompilationUnit): Unit + + lazy val global: Global = newCompiler() + lazy val units: List[global.CompilationUnit] = compilationUnits(global)(sources: _ *) + import global._ + import definitions.{ compilerTypeFromTag } + + override def extraSettings = "-usejavacp -d " + testOutput.path + + def show() = (sources, units).zipped foreach check + + // Override at least one of these... + def code = "" + def sources: List[String] = List(code) + + // Utility functions + class MkType(sym: Symbol) { + def apply[M](implicit t: ru.TypeTag[M]): Type = + if (sym eq NoSymbol) NoType + else appliedType(sym, compilerTypeFromTag(t)) + } + implicit def mkMkType(sym: Symbol) = new MkType(sym) + + def allMembers(root: Symbol): List[Symbol] = { + def loop(seen: Set[Symbol], roots: List[Symbol]): List[Symbol] = { + val latest = roots flatMap (_.info.members) filterNot (seen contains _) + if (latest.isEmpty) seen.toList.sortWith(_ isLess _) + else loop(seen ++ latest, latest) + } + loop(Set(), List(root)) + } + + class SymsInPackage(pkgName: String) { + def pkg = rootMirror.getPackage(pkgName) + def classes = allMembers(pkg) filter (_.isClass) + def modules = allMembers(pkg) filter (_.isModule) + def symbols = classes ++ terms filterNot (_ eq NoSymbol) + def terms = allMembers(pkg) filter (s => s.isTerm && !s.isConstructor) + def tparams = classes flatMap (_.info.typeParams) + def tpes = symbols map (_.tpe) distinct + } +} object Test extends CompilerTest { import global._ |