aboutsummaryrefslogtreecommitdiff
path: root/compiler/src/dotty/tools/dotc/core
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2016-12-17 15:09:27 +0100
committerMartin Odersky <odersky@gmail.com>2016-12-17 15:09:52 +0100
commitb63480a59bbdd284a5e32281fbb0037e509f4b1e (patch)
tree825824024ad6768646c3dbf630a2db9283eedcd4 /compiler/src/dotty/tools/dotc/core
parent653698ef67a5cf8f5e0fd0fcdcd1f631f1dc96e2 (diff)
downloaddotty-b63480a59bbdd284a5e32281fbb0037e509f4b1e.tar.gz
dotty-b63480a59bbdd284a5e32281fbb0037e509f4b1e.tar.bz2
dotty-b63480a59bbdd284a5e32281fbb0037e509f4b1e.zip
Make errors are not swept under the carpet
Typer#ensureReported's comment outlines an example where errors could go unreported, resulting in error trees after typer without any reported error messages. This commit makes sure that at least one error is reported if a tree node has an error type. Fixes #1802.
Diffstat (limited to 'compiler/src/dotty/tools/dotc/core')
-rw-r--r--compiler/src/dotty/tools/dotc/core/SymDenotations.scala11
-rw-r--r--compiler/src/dotty/tools/dotc/core/Symbols.scala7
-rw-r--r--compiler/src/dotty/tools/dotc/core/TypeComparer.scala4
-rw-r--r--compiler/src/dotty/tools/dotc/core/TypeErasure.scala6
-rw-r--r--compiler/src/dotty/tools/dotc/core/TypeOps.scala2
-rw-r--r--compiler/src/dotty/tools/dotc/core/Types.scala27
6 files changed, 33 insertions, 24 deletions
diff --git a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala
index e2bb0ac1a..aaae78c57 100644
--- a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala
+++ b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala
@@ -1937,12 +1937,12 @@ object SymDenotations {
/** A completer for missing references */
class StubInfo() extends LazyType {
- def initializeToDefaults(denot: SymDenotation)(implicit ctx: Context) = {
+ def initializeToDefaults(denot: SymDenotation, errMsg: => String)(implicit ctx: Context) = {
denot.info = denot match {
case denot: ClassDenotation =>
ClassInfo(denot.owner.thisType, denot.classSymbol, Nil, EmptyScope)
case _ =>
- ErrorType
+ new ErrorType(errMsg)
}
denot.privateWithin = NoSymbol
}
@@ -1954,13 +1954,14 @@ object SymDenotations {
if (file != null) (s" in $file", file.toString)
else ("", "the signature")
val name = ctx.fresh.setSetting(ctx.settings.debugNames, true).nameString(denot.name)
- ctx.error(
+ def errMsg =
i"""bad symbolic reference. A signature$location
|refers to $name in ${denot.owner.showKind} ${denot.owner.showFullName} which is not available.
|It may be completely missing from the current classpath, or the version on
- |the classpath might be incompatible with the version used when compiling $src.""")
+ |the classpath might be incompatible with the version used when compiling $src."""
+ ctx.error(errMsg)
if (ctx.debug) throw new Error()
- initializeToDefaults(denot)
+ initializeToDefaults(denot, errMsg)
}
}
diff --git a/compiler/src/dotty/tools/dotc/core/Symbols.scala b/compiler/src/dotty/tools/dotc/core/Symbols.scala
index cfd85c49c..b10b94ad8 100644
--- a/compiler/src/dotty/tools/dotc/core/Symbols.scala
+++ b/compiler/src/dotty/tools/dotc/core/Symbols.scala
@@ -22,6 +22,7 @@ import NameOps._
import ast.tpd.Tree
import ast.TreeTypeMap
import Constants.Constant
+import reporting.diagnostic.Message
import Denotations.{ Denotation, SingleDenotation, MultiDenotation }
import collection.mutable
import io.AbstractFile
@@ -290,9 +291,11 @@ trait Symbols { this: Context =>
*/
def newSkolem(tp: Type) = newSymbol(defn.RootClass, nme.SKOLEM, SyntheticArtifact | Permanent, tp)
- def newErrorSymbol(owner: Symbol, name: Name) =
+ def newErrorSymbol(owner: Symbol, name: Name, msg: => Message) = {
+ val errType = new ErrorType(msg)
newSymbol(owner, name, SyntheticArtifact,
- if (name.isTypeName) TypeAlias(ErrorType) else ErrorType)
+ if (name.isTypeName) TypeAlias(errType) else errType)
+ }
/** Map given symbols, subjecting their attributes to the mappings
* defined in the given TreeTypeMap `ttmap`.
diff --git a/compiler/src/dotty/tools/dotc/core/TypeComparer.scala b/compiler/src/dotty/tools/dotc/core/TypeComparer.scala
index 743220f55..e8905320b 100644
--- a/compiler/src/dotty/tools/dotc/core/TypeComparer.scala
+++ b/compiler/src/dotty/tools/dotc/core/TypeComparer.scala
@@ -265,7 +265,7 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
case ConstantType(v1) => v1.value == v2.value
case _ => secondTry(tp1, tp2)
}
- case ErrorType =>
+ case _: FlexType =>
true
case _ =>
secondTry(tp1, tp2)
@@ -341,7 +341,7 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
false
}
joinOK || isSubType(tp11, tp2) && isSubType(tp12, tp2)
- case ErrorType =>
+ case _: FlexType =>
true
case _ =>
thirdTry(tp1, tp2)
diff --git a/compiler/src/dotty/tools/dotc/core/TypeErasure.scala b/compiler/src/dotty/tools/dotc/core/TypeErasure.scala
index 82943377a..2e7c1db04 100644
--- a/compiler/src/dotty/tools/dotc/core/TypeErasure.scala
+++ b/compiler/src/dotty/tools/dotc/core/TypeErasure.scala
@@ -55,7 +55,7 @@ object TypeErasure {
tp.paramTypes.forall(isErasedType) && isErasedType(tp.resultType)
case tp @ ClassInfo(pre, _, parents, decls, _) =>
isErasedType(pre) && parents.forall(isErasedType) //&& decls.forall(sym => isErasedType(sym.info)) && isErasedType(tp.selfType)
- case NoType | NoPrefix | WildcardType | ErrorType | SuperType(_, _) =>
+ case NoType | NoPrefix | WildcardType | _: ErrorType | SuperType(_, _) =>
true
case _ =>
false
@@ -398,7 +398,7 @@ class TypeErasure(isJava: Boolean, semiEraseVCs: Boolean, isConstructor: Boolean
tp.derivedClassInfo(NoPrefix, parents, erasedDecls, erasedRef(tp.selfType))
// can't replace selftype by NoType because this would lose the sourceModule link
}
- case NoType | NoPrefix | ErrorType | JavaArrayType(_) =>
+ case NoType | NoPrefix | _: ErrorType | JavaArrayType(_) =>
tp
case tp: WildcardType if wildcardOK =>
tp
@@ -506,7 +506,7 @@ class TypeErasure(isJava: Boolean, semiEraseVCs: Boolean, isConstructor: Boolean
if (inst.exists) sigName(inst) else tpnme.Uninstantiated
case tp: TypeProxy =>
sigName(tp.underlying)
- case ErrorType | WildcardType =>
+ case _: ErrorType | WildcardType =>
tpnme.WILDCARD
case tp: WildcardType =>
sigName(tp.optBounds)
diff --git a/compiler/src/dotty/tools/dotc/core/TypeOps.scala b/compiler/src/dotty/tools/dotc/core/TypeOps.scala
index 39214dd0c..f134412a7 100644
--- a/compiler/src/dotty/tools/dotc/core/TypeOps.scala
+++ b/compiler/src/dotty/tools/dotc/core/TypeOps.scala
@@ -433,7 +433,7 @@ trait TypeOps { this: Context => // TODO: Make standalone object.
formals = formals.updated(name, tp1.typeParamNamed(name))
}
normalizeToRef(tp1)
- case ErrorType =>
+ case _: ErrorType =>
defn.AnyType
case AnnotatedType(tpe, _) =>
normalizeToRef(tpe)
diff --git a/compiler/src/dotty/tools/dotc/core/Types.scala b/compiler/src/dotty/tools/dotc/core/Types.scala
index 4dffc4542..8f43ed9bb 100644
--- a/compiler/src/dotty/tools/dotc/core/Types.scala
+++ b/compiler/src/dotty/tools/dotc/core/Types.scala
@@ -15,9 +15,10 @@ import SymDenotations._
import Decorators._
import Denotations._
import Periods._
-import util.Positions.Position
+import util.Positions.{Position, NoPosition}
import util.Stats._
import util.{DotClass, SimpleMap}
+import reporting.diagnostic.Message
import ast.tpd._
import ast.TreeTypeMap
import printing.Texts._
@@ -176,7 +177,7 @@ object Types {
/** Is this type produced as a repair for an error? */
final def isError(implicit ctx: Context): Boolean = stripTypeVar match {
- case ErrorType => true
+ case _: ErrorType => true
case tp => (tp.typeSymbol is Erroneous) || (tp.termSymbol is Erroneous)
}
@@ -387,8 +388,8 @@ object Types {
tp.decls.denotsNamed(name).filterExcluded(excluded).toDenot(NoPrefix)
case tp: TypeProxy =>
tp.underlying.findDecl(name, excluded)
- case ErrorType =>
- ctx.newErrorSymbol(classSymbol orElse defn.RootClass, name)
+ case err: ErrorType =>
+ ctx.newErrorSymbol(classSymbol orElse defn.RootClass, name, err.msg)
case _ =>
NoDenotation
}
@@ -453,8 +454,8 @@ object Types {
go(tp.join)
case tp: JavaArrayType =>
defn.ObjectType.findMember(name, pre, excluded)
- case ErrorType =>
- ctx.newErrorSymbol(pre.classSymbol orElse defn.RootClass, name)
+ case err: ErrorType =>
+ ctx.newErrorSymbol(pre.classSymbol orElse defn.RootClass, name, err.msg)
case _ =>
NoDenotation
}
@@ -1497,7 +1498,7 @@ object Types {
(lastDefRunId != sym.defRunId) ||
(lastDefRunId == NoRunId)
} ||
- (lastSymbol.infoOrCompleter == ErrorType ||
+ (lastSymbol.infoOrCompleter.isInstanceOf[ErrorType] ||
sym.owner != lastSymbol.owner &&
(sym.owner.derivesFrom(lastSymbol.owner) ||
selfTypeOf(sym).derivesFrom(lastSymbol.owner) ||
@@ -2693,7 +2694,7 @@ object Types {
protected def checkInst(implicit ctx: Context): this.type = {
def check(tycon: Type): Unit = tycon.stripTypeVar match {
case tycon: TypeRef if !tycon.symbol.isClass =>
- case _: PolyParam | ErrorType | _: WildcardType =>
+ case _: PolyParam | _: ErrorType | _: WildcardType =>
case _: PolyType =>
assert(args.exists(_.isInstanceOf[TypeBounds]), s"unreduced type apply: $this")
case tycon: AnnotatedType =>
@@ -3251,12 +3252,16 @@ object Types {
override def computeHash = hashSeed
}
- abstract class ErrorType extends UncachedGroundType with ValueType
+ abstract class FlexType extends UncachedGroundType with ValueType
- object ErrorType extends ErrorType
+ class ErrorType(_msg: => Message) extends FlexType {
+ val msg = _msg
+ }
+
+ object UnspecifiedErrorType extends ErrorType("unspecified error")
/* Type used to track Select nodes that could not resolve a member and their qualifier is a scala.Dynamic. */
- object TryDynamicCallType extends ErrorType
+ object TryDynamicCallType extends FlexType
/** Wildcard type, possibly with bounds */
abstract case class WildcardType(optBounds: Type) extends CachedGroundType with TermType {