diff options
-rw-r--r-- | src/compiler/scala/reflect/internal/Definitions.scala | 15 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/Global.scala | 17 | ||||
-rw-r--r-- | src/partest/scala/tools/partest/CompilerTest.scala | 35 | ||||
-rw-r--r-- | src/partest/scala/tools/partest/DirectTest.scala | 2 | ||||
-rw-r--r-- | test/files/run/compiler-asSeenFrom.check | 323 | ||||
-rw-r--r-- | test/files/run/compiler-asSeenFrom.scala | 122 | ||||
-rw-r--r-- | test/files/run/existentials-in-compiler.scala | 2 |
7 files changed, 498 insertions, 18 deletions
diff --git a/src/compiler/scala/reflect/internal/Definitions.scala b/src/compiler/scala/reflect/internal/Definitions.scala index 1d53b83b75..bd823c3128 100644 --- a/src/compiler/scala/reflect/internal/Definitions.scala +++ b/src/compiler/scala/reflect/internal/Definitions.scala @@ -904,6 +904,20 @@ trait Definitions extends reflect.api.StandardDefinitions { def termMember(owner: Symbol, name: String): Symbol = owner.info.member(newTermName(name)) def typeMember(owner: Symbol, name: String): Symbol = owner.info.member(newTypeName(name)) + def findMemberFromRoot(fullName: Name): Symbol = { + val segs = nme.segments(fullName.toString, fullName.isTermName) + if (segs.isEmpty) NoSymbol + else findNamedMember(segs.tail, definitions.RootClass.info member segs.head) + } + def findNamedMember(fullName: Name, root: Symbol): Symbol = { + val segs = nme.segments(fullName.toString, fullName.isTermName) + if (segs.isEmpty || segs.head != root.simpleName) NoSymbol + else findNamedMember(segs.tail, root) + } + def findNamedMember(segs: List[Name], root: Symbol): Symbol = + if (segs.isEmpty) root + else findNamedMember(segs.tail, root.info member segs.head) + def getMember(owner: Symbol, name: Name): Symbol = { if (owner == NoSymbol) NoSymbol else owner.info.nonPrivateMember(name) match { @@ -911,6 +925,7 @@ trait Definitions extends reflect.api.StandardDefinitions { case result => result } } + def packageExists(packageName: String): Boolean = getModuleIfDefined(packageName).isPackage diff --git a/src/compiler/scala/tools/nsc/Global.scala b/src/compiler/scala/tools/nsc/Global.scala index bc2cc8191c..9ccd0c28db 100644 --- a/src/compiler/scala/tools/nsc/Global.scala +++ b/src/compiler/scala/tools/nsc/Global.scala @@ -44,6 +44,8 @@ class Global(var currentSettings: Settings, var reporter: Reporter) extends Symb with symtab.Positions { override def settings = currentSettings + + import definitions.{ findNamedMember, findMemberFromRoot } // alternate constructors ------------------------------------------ @@ -1494,21 +1496,6 @@ class Global(var currentSettings: Settings, var reporter: Reporter) extends Symb afterPhase(phase) { currentRun.units foreach (treePrinter.print(_)) } } - private def findMemberFromRoot(fullName: Name): Symbol = { - val segs = nme.segments(fullName.toString, fullName.isTermName) - if (segs.isEmpty) NoSymbol - else findNamedMember(segs.tail, definitions.RootClass.info member segs.head) - } - - private def findNamedMember(fullName: Name, root: Symbol): Symbol = { - val segs = nme.segments(fullName.toString, fullName.isTermName) - if (segs.isEmpty || segs.head != root.simpleName) NoSymbol - else findNamedMember(segs.tail, root) - } - private def findNamedMember(segs: List[Name], root: Symbol): Symbol = - if (segs.isEmpty) root - else findNamedMember(segs.tail, root.info member segs.head) - /** We resolve the class/object ambiguity by passing a type/term name. */ def showDef(fullName: Name, declsOnly: Boolean, ph: Phase) = { diff --git a/src/partest/scala/tools/partest/CompilerTest.scala b/src/partest/scala/tools/partest/CompilerTest.scala index 1cb09b433a..994928c0f6 100644 --- a/src/partest/scala/tools/partest/CompilerTest.scala +++ b/src/partest/scala/tools/partest/CompilerTest.scala @@ -19,9 +19,42 @@ abstract class CompilerTest extends DirectTest { lazy val global: Global = newCompiler() lazy val units = compilationUnits(global)(sources: _ *) + import global._ + import definitions._ override def extraSettings = "-usejavacp -d " + testOutput.path - def sources: List[String] = List(code) 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 m1: Manifest[M]): Type = + if (sym eq NoSymbol) NoType + else appliedType(sym.typeConstructor, List(m1) map (x => manifestToType(x))) + } + 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 = getRequiredModule(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 + } } diff --git a/src/partest/scala/tools/partest/DirectTest.scala b/src/partest/scala/tools/partest/DirectTest.scala index 07444f8d4b..4e7f36bdc9 100644 --- a/src/partest/scala/tools/partest/DirectTest.scala +++ b/src/partest/scala/tools/partest/DirectTest.scala @@ -69,7 +69,7 @@ abstract class DirectTest extends App { /** Constructor/main body **/ try show() - catch { case t => println(t) ; sys.exit(1) } + catch { case t => println(t) ; t.printStackTrace ; sys.exit(1) } /** Debugger interest only below this line **/ protected def isDebug = (sys.props contains "partest.debug") || (sys.env contains "PARTEST_DEBUG") diff --git a/test/files/run/compiler-asSeenFrom.check b/test/files/run/compiler-asSeenFrom.check new file mode 100644 index 0000000000..f198e61072 --- /dev/null +++ b/test/files/run/compiler-asSeenFrom.check @@ -0,0 +1,323 @@ +class C { + type seen from prefix is + ---- ---------------- -- + C[List[T3]]#I[T1] D[A1] C[List[T3]]#I[A1] + C[List[T3]]#I[T1] D[T3] C[List[T3]]#I[T3] + C[List[T3]]#J[T1] D[A1] C[List[T3]]#J[A1] + C[List[T3]]#J[T1] D[T3] C[List[T3]]#J[T3] + C[T1]#I[Int] C[List[T3]] C[List[T3]]#I[Int] + C[T1]#I[Int] D[A1] C[A1]#I[Int] + C[T1]#I[Int] D[T3] C[T3]#I[Int] + C[T1]#I[List[Int]] C[List[T3]] C[List[T3]]#I[List[Int]] + C[T1]#I[List[Int]] D[A1] C[A1]#I[List[Int]] + C[T1]#I[List[Int]] D[T3] C[T3]#I[List[Int]] + C[T1]#I[T1] C[List[T3]] C[List[T3]]#I[List[T3]] + C[T1]#I[T1] D[A1] C[A1]#I[A1] + C[T1]#I[T1] D[T3] C[T3]#I[T3] + C[T1]#I[T2] C[List[T3]] C[List[T3]]#I[T2] + C[T1]#I[T2] D[A1] C[A1]#I[T2] + C[T1]#I[T2] D[T3] C[T3]#I[T2] + C[T1]#I[T3] C[List[T3]] C[List[T3]]#I[T3] + C[T1]#I[T3] D[A1] C[A1]#I[T3] + C[T1]#I[T3] D[T3] C[T3]#I[T3] + C[T1]#I[T4] C[List[T3]] C[List[T3]]#I[T4] + C[T1]#I[T4] D[A1] C[A1]#I[T4] + C[T1]#I[T4] D[T3] C[T3]#I[T4] + C[T1]#J[Int] C[List[T3]] C[List[T3]]#J[Int] + C[T1]#J[Int] D[A1] C[A1]#J[Int] + C[T1]#J[Int] D[T3] C[T3]#J[Int] + C[T1]#J[List[Int]] C[List[T3]] C[List[T3]]#J[List[Int]] + C[T1]#J[List[Int]] D[A1] C[A1]#J[List[Int]] + C[T1]#J[List[Int]] D[T3] C[T3]#J[List[Int]] + C[T1]#J[T1] C[List[T3]] C[List[T3]]#J[List[T3]] + C[T1]#J[T1] D[A1] C[A1]#J[A1] + C[T1]#J[T1] D[T3] C[T3]#J[T3] + C[T1]#J[T2] C[List[T3]] C[List[T3]]#J[T2] + C[T1]#J[T2] D[A1] C[A1]#J[T2] + C[T1]#J[T2] D[T3] C[T3]#J[T2] + C[T1]#J[T3] C[List[T3]] C[List[T3]]#J[T3] + C[T1]#J[T3] D[A1] C[A1]#J[T3] + C[T1]#J[T3] D[T3] C[T3]#J[T3] + C[T1]#J[T4] C[List[T3]] C[List[T3]]#J[T4] + C[T1]#J[T4] D[A1] C[A1]#J[T4] + C[T1]#J[T4] D[T3] C[T3]#J[T4] + D[T3]#J[T1] C[List[T3]] D[T3]#J[List[T3]] + D[T3]#J[T1] D[A1] D[T3]#J[A1] + D[A1]#J[T1] C[List[T3]] D[A1]#J[List[T3]] + D[A1]#J[T1] D[T3] D[A1]#J[T3] +} +class D { + type seen from prefix is + ---- ---------------- -- + C[List[T3]]#I[Int] D[A1] C[List[A1]]#I[Int] + C[List[T3]]#I[List[Int]] D[A1] C[List[A1]]#I[List[Int]] + C[List[T3]]#I[T1] D[A1] C[List[A1]]#I[T1] + C[List[T3]]#I[T2] D[A1] C[List[A1]]#I[T2] + C[List[T3]]#I[T3] D[A1] C[List[A1]]#I[A1] + C[List[T3]]#I[T4] D[A1] C[List[A1]]#I[T4] + C[List[T3]]#J[Int] D[A1] C[List[A1]]#J[Int] + C[List[T3]]#J[List[Int]] D[A1] C[List[A1]]#J[List[Int]] + C[List[T3]]#J[T1] D[A1] C[List[A1]]#J[T1] + C[List[T3]]#J[T2] D[A1] C[List[A1]]#J[T2] + C[List[T3]]#J[T3] D[A1] C[List[A1]]#J[A1] + C[List[T3]]#J[T4] D[A1] C[List[A1]]#J[T4] + C[T1]#I[T3] D[A1] C[T1]#I[A1] + C[T1]#J[T3] D[A1] C[T1]#J[A1] + D[T3]#J[Int] D[A1] D[A1]#J[Int] + D[T3]#J[List[Int]] D[A1] D[A1]#J[List[Int]] + D[T3]#J[T1] D[A1] D[A1]#J[T1] + D[T3]#J[T2] D[A1] D[A1]#J[T2] + D[T3]#J[T3] D[A1] D[A1]#J[A1] + D[T3]#J[T4] D[A1] D[A1]#J[T4] +} +class I { + type seen from prefix is + ---- ---------------- -- + C[List[T3]]#I[T1] D.this.J[T4] C[List[T3]]#I[List[T3]] + C[List[T3]]#I[T1] Z.dZ.J[A2] C[List[T3]]#I[List[A1]] + C[List[T3]]#I[T1] Z.dZ.J[P] C[List[T3]]#I[List[A1]] + C[List[T3]]#I[T2] D.this.J[T4] C[List[T3]]#I[T4] + C[List[T3]]#I[T2] Z.dZ.J[A2] C[List[T3]]#I[A2] + C[List[T3]]#I[T2] Z.dZ.J[P] C[List[T3]]#I[P] + C[List[T3]]#J[T1] D.this.J[T4] C[List[T3]]#J[List[T3]] + C[List[T3]]#J[T1] Z.dZ.J[A2] C[List[T3]]#J[List[A1]] + C[List[T3]]#J[T1] Z.dZ.J[P] C[List[T3]]#J[List[A1]] + C[List[T3]]#J[T2] D.this.J[T4] C[List[T3]]#J[T4] + C[List[T3]]#J[T2] Z.dZ.J[A2] C[List[T3]]#J[A2] + C[List[T3]]#J[T2] Z.dZ.J[P] C[List[T3]]#J[P] + C[T1]#I[Int] D.this.J[T4] C[List[T3]]#I[Int] + C[T1]#I[Int] Z.dZ.J[A2] C[List[A1]]#I[Int] + C[T1]#I[Int] Z.dZ.J[P] C[List[A1]]#I[Int] + C[T1]#I[List[Int]] D.this.J[T4] C[List[T3]]#I[List[Int]] + C[T1]#I[List[Int]] Z.dZ.J[A2] C[List[A1]]#I[List[Int]] + C[T1]#I[List[Int]] Z.dZ.J[P] C[List[A1]]#I[List[Int]] + C[T1]#I[T1] D.this.J[T4] C[List[T3]]#I[List[T3]] + C[T1]#I[T1] Z.dZ.J[A2] C[List[A1]]#I[List[A1]] + C[T1]#I[T1] Z.dZ.J[P] C[List[A1]]#I[List[A1]] + C[T1]#I[T2] D.this.J[T4] C[List[T3]]#I[T4] + C[T1]#I[T2] Z.dZ.J[A2] C[List[A1]]#I[A2] + C[T1]#I[T2] Z.dZ.J[P] C[List[A1]]#I[P] + C[T1]#I[T3] D.this.J[T4] C[List[T3]]#I[T3] + C[T1]#I[T3] Z.dZ.J[A2] C[List[A1]]#I[T3] + C[T1]#I[T3] Z.dZ.J[P] C[List[A1]]#I[T3] + C[T1]#I[T4] D.this.J[T4] C[List[T3]]#I[T4] + C[T1]#I[T4] Z.dZ.J[A2] C[List[A1]]#I[T4] + C[T1]#I[T4] Z.dZ.J[P] C[List[A1]]#I[T4] + C[T1]#J[Int] D.this.J[T4] C[List[T3]]#J[Int] + C[T1]#J[Int] Z.dZ.J[A2] C[List[A1]]#J[Int] + C[T1]#J[Int] Z.dZ.J[P] C[List[A1]]#J[Int] + C[T1]#J[List[Int]] D.this.J[T4] C[List[T3]]#J[List[Int]] + C[T1]#J[List[Int]] Z.dZ.J[A2] C[List[A1]]#J[List[Int]] + C[T1]#J[List[Int]] Z.dZ.J[P] C[List[A1]]#J[List[Int]] + C[T1]#J[T1] D.this.J[T4] C[List[T3]]#J[List[T3]] + C[T1]#J[T1] Z.dZ.J[A2] C[List[A1]]#J[List[A1]] + C[T1]#J[T1] Z.dZ.J[P] C[List[A1]]#J[List[A1]] + C[T1]#J[T2] D.this.J[T4] C[List[T3]]#J[T4] + C[T1]#J[T2] Z.dZ.J[A2] C[List[A1]]#J[A2] + C[T1]#J[T2] Z.dZ.J[P] C[List[A1]]#J[P] + C[T1]#J[T3] D.this.J[T4] C[List[T3]]#J[T3] + C[T1]#J[T3] Z.dZ.J[A2] C[List[A1]]#J[T3] + C[T1]#J[T3] Z.dZ.J[P] C[List[A1]]#J[T3] + C[T1]#J[T4] D.this.J[T4] C[List[T3]]#J[T4] + C[T1]#J[T4] Z.dZ.J[A2] C[List[A1]]#J[T4] + C[T1]#J[T4] Z.dZ.J[P] C[List[A1]]#J[T4] + D[T3]#J[T1] D.this.J[T4] D[T3]#J[List[T3]] + D[T3]#J[T1] Z.dZ.J[A2] D[T3]#J[List[A1]] + D[T3]#J[T1] Z.dZ.J[P] D[T3]#J[List[A1]] + D[T3]#J[T2] D.this.J[T4] D[T3]#J[T4] + D[T3]#J[T2] Z.dZ.J[A2] D[T3]#J[A2] + D[T3]#J[T2] Z.dZ.J[P] D[T3]#J[P] + D[A1]#J[T1] D.this.J[T4] D[A1]#J[List[T3]] + D[A1]#J[T1] Z.dZ.J[A2] D[A1]#J[List[A1]] + D[A1]#J[T1] Z.dZ.J[P] D[A1]#J[List[A1]] + D[A1]#J[T2] D.this.J[T4] D[A1]#J[T4] + D[A1]#J[T2] Z.dZ.J[A2] D[A1]#J[A2] + D[A1]#J[T2] Z.dZ.J[P] D[A1]#J[P] +} +class J { + type seen from prefix is + ---- ---------------- -- + C[List[T3]]#I[Int] Z.dZ.J[A2] C[List[A1]]#I[Int] + C[List[T3]]#I[Int] Z.dZ.J[P] C[List[A1]]#I[Int] + C[List[T3]]#I[List[Int]] Z.dZ.J[A2] C[List[A1]]#I[List[Int]] + C[List[T3]]#I[List[Int]] Z.dZ.J[P] C[List[A1]]#I[List[Int]] + C[List[T3]]#I[T1] Z.dZ.J[A2] C[List[A1]]#I[T1] + C[List[T3]]#I[T1] Z.dZ.J[P] C[List[A1]]#I[T1] + C[List[T3]]#I[T2] Z.dZ.J[A2] C[List[A1]]#I[T2] + C[List[T3]]#I[T2] Z.dZ.J[P] C[List[A1]]#I[T2] + C[List[T3]]#I[T3] Z.dZ.J[A2] C[List[A1]]#I[A1] + C[List[T3]]#I[T3] Z.dZ.J[P] C[List[A1]]#I[A1] + C[List[T3]]#I[T4] Z.dZ.J[A2] C[List[A1]]#I[A2] + C[List[T3]]#I[T4] Z.dZ.J[P] C[List[A1]]#I[P] + C[List[T3]]#J[Int] Z.dZ.J[A2] C[List[A1]]#J[Int] + C[List[T3]]#J[Int] Z.dZ.J[P] C[List[A1]]#J[Int] + C[List[T3]]#J[List[Int]] Z.dZ.J[A2] C[List[A1]]#J[List[Int]] + C[List[T3]]#J[List[Int]] Z.dZ.J[P] C[List[A1]]#J[List[Int]] + C[List[T3]]#J[T1] Z.dZ.J[A2] C[List[A1]]#J[T1] + C[List[T3]]#J[T1] Z.dZ.J[P] C[List[A1]]#J[T1] + C[List[T3]]#J[T2] Z.dZ.J[A2] C[List[A1]]#J[T2] + C[List[T3]]#J[T2] Z.dZ.J[P] C[List[A1]]#J[T2] + C[List[T3]]#J[T3] Z.dZ.J[A2] C[List[A1]]#J[A1] + C[List[T3]]#J[T3] Z.dZ.J[P] C[List[A1]]#J[A1] + C[List[T3]]#J[T4] Z.dZ.J[A2] C[List[A1]]#J[A2] + C[List[T3]]#J[T4] Z.dZ.J[P] C[List[A1]]#J[P] + C[T1]#I[T3] Z.dZ.J[A2] C[T1]#I[A1] + C[T1]#I[T3] Z.dZ.J[P] C[T1]#I[A1] + C[T1]#I[T4] Z.dZ.J[A2] C[T1]#I[A2] + C[T1]#I[T4] Z.dZ.J[P] C[T1]#I[P] + C[T1]#J[T3] Z.dZ.J[A2] C[T1]#J[A1] + C[T1]#J[T3] Z.dZ.J[P] C[T1]#J[A1] + C[T1]#J[T4] Z.dZ.J[A2] C[T1]#J[A2] + C[T1]#J[T4] Z.dZ.J[P] C[T1]#J[P] + D[T3]#J[Int] Z.dZ.J[A2] D[A1]#J[Int] + D[T3]#J[Int] Z.dZ.J[P] D[A1]#J[Int] + D[T3]#J[List[Int]] Z.dZ.J[A2] D[A1]#J[List[Int]] + D[T3]#J[List[Int]] Z.dZ.J[P] D[A1]#J[List[Int]] + D[T3]#J[T1] Z.dZ.J[A2] D[A1]#J[T1] + D[T3]#J[T1] Z.dZ.J[P] D[A1]#J[T1] + D[T3]#J[T2] Z.dZ.J[A2] D[A1]#J[T2] + D[T3]#J[T2] Z.dZ.J[P] D[A1]#J[T2] + D[T3]#J[T3] Z.dZ.J[A2] D[A1]#J[A1] + D[T3]#J[T3] Z.dZ.J[P] D[A1]#J[A1] + D[T3]#J[T4] Z.dZ.J[A2] D[A1]#J[A2] + D[T3]#J[T4] Z.dZ.J[P] D[A1]#J[P] + D[A1]#J[T3] Z.dZ.J[A2] D[A1]#J[A1] + D[A1]#J[T3] Z.dZ.J[P] D[A1]#J[A1] + D[A1]#J[T4] Z.dZ.J[A2] D[A1]#J[A2] + D[A1]#J[T4] Z.dZ.J[P] D[A1]#J[P] +} +class D { // after parser + private val cD: ll.C[List[T3]] + val cD: ll.C[List[T3]] +} + +class D { // after uncurry + private val cD: ll.C[List[T3]] + val cD(): ll.C[List[T3]] +} + +class D { // after erasure + private val cD: ll.C + val cD(): ll.C +} + +object Z { // after parser + def kz[P <: ll.Z.dZ.J[ll.A2]]: ll.Z.dZ.J[P] + private val jZ: ll.Z.dZ.J[ll.A2] + val jZ: ll.Z.dZ.J[ll.A2] + private val dZ: ll.D[ll.A1] + val dZ: ll.D[ll.A1] +} + +object Z { // after uncurry + def kz[P <: ll.Z.dZ.J[ll.A2]](): ll.Z.dZ.J[P] + private val jZ: ll.Z.dZ.J[ll.A2] + val jZ(): ll.Z.dZ.J[ll.A2] + private val dZ: ll.D[ll.A1] + val dZ(): ll.D[ll.A1] +} + +object Z { // after erasure + def kz(): ll.D#J + private val jZ: ll.D#J + val jZ(): ll.D#J + private val dZ: ll.D + val dZ(): ll.D +} + +object Z { // after flatten + def kz(): ll.D#D$J + private val jZ: ll.D#D$J + val jZ(): ll.D#D$J + private val dZ: ll.D + val dZ(): ll.D +} + +value dZ { // after parser + private val cD: ll.C[List[T3]] + val cD: ll.C[List[T3]] +} + +value dZ { // after parser + private val cD: ll.C[List[T3]] + val cD: ll.C[List[T3]] +} + +value dZ { // after uncurry + private val cD: ll.C[List[T3]] + val cD(): ll.C[List[T3]] +} + +value dZ { // after erasure + private val cD: ll.C + val cD(): ll.C +} + +value jZ { // after parser + def thisI(): I.this.type + def thisC(): C.this.type + def t2(): T2 + def t1(): T1 +} + +value jZ { // after parser + def thisI(): I.this.type + def thisC(): C.this.type + def t2(): T2 + def t1(): T1 +} + +value jZ { // after explicitouter + protected val $outer: D.this.type + val ll$D$J$$$outer(): D.this.type + val ll$C$I$$$outer(): C.this.type + def thisI(): I.this.type + def thisC(): C.this.type + def t2(): T2 + def t1(): T1 +} + +value jZ { // after erasure + protected val $outer: ll.D + val ll$D$J$$$outer(): ll.D + protected val $outer: ll.C + val ll$C$I$$$outer(): ll.C + def thisI(): ll.C#I + def thisC(): ll.C + def t2(): Object + def t1(): Object +} + +value jZ { // after flatten + protected val $outer: ll.D + val ll$D$J$$$outer(): ll.D + protected val $outer: ll.C + val ll$C$I$$$outer(): ll.C + def thisI(): ll.C#C$I + def thisC(): ll.C + def t2(): Object + def t1(): Object +} + +method kz { // after parser + def thisI(): I.this.type + def thisC(): C.this.type + def t2(): T2 + def t1(): T1 +} + +value $outer { // after parser + private val cD: ll.C[List[T3]] + val cD: ll.C[List[T3]] +} + +value $outer { // after uncurry + private val cD: ll.C[List[T3]] + val cD(): ll.C[List[T3]] +} + +value $outer { // after erasure + private val cD: ll.C + val cD(): ll.C +} + diff --git a/test/files/run/compiler-asSeenFrom.scala b/test/files/run/compiler-asSeenFrom.scala new file mode 100644 index 0000000000..1fc3a5ee71 --- /dev/null +++ b/test/files/run/compiler-asSeenFrom.scala @@ -0,0 +1,122 @@ +import scala.tools.nsc._ +import scala.tools.partest.CompilerTest +import scala.collection.{ mutable, immutable, generic } + +/** It's too messy but it's better than not having it. + */ +object Test extends CompilerTest { + import global._ + import definitions._ + + override def sources = List(lambdaLift) + def lambdaLift = """ +package ll { + class A1 + class A2 + class X + class C[T1]() { + class I[T2]() { + def t1(): T1 = ??? + def t2(): T2 = ??? + def thisC(): C.this.type = ??? + def thisI(): I.this.type = ??? + } + } + class D[T3]() extends C[T3]() { + val cD: C[List[T3]] = ??? + class J[T4]() extends cD.I[T4]() + } + object Z { + val dZ: D[A1] = ??? + val jZ: dZ.J[A2] = ??? + + def kz[P <: dZ.J[A2]]: dZ.J[P] = ??? + } +} +""" + + object syms extends SymsInPackage("ll") { + def isPossibleEnclosure(encl: Symbol, sym: Symbol) = sym.enclClassChain drop 1 exists (_ isSubClass encl) + def isInterestingPrefix(pre: Type) = pre.typeConstructor.typeParams.nonEmpty && pre.members.exists(_.isType) + + def asSeenPrefixes = tpes map (_.finalResultType) distinct + def typeRefPrefixes = asSeenPrefixes filter isInterestingPrefix + + def nestsIn(outer: Symbol) = classes filter (c => c.enclClassChain drop 1 exists(_ isSubClass outer)) + def typeRefs(targs: List[Type]) = ( + for (p <- typeRefPrefixes ; c <- classes filter (isPossibleEnclosure(p.typeSymbol, _)) ; a <- targs) yield + typeRef(p, c, List(a)) + ) + + val wfmt = "%-" + 25 + "s" + def to_s(x: Any): String = wfmt.format(x.toString.replaceAll("""\bll\.""", "")) + + def fmt(args: Any*): String = { + (args map to_s mkString " ").replaceAll("""\s+$""", "") + } + def fname(sym: Symbol) = { + val p = "" + sym.owner.name + val x = if (sym.owner.isPackageClass || sym.owner.isModuleClass || sym.owner.isTerm) "." else "#" + sym.kindString + " " + p + x + sym.name + } + + def permuteAsSeenFrom(targs: List[Type]) = ( + for { + tp <- typeRefs(targs filterNot (_ eq NoType)) + prefix <- asSeenPrefixes + if tp.prefix != prefix + site <- classes + seen = tp.asSeenFrom(prefix, site) + if tp != seen + if !seen.isInstanceOf[ExistentialType] + } + yield ((site, tp, prefix, seen)) + ) + + def block(label: Any)(lines: List[String]): List[String] = { + val first = "" + label + " {" + val last = "}" + + first +: lines.map(" " + _) :+ last + } + + def permute(targs: List[Type]): List[String] = { + permuteAsSeenFrom(targs).groupBy(_._1).toList.sortBy(_._1.toString) flatMap { + case (site, xs) => + block(fmt(site)) { + fmt("type", "seen from prefix", "is") :: + fmt("----", "----------------", "--") :: { + xs.groupBy(_._2).toList.sortBy(_._1.toString) flatMap { + case (tp, ys) => + (ys map { case (_, _, prefix, seen) => fmt(tp, prefix, seen) }).sorted.distinct + } + } + } + } + } + } + + def pretty(xs: List[_]) = if (xs.isEmpty) "" else xs.mkString("\n ", "\n ", "\n") + + def signaturesIn(info: Type): List[String] = ( + info.members + filterNot (s => s.isType || s.owner == ObjectClass || s.owner == AnyClass || s.isConstructor) + map (_.defString) + ) + + def check(source: String, unit: global.CompilationUnit) = { + import syms._ + + afterTyper { + val typeArgs = List[Type](IntClass.tpe, ListClass[Int]) ++ tparams.map(_.tpe) + permute(typeArgs) foreach println + } + for (x <- classes ++ terms) { + afterEachPhase(signaturesIn(x.tpe)) collect { + case (ph, sigs) if sigs.nonEmpty => + println(sigs.mkString(x + " { // after " + ph + "\n ", "\n ", "\n}\n")) + } + } + true + } +} diff --git a/test/files/run/existentials-in-compiler.scala b/test/files/run/existentials-in-compiler.scala index e4f6920145..8c04e4782c 100644 --- a/test/files/run/existentials-in-compiler.scala +++ b/test/files/run/existentials-in-compiler.scala @@ -6,7 +6,7 @@ object Test extends CompilerTest { import global._ import definitions._ - def code = """ + override def code = """ package extest { trait Bippy[A <: AnyRef, B] { } // wildcards trait BippyLike[A <: AnyRef, B <: List[A], This <: BippyLike[A, B, This] with Bippy[A, B]] // no wildcards |