diff options
author | Martin Odersky <odersky@gmail.com> | 2015-06-28 19:26:21 +0200 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2015-07-06 16:55:51 +0200 |
commit | 1061743aaaf2b18419c8fdb1cc89cb1498c9673f (patch) | |
tree | f2a2c4ab7afc7fa7a534ab84543e22e8e465098d /src/dotty/tools/dotc | |
parent | c277b9865b8a9a0f72279e0a33184ec3a4efcc33 (diff) | |
download | dotty-1061743aaaf2b18419c8fdb1cc89cb1498c9673f.tar.gz dotty-1061743aaaf2b18419c8fdb1cc89cb1498c9673f.tar.bz2 dotty-1061743aaaf2b18419c8fdb1cc89cb1498c9673f.zip |
Error instead of crash when sigName comes up with a missing reference.
A TypeRef can have be unresolved, either because it refers to something that's missing
from the classpath or because of transitive self type references. Instead of crashing
in sigName, we now report the error.
Achieved by defining a new exception type, MissingType, which derives from TypeError.
This catches t7933.scala, now integrated in the neg/selfreq.scala. The problem there was
a reference to AbsSettings, which was not a member of StandardScalaSettings.this,
but was a member of the required type of AbsSettings, which itself appeared in the
required type of StandardScalaSettings. We will outlaw in the next commit such transitive
required references.
Also collapsed TypeError and FatalTypeError. It was a misnomer anyway. Fatal were those
type errors that were caught and reported!
Open: Where else we should check for unresolved NamedTypes.
Diffstat (limited to 'src/dotty/tools/dotc')
-rw-r--r-- | src/dotty/tools/dotc/core/TypeErasure.scala | 1 | ||||
-rw-r--r-- | src/dotty/tools/dotc/core/Types.scala | 20 | ||||
-rw-r--r-- | src/dotty/tools/dotc/typer/Typer.scala | 2 |
3 files changed, 17 insertions, 6 deletions
diff --git a/src/dotty/tools/dotc/core/TypeErasure.scala b/src/dotty/tools/dotc/core/TypeErasure.scala index 9b41eb982..0ef31015c 100644 --- a/src/dotty/tools/dotc/core/TypeErasure.scala +++ b/src/dotty/tools/dotc/core/TypeErasure.scala @@ -439,6 +439,7 @@ class TypeErasure(isJava: Boolean, semiEraseVCs: Boolean, isConstructor: Boolean case ErasedValueType(_, underlying) => sigName(underlying) case tp: TypeRef => + if (!tp.denot.exists) throw new MissingType(tp.prefix, tp.name) val sym = tp.symbol if (!sym.isClass) sigName(tp.info) else if (isDerivedValueClass(sym)) sigName(eraseDerivedValueClassRef(tp)) diff --git a/src/dotty/tools/dotc/core/Types.scala b/src/dotty/tools/dotc/core/Types.scala index d6bb9c3c5..f4dbfb0e3 100644 --- a/src/dotty/tools/dotc/core/Types.scala +++ b/src/dotty/tools/dotc/core/Types.scala @@ -936,6 +936,7 @@ object Types { /** the self type of the underlying classtype */ def givenSelfType(implicit ctx: Context): Type = this match { case tp @ RefinedType(parent, name) => tp.wrapIfMember(parent.givenSelfType) + case tp: ThisType => tp.tref.givenSelfType case tp: TypeProxy => tp.underlying.givenSelfType case _ => NoType } @@ -3181,14 +3182,23 @@ object Types { // ----- Exceptions ------------------------------------------------------------- class TypeError(msg: String) extends Exception(msg) - class FatalTypeError(msg: String) extends TypeError(msg) class MalformedType(pre: Type, denot: Denotation, absMembers: Set[Name]) - extends FatalTypeError( - s"""malformed type: $pre is not a legal prefix for $denot because it contains abstract type member${if (absMembers.size == 1) "" else "s"} ${absMembers.mkString(", ")}""") + extends TypeError( + s"malformed type: $pre is not a legal prefix for $denot because it contains abstract type member${if (absMembers.size == 1) "" else "s"} ${absMembers.mkString(", ")}") + + class MissingType(pre: Type, name: Name)(implicit ctx: Context) extends TypeError( + i"""cannot resolve reference to type $pre.$name + |the classfile defining the type might be missing from the classpath${otherReason(pre)}""".stripMargin) + + private def otherReason(pre: Type)(implicit ctx: Context): String = pre match { + case pre: ThisType if pre.givenSelfType.exists => + i"\nor the self type of $pre might not contain all transitive dependencies" + case _ => "" + } class CyclicReference private (val denot: SymDenotation) - extends FatalTypeError(s"cyclic reference involving $denot") { + extends TypeError(s"cyclic reference involving $denot") { def show(implicit ctx: Context) = s"cyclic reference involving ${denot.show}" } @@ -3204,7 +3214,7 @@ object Types { } } - class MergeError(msg: String) extends FatalTypeError(msg) + class MergeError(msg: String) extends TypeError(msg) // ----- Debug --------------------------------------------------------- diff --git a/src/dotty/tools/dotc/typer/Typer.scala b/src/dotty/tools/dotc/typer/Typer.scala index 479eedd38..33ec156a1 100644 --- a/src/dotty/tools/dotc/typer/Typer.scala +++ b/src/dotty/tools/dotc/typer/Typer.scala @@ -1087,7 +1087,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit try adapt(typedUnadapted(tree, pt), pt, tree) catch { case ex: CyclicReference => errorTree(tree, cyclicErrorMsg(ex)) - case ex: FatalTypeError => errorTree(tree, ex.getMessage) + case ex: TypeError => errorTree(tree, ex.getMessage) } } |