aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/dotty/tools/dotc/core/Printers.scala4
-rw-r--r--src/dotty/tools/dotc/core/SymDenotations.scala2
-rw-r--r--src/dotty/tools/dotc/core/Types.scala21
-rw-r--r--src/dotty/tools/dotc/core/pickling/ClassfileParser.scala2
-rw-r--r--src/dotty/tools/dotc/core/pickling/UnPickler.scala16
-rw-r--r--src/dotty/tools/dotc/core/transform/Erasure.scala8
-rw-r--r--src/test/showClass.scala98
-rw-r--r--test/test/ShowClassTests.scala118
-rw-r--r--test/test/showClass.scala13
9 files changed, 172 insertions, 110 deletions
diff --git a/src/dotty/tools/dotc/core/Printers.scala b/src/dotty/tools/dotc/core/Printers.scala
index de9677a3a..e789e7db1 100644
--- a/src/dotty/tools/dotc/core/Printers.scala
+++ b/src/dotty/tools/dotc/core/Printers.scala
@@ -89,7 +89,7 @@ object Printers {
}
class PlainPrinter(_ctx: Context) extends Printer {
- protected[this] implicit val ctx = _ctx
+ protected[this] implicit val ctx = _ctx.fresh.withCheckPrefix(false)
def controlled(op: => Text): Text =
if (ctx.toTextRecursions < maxToTextRecursions)
@@ -98,7 +98,7 @@ object Printers {
op
} catch {
case ex: CyclicReference =>
- "<cycle involving ${ex.denot}>"
+ s"<cycle involving ${ex.denot}>"
} finally {
ctx.toTextRecursions -= 1
}
diff --git a/src/dotty/tools/dotc/core/SymDenotations.scala b/src/dotty/tools/dotc/core/SymDenotations.scala
index dc2502092..fc702b85e 100644
--- a/src/dotty/tools/dotc/core/SymDenotations.scala
+++ b/src/dotty/tools/dotc/core/SymDenotations.scala
@@ -570,7 +570,7 @@ object SymDenotations {
*/
def typeConstructor(implicit ctx: Context): TypeRef =
if ((this is PackageClass) || owner.isTerm) symbolicRef
- else TypeRef(owner.thisType, name.asTypeName)
+ else TypeRef(owner.thisType, name.asTypeName).withDenot(this)
/** The symbolic typeref representing the type constructor for this type.
* @throws ClassCastException is this is not a type
diff --git a/src/dotty/tools/dotc/core/Types.scala b/src/dotty/tools/dotc/core/Types.scala
index c349bc7ba..35225e8e7 100644
--- a/src/dotty/tools/dotc/core/Types.scala
+++ b/src/dotty/tools/dotc/core/Types.scala
@@ -257,6 +257,20 @@ object Types {
pdenot & new JointRefDenotation(NoSymbol, tp.refinedInfo.substThis(tp, pre), Period.allInRun(ctx.runId))
else
pdenot
+ case tp: ThisType =>
+ val d = tp.underlying.findMember(name, pre, excluded)
+ if (d.exists) d
+ else
+ // There is a special case to handle:
+ // trait Super { this: Sub => private class Inner {} println(this.Inner) }
+ // class Sub extends Super
+ // When resolving Super.this.Inner, the normal logic goes to the self type and
+ // looks for Inner from there. But this fails because Inner is private.
+ // We fix the problem by having the following fallback case, which links up the
+ // member in Super instead of Sub.
+ // As an example of this in the wild, see
+ // loadClassWithPrivateInnerAndSubSelf in ShowClassTests
+ tp.cls.symbolicRef.findMember(name, pre, excluded)
case tp: TypeProxy =>
tp.underlying.findMember(name, pre, excluded)
case tp: ClassInfo =>
@@ -868,6 +882,11 @@ object Types {
lastDenotation
}
+ private[core] final def withDenot(denot: Denotation): this.type = {
+ lastDenotation = denot
+ this
+ }
+
protected def loadDenot(implicit ctx: Context) = prefix.member(name)
def isType = name.isTypeName
@@ -1659,7 +1678,7 @@ object Types {
class FatalTypeError(msg: String) extends TypeError(msg)
class MalformedType(pre: Type, denot: Denotation)
extends FatalTypeError(s"malformed type: $pre is not a legal prefix for $denot")
- class CyclicReference(denot: SymDenotation)
+ class CyclicReference(val denot: SymDenotation)
extends FatalTypeError(s"cyclic reference involving $denot")
// ----- Misc utilities ---------------------------------------------------------
diff --git a/src/dotty/tools/dotc/core/pickling/ClassfileParser.scala b/src/dotty/tools/dotc/core/pickling/ClassfileParser.scala
index 6b7721213..4981a6f4e 100644
--- a/src/dotty/tools/dotc/core/pickling/ClassfileParser.scala
+++ b/src/dotty/tools/dotc/core/pickling/ClassfileParser.scala
@@ -229,7 +229,7 @@ class ClassfileParser(
case 'L' =>
def processInner(tp: Type): Type = tp match {
case tp @ TypeRef(pre, name) if !(tp.symbol.owner is Flags.ModuleClass) =>
- TypeRef(pre.widen, name)
+ TypeRef(processInner(pre.widen), name)
case _ =>
tp
}
diff --git a/src/dotty/tools/dotc/core/pickling/UnPickler.scala b/src/dotty/tools/dotc/core/pickling/UnPickler.scala
index e34209aa1..161034bde 100644
--- a/src/dotty/tools/dotc/core/pickling/UnPickler.scala
+++ b/src/dotty/tools/dotc/core/pickling/UnPickler.scala
@@ -364,14 +364,16 @@ class UnPickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClassRoot:
// return NoSymbol
if (tag == EXTMODCLASSref) {
- unimplementedTree(s"nested objects")
- /*
+ val module = owner.info.decl(name.toTermName).suchThat(_ is Module)
+ module.info // force it, as completer does not yet point to module class.
+ module.symbol.moduleClass
+
+ /* was:
val moduleVar = owner.info.decl(name.toTermName.moduleVarName).symbol
if (moduleVar.isLazyAccessor)
return moduleVar.lazyAccessor.lazyAccessor
-*/
- }
- NoSymbol
+ */
+ } else NoSymbol
}
// println(s"read ext symbol $name from ${owner.denot.debugString} in ${classRoot.debugString}") // !!! DEBUG
@@ -562,7 +564,9 @@ class UnPickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClassRoot:
val tp1 = elim(tp)
val isBound = (tp: Type) => boundSyms contains tp.typeSymbol
if (tp1 existsPart isBound) {
- val tp2 = tp1.subst(boundSyms, boundSyms map (_ => defn.AnyType))
+ val anyTypes = boundSyms map (_ => defn.AnyType)
+ val boundBounds = boundSyms map (_.info.bounds.hi)
+ val tp2 = tp1.subst(boundSyms, boundBounds).subst(boundSyms, anyTypes)
cctx.warning(s"""failure to eliminate existential
|original type : $tp forSome {${cctx.dclsText(boundSyms, "; ").show}
|reduces to : $tp1
diff --git a/src/dotty/tools/dotc/core/transform/Erasure.scala b/src/dotty/tools/dotc/core/transform/Erasure.scala
index d10415829..330442408 100644
--- a/src/dotty/tools/dotc/core/transform/Erasure.scala
+++ b/src/dotty/tools/dotc/core/transform/Erasure.scala
@@ -109,7 +109,13 @@ object Erasure {
else paramSignature(sym.info)
case tp: RefinedType =>
val parent = tp.parent
- if (parent.dealias.typeSymbol == defn.ArrayClass) paramSignature(eraseArray(tp))
+ if (parent.dealias.typeSymbol == defn.ArrayClass)
+ eraseArray(tp) match {
+ case tp1: RefinedType if tp1.parent.dealias.typeSymbol == defn.ArrayClass =>
+ paramSignature(tp1.parent) ++ "[]"
+ case tp1 =>
+ paramSignature(tp1)
+ }
else paramSignature(parent)
case tp: TypeProxy =>
paramSignature(tp.underlying)
diff --git a/src/test/showClass.scala b/src/test/showClass.scala
deleted file mode 100644
index 823e59d5c..000000000
--- a/src/test/showClass.scala
+++ /dev/null
@@ -1,98 +0,0 @@
-package test
-
-import dotty.tools.dotc.core._
-import Contexts._
-import Symbols._, Flags._, Types._, dotty.tools.dotc.util.Texts._
-import Decorators._
-
-object showClass {
-
- private val blackList = List(
- // the followig classes cannot be read correctly because they
- // contain illegally pickled @throws annotations
- // "scala.actors.remote.Proxy",
- "scala.actors.remote.Serializer",
- "scala.actors.remote.JavaSerializer",
- "scala.build.genprod",
- "scala.tools.nsc.symtab.classfile.AbstractFileReader",
- "scala.remoting.Channel",
- "scala.runtime.remoting.RegistryDelegate",
- "scala.concurrent.Future",
- "scala.concurrent.impl.Future",
- "scala.concurrent.Await",
- "scala.concurrent.Awaitable",
- "scala.concurrent.impl.Promise"
- )
-
- def showPackage(pkg: TermSymbol)(implicit ctx: Context) {
- for (sym <- pkg.info.decls
- if sym.owner == pkg.moduleClass && !(sym.name contains '$')) {
- println(s"showing $sym in ${pkg.fullName}")
- if (sym is Package) showPackage(sym.asTerm)
- else if (sym.isClass) showClass(sym)
- else if (sym is Module) showClass(sym.moduleClass)
- }
- }
-
- def showClass(cls: Symbol)(implicit ctx: Context) = {
- val path = cls.fullName.toString
- if (blackList contains path)
- println(s"blacklisted: $path")
- else {
- println(s"showing $path -> ${cls.denot}")
- val cinfo = cls.info
- val infoText: Text = if (cinfo.exists) cinfo.toText else " is missing"
- println("======================================")
- println((cls.toText ~ infoText).show)
- }
- }
-
- def showClasses(path: String)(implicit ctx: Context): Unit = {
- println(s"showing file $path")
- val cls = ctx.requiredClass(path.toTypeName)
- showClass(cls)
- showClass(cls.linkedClass)
-
-/*
- val info = cls.info
- info match {
- case ClassInfo(pre, c, cps, decls, optSelfType) =>
- println(s"prefix = ${pre.show}")
- println(s"self = ${c.show}")
- println(s"parents = ${cps.map(_.show).mkString(",")}")
- println(s"showClass $path") // !!! DEBUG
- println(s"decls = ${decls.show}")
- println(s"selftype = ${optSelfType.show}")
- println(s"type-params = ${info.typeParams}")
- }
-*/
- }
-
- def main(args: Array[String]) = {
- val base = Context.theBase
- implicit val ctx = base.initialCtx
- println(ctx.settings)
- base.definitions.init()
-
- for (arg <- args) showPackage(ctx.requiredPackage(arg))
-
-// showPackage(ctx.requiredPackage("scala.reflect"))
-
- showClasses("scala.reflect.internal.StdCreators")
-// showClasses("scala.Array")
-// showClasses("scala.math.Ordering")
-// showClasses("scala.collection.JavaConversions")
-// showClasses("scala.collection.convert.Wrappers")
-// showClasses("scala.collection.mutable.WeakHashMap")
-// showClasses("scala.collection.GenIterable")
-// showClasses("scala.collection.Traversable")
-// showClasses("scala.collection.LinearSeqLike")
-// showClasses("scala.collection.immutable.List")
-// showClasses("scala.collection.convert.Wrappers")
-// showClasses("scala.collection.generic.package")
-// showClasses("scala.collection.MapLike")
-// showClasses("scala.Function1")
-// showClasses("dotty.tools.dotc.core.Types")
- println("done")
- }
-} \ No newline at end of file
diff --git a/test/test/ShowClassTests.scala b/test/test/ShowClassTests.scala
new file mode 100644
index 000000000..0f763affd
--- /dev/null
+++ b/test/test/ShowClassTests.scala
@@ -0,0 +1,118 @@
+package test
+
+import dotty.tools.dotc.core._
+import dotty.tools.dotc.core.Contexts._
+import dotty.tools.dotc.core.Symbols._
+import dotty.tools.dotc.core.Flags._
+import dotty.tools.dotc.core.Types._
+import dotty.tools.dotc.util.Texts._
+import dotty.tools.dotc.core.Decorators._
+import org.junit.Test
+
+class ShowClassTests {
+
+ private val blackList = List(
+ // the following classes cannot be read correctly because they
+ // contain illegally pickled @throws annotations
+ "scala.actors.remote.Proxy",
+ "scala.actors.remote.Serializer",
+ "scala.actors.remote.JavaSerializer",
+ "scala.build.genprod",
+ "scala.tools.nsc.symtab.classfile.AbstractFileReader",
+ "scala.remoting.Channel",
+ "scala.runtime.remoting.RegistryDelegate",
+ "scala.concurrent.Future",
+ "scala.concurrent.impl.Future",
+ "scala.concurrent.Await",
+ "scala.concurrent.Awaitable",
+ "scala.concurrent.impl.Promise",
+ // the following packages and classes cannot be read because
+ // theyt refer to external libraries which are not available
+ // (apache.ant, usually)
+ "scala.tools.ant",
+ "scala.tools.partest.PartestTask")
+
+ def showPackage(pkg: TermSymbol)(implicit ctx: Context): Unit = {
+ val path = pkg.fullName.toString
+ if (blackList contains path)
+ println(s"blacklisted package: $path")
+ else {
+ for (
+ sym <- pkg.info.decls if sym.owner == pkg.moduleClass && !(sym.name contains '$')
+ ) {
+ println(s"showing $sym in ${pkg.fullName}")
+ if (sym is Package) showPackage(sym.asTerm)
+ else if (sym.isClass) showClass(sym)
+ else if (sym is Module) showClass(sym.moduleClass)
+ }
+ }
+ }
+
+ def showPackage(path: String)(implicit ctx: Context): Unit =
+ showPackage(ctx.requiredPackage(path))
+
+ def showClass(cls: Symbol)(implicit ctx: Context) = {
+ val path = cls.fullName.toString
+ if (blackList contains path)
+ println(s"blacklisted: $path")
+ else {
+ println(s"showing $path -> ${cls.denot}")
+ val cinfo = cls.info
+ val infoText: Text = if (cinfo.exists) cinfo.toText else " is missing"
+ println("======================================")
+ println((cls.toText ~ infoText).show)
+ }
+ }
+
+ def showClasses(path: String)(implicit ctx: Context): Unit = {
+ println(s"showing file $path")
+ val cls = ctx.requiredClass(path.toTypeName)
+ showClass(cls)
+ showClass(cls.linkedClass)
+ }
+
+ implicit val ctx: Context = {
+ val base = Context.theBase
+ val ctx = base.initialCtx
+ println(ctx.settings)
+ base.definitions.init()
+ ctx
+ }
+
+ @Test
+ def loadSimpleClasses() = {
+ showClasses("scala.Array")
+ showClasses("scala.math.Ordering")
+ }
+
+ @Test
+ def loadMoreClasses() = {
+ showClasses("scala.collection.JavaConversions")
+ showClasses("scala.collection.convert.Wrappers")
+ showClasses("scala.collection.mutable.WeakHashMap")
+ showClasses("scala.collection.GenIterable")
+ showClasses("scala.collection.Traversable")
+ showClasses("scala.collection.LinearSeqLike")
+ showClasses("scala.collection.immutable.List")
+ showClasses("scala.collection.convert.Wrappers")
+ showClasses("scala.collection.generic.package")
+ showClasses("scala.collection.MapLike")
+ showClasses("scala.Function1")
+ }
+
+ @Test
+ def loadScalaReflect() = {
+ showPackage(ctx.requiredPackage("scala.reflect"))
+ }
+
+ @Test
+ def loadClassWithPrivateInnerAndSubSelf() = {
+ showClasses("scala.tools.nsc.settings.ScalaSettings")
+ showClasses("scala.tools.jline.console.history.MemoryHistory")
+ }
+
+ @Test
+ def loadJlineHistiry() = {
+ showPackage("scala.tools.jline.console.history")
+ }
+}
diff --git a/test/test/showClass.scala b/test/test/showClass.scala
new file mode 100644
index 000000000..d2c118f5d
--- /dev/null
+++ b/test/test/showClass.scala
@@ -0,0 +1,13 @@
+package test
+
+import dotty.tools.dotc.core.Decorators._
+
+object showClass extends ShowClassTests {
+
+ def main(args: Array[String]) = {
+ for (arg <- args) showPackage(ctx.requiredPackage(arg))
+// showClasses("scala.tools.jline.console.history.MemoryHistory")
+ showPackage("scala")
+ println("done")
+ }
+}