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 | |
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')
-rw-r--r-- | test/files/run/compiler-asSeenFrom.scala | 50 | ||||
-rw-r--r-- | test/files/run/t7096.scala | 47 | ||||
-rw-r--r-- | test/files/run/t8190.check | 95 | ||||
-rw-r--r-- | test/files/run/t8190.scala | 210 |
4 files changed, 400 insertions, 2 deletions
diff --git a/test/files/run/compiler-asSeenFrom.scala b/test/files/run/compiler-asSeenFrom.scala index 7020469bb2..61aa013696 100644 --- a/test/files/run/compiler-asSeenFrom.scala +++ b/test/files/run/compiler-asSeenFrom.scala @@ -2,9 +2,55 @@ * filter: inliner warning\(s\); re-run with -Yinline-warnings for details */ import scala.tools.nsc._ -import scala.tools.partest.CompilerTest +import scala.tools.partest.DirectTest import scala.collection.{ mutable, immutable, generic } -import scala.language.postfixOps +import scala.language.{postfixOps, implicitConversions} +import scala.reflect.runtime.{universe => ru} + +// 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 = "-feature -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 + } +} /** It's too messy but it's better than not having it. */ 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._ diff --git a/test/files/run/t8190.check b/test/files/run/t8190.check new file mode 100644 index 0000000000..2362af7320 --- /dev/null +++ b/test/files/run/t8190.check @@ -0,0 +1,95 @@ +Annotation +JavaArgument +LiteralArgument +ArrayArgument +NestedArgument +Constant +Mirror +Name +TermName +TypeName +Position +Scope +MemberScope +Symbol +TermSymbol +TypeSymbol +MethodSymbol +ModuleSymbol +ClassSymbol +FreeTermSymbol +FreeTypeSymbol +Type +SingletonType +ThisType +SingleType +SuperType +ConstantType +TypeRef +CompoundType +RefinedType +ClassInfoType +MethodType +NullaryMethodType +PolyType +ExistentialType +AnnotatedType +TypeBounds +BoundedWildcardType +Tree +TermTree +TypTree +SymTree +NameTree +RefTree +DefTree +MemberDef +PackageDef +ImplDef +ClassDef +ModuleDef +ValOrDefDef +ValDef +DefDef +TypeDef +LabelDef +ImportSelector +Import +Template +Block +CaseDef +Alternative +Star +Bind +UnApply +Function +Assign +AssignOrNamedArg +If +Match +Return +Try +Throw +New +Typed +GenericApply +TypeApply +Apply +Super +This +Select +Ident +ReferenceToBoxed +Literal +Annotated +SingletonTypeTree +SelectFromTypeTree +CompoundTypeTree +AppliedTypeTree +TypeBoundsTree +ExistentialTypeTree +TypeTree +Modifiers +TreeCopier +checking exhaustiveness in scala.reflect.api.Universe... +uncovered type members: List() diff --git a/test/files/run/t8190.scala b/test/files/run/t8190.scala new file mode 100644 index 0000000000..f8abb73f15 --- /dev/null +++ b/test/files/run/t8190.scala @@ -0,0 +1,210 @@ +import scala.reflect.runtime.universe._ + +trait Overloads { + // makes sure noone erases to Any or AnyRef + def test(x: AnyRef) = "AnyRef" + def test(x: Annotation) = "Annotation" + def test(x: JavaArgument) = "JavaArgument" + def test(x: LiteralArgument) = "LiteralArgument" + def test(x: ArrayArgument) = "ArrayArgument" + def test(x: NestedArgument) = "NestedArgument" + def test(x: Constant) = "Constant" + def test(x: Mirror) = "Mirror" + def test(x: Name) = "Name" + def test(x: TermName) = "TermName" + def test(x: TypeName) = "TypeName" + def test(x: Position) = "Position" + def test(x: Scope) = "Scope" + def test(x: MemberScope) = "MemberScope" + def test(x: Symbol) = "Symbol" + def test(x: TermSymbol) = "TermSymbol" + def test(x: TypeSymbol) = "TypeSymbol" + def test(x: MethodSymbol) = "MethodSymbol" + def test(x: ModuleSymbol) = "ModuleSymbol" + def test(x: ClassSymbol) = "ClassSymbol" + def test(x: FreeTermSymbol) = "FreeTermSymbol" + def test(x: FreeTypeSymbol) = "FreeTypeSymbol" + def test(x: Type) = "Type" + def test(x: SingletonType) = "SingletonType" + def test(x: ThisType) = "ThisType" + def test(x: SingleType) = "SingleType" + def test(x: SuperType) = "SuperType" + def test(x: ConstantType) = "ConstantType" + def test(x: TypeRef) = "TypeRef" + def test(x: CompoundType) = "CompoundType" + def test(x: RefinedType) = "RefinedType" + def test(x: ClassInfoType) = "ClassInfoType" + def test(x: MethodType) = "MethodType" + def test(x: NullaryMethodType) = "NullaryMethodType" + def test(x: PolyType) = "PolyType" + def test(x: ExistentialType) = "ExistentialType" + def test(x: AnnotatedType) = "AnnotatedType" + def test(x: TypeBounds) = "TypeBounds" + def test(x: BoundedWildcardType) = "BoundedWildcardType" + def test(x: Tree) = "Tree" + def test(x: TermTree) = "TermTree" + def test(x: TypTree) = "TypTree" + def test(x: SymTree) = "SymTree" + def test(x: NameTree) = "NameTree" + def test(x: RefTree) = "RefTree" + def test(x: DefTree) = "DefTree" + def test(x: MemberDef) = "MemberDef" + def test(x: PackageDef) = "PackageDef" + def test(x: ImplDef) = "ImplDef" + def test(x: ClassDef) = "ClassDef" + def test(x: ModuleDef) = "ModuleDef" + def test(x: ValOrDefDef) = "ValOrDefDef" + def test(x: ValDef) = "ValDef" + def test(x: DefDef) = "DefDef" + def test(x: TypeDef) = "TypeDef" + def test(x: LabelDef) = "LabelDef" + def test(x: ImportSelector) = "ImportSelector" + def test(x: Import) = "Import" + def test(x: Template) = "Template" + def test(x: Block) = "Block" + def test(x: CaseDef) = "CaseDef" + def test(x: Alternative) = "Alternative" + def test(x: Star) = "Star" + def test(x: Bind) = "Bind" + def test(x: UnApply) = "UnApply" + def test(x: Function) = "Function" + def test(x: Assign) = "Assign" + def test(x: AssignOrNamedArg) = "AssignOrNamedArg" + def test(x: If) = "If" + def test(x: Match) = "Match" + def test(x: Return) = "Return" + def test(x: Try) = "Try" + def test(x: Throw) = "Throw" + def test(x: New) = "New" + def test(x: Typed) = "Typed" + def test(x: GenericApply) = "GenericApply" + def test(x: TypeApply) = "TypeApply" + def test(x: Apply) = "Apply" + def test(x: Super) = "Super" + def test(x: This) = "This" + def test(x: Select) = "Select" + def test(x: Ident) = "Ident" + def test(x: ReferenceToBoxed) = "ReferenceToBoxed" + def test(x: Literal) = "Literal" + def test(x: Annotated) = "Annotated" + def test(x: SingletonTypeTree) = "SingletonTypeTree" + def test(x: SelectFromTypeTree) = "SelectFromTypeTree" + def test(x: CompoundTypeTree) = "CompoundTypeTree" + def test(x: AppliedTypeTree) = "AppliedTypeTree" + def test(x: TypeBoundsTree) = "TypeBoundsTree" + def test(x: ExistentialTypeTree) = "ExistentialTypeTree" + def test(x: TypeTree) = "TypeTree" + def test(x: Modifiers) = "Modifiers" + def test(x: TreeCopier) = "TreeCopier" +} + +object Test extends App with Overloads { + val buf = scala.collection.mutable.ListBuffer[String]() + def record(result: String): Unit = { + println(result) + buf += result + } + def check(): Unit = { + println("checking exhaustiveness in scala.reflect.api.Universe...") + var types = typeOf[scala.reflect.api.Universe].members.filter(sym => sym.isType && !sym.isClass).map(_.name.toString) + types = types.filter(_ != "ModifiersCreator") // type ModifiersCreator = ModifiersExtractor + types = types.filter(_ != "FlagSet") // type FlagSet + types = types.filter(_ != "RuntimeClass") // type RuntimeClass = java.lang.Class[_] + val diff = types.toList diff buf.toList + println("uncovered type members: " + diff) + } + record(test(null: Annotation)) + record(test(null: JavaArgument)) + record(test(null: LiteralArgument)) + record(test(null: ArrayArgument)) + record(test(null: NestedArgument)) + record(test(null: Constant)) + record(test(null: Mirror)) + record(test(null: Name)) + record(test(null: TermName)) + record(test(null: TypeName)) + record(test(null: Position)) + record(test(null: Scope)) + record(test(null: MemberScope)) + record(test(null: Symbol)) + record(test(null: TermSymbol)) + record(test(null: TypeSymbol)) + record(test(null: MethodSymbol)) + record(test(null: ModuleSymbol)) + record(test(null: ClassSymbol)) + record(test(null: FreeTermSymbol)) + record(test(null: FreeTypeSymbol)) + record(test(null: Type)) + record(test(null: SingletonType)) + record(test(null: ThisType)) + record(test(null: SingleType)) + record(test(null: SuperType)) + record(test(null: ConstantType)) + record(test(null: TypeRef)) + record(test(null: CompoundType)) + record(test(null: RefinedType)) + record(test(null: ClassInfoType)) + record(test(null: MethodType)) + record(test(null: NullaryMethodType)) + record(test(null: PolyType)) + record(test(null: ExistentialType)) + record(test(null: AnnotatedType)) + record(test(null: TypeBounds)) + record(test(null: BoundedWildcardType)) + record(test(null: Tree)) + record(test(null: TermTree)) + record(test(null: TypTree)) + record(test(null: SymTree)) + record(test(null: NameTree)) + record(test(null: RefTree)) + record(test(null: DefTree)) + record(test(null: MemberDef)) + record(test(null: PackageDef)) + record(test(null: ImplDef)) + record(test(null: ClassDef)) + record(test(null: ModuleDef)) + record(test(null: ValOrDefDef)) + record(test(null: ValDef)) + record(test(null: DefDef)) + record(test(null: TypeDef)) + record(test(null: LabelDef)) + record(test(null: ImportSelector)) + record(test(null: Import)) + record(test(null: Template)) + record(test(null: Block)) + record(test(null: CaseDef)) + record(test(null: Alternative)) + record(test(null: Star)) + record(test(null: Bind)) + record(test(null: UnApply)) + record(test(null: Function)) + record(test(null: Assign)) + record(test(null: AssignOrNamedArg)) + record(test(null: If)) + record(test(null: Match)) + record(test(null: Return)) + record(test(null: Try)) + record(test(null: Throw)) + record(test(null: New)) + record(test(null: Typed)) + record(test(null: GenericApply)) + record(test(null: TypeApply)) + record(test(null: Apply)) + record(test(null: Super)) + record(test(null: This)) + record(test(null: Select)) + record(test(null: Ident)) + record(test(null: ReferenceToBoxed)) + record(test(null: Literal)) + record(test(null: Annotated)) + record(test(null: SingletonTypeTree)) + record(test(null: SelectFromTypeTree)) + record(test(null: CompoundTypeTree)) + record(test(null: AppliedTypeTree)) + record(test(null: TypeBoundsTree)) + record(test(null: ExistentialTypeTree)) + record(test(null: TypeTree)) + record(test(null: Modifiers)) + record(test(null: TreeCopier)) + check() +}
\ No newline at end of file |