diff options
author | Hubert Plociniczak <hubert.plociniczak@epfl.ch> | 2011-09-23 14:22:13 +0000 |
---|---|---|
committer | Hubert Plociniczak <hubert.plociniczak@epfl.ch> | 2011-09-23 14:22:13 +0000 |
commit | 1111b27d0eb95d69d7507291d242817a2dbe7e64 (patch) | |
tree | a93f609f79877a503d501e9278479a695dbca859 /src/compiler/scala/tools/nsc/typechecker/TypeDiagnostics.scala | |
parent | 7dc4723db3b8d435a5596db9de3e0378e023c8df (diff) | |
download | scala-1111b27d0eb95d69d7507291d242817a2dbe7e64.tar.gz scala-1111b27d0eb95d69d7507291d242817a2dbe7e64.tar.bz2 scala-1111b27d0eb95d69d7507291d242817a2dbe7e64.zip |
Back to square one.
Current design of error trees complicates the design of reflection
library, and introduces sometimes unnecessary boilerplate and since I
do not want to stall that work I am reverting all the changes related
to error trees. A different design is currently under consideration but
work will be done on separate branch on github.
Revisions that got reverted:
r25705, r25704 (partially), r25673, r25669, r25649, r25644, r25621, r25620, r25619
Review by odersky and extempore.
Diffstat (limited to 'src/compiler/scala/tools/nsc/typechecker/TypeDiagnostics.scala')
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/TypeDiagnostics.scala | 73 |
1 files changed, 52 insertions, 21 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/TypeDiagnostics.scala b/src/compiler/scala/tools/nsc/typechecker/TypeDiagnostics.scala index 0b84e67447..6e0e78e8e2 100644 --- a/src/compiler/scala/tools/nsc/typechecker/TypeDiagnostics.scala +++ b/src/compiler/scala/tools/nsc/typechecker/TypeDiagnostics.scala @@ -135,6 +135,21 @@ trait TypeDiagnostics { def alternativesString(tree: Tree) = alternatives(tree) map (x => " " + methodTypeErrorString(x)) mkString ("", " <and>\n", "\n") + def missingParameterTypeMsg(fun: Tree, vparam: ValDef, pt: Type) = { + def anonMessage = ( + "\nThe argument types of an anonymous function must be fully known. (SLS 8.5)" + + "\nExpected type was: " + pt.toLongString + ) + val suffix = + if (!vparam.mods.isSynthetic) "" + else " for expanded function" + (fun match { + case Function(_, Match(_, _)) => anonMessage + case _ => " " + fun + }) + + "missing parameter type" + suffix + } + def treeSymTypeMsg(tree: Tree): String = { val sym = tree.symbol def hasParams = tree.tpe.paramSectionCount > 0 @@ -153,6 +168,34 @@ trait TypeDiagnostics { else defaultMessage } + def notEnoughArgumentsMsg(fun: Tree, missing: List[Symbol]): String = { + val suffix = { + if (missing.isEmpty) "" + else { + val keep = missing take 3 map (_.name) + ".\nUnspecified value parameter%s %s".format( + if (missing.tail.isEmpty) "" else "s", + if (missing drop 3 nonEmpty) (keep :+ "...").mkString(", ") + else keep.mkString("", ", ", ".") + ) + } + } + + "not enough arguments for " + treeSymTypeMsg(fun) + suffix + } + + def applyErrorMsg(tree: Tree, msg: String, argtpes: List[Type], pt: Type) = { + def asParams(xs: List[Any]) = xs.mkString("(", ", ", ")") + + def resType = if (pt isWildcard) "" else " with expected result type " + pt + def allTypes = (alternatives(tree) flatMap (_.paramTypes)) ++ argtpes :+ pt + def locals = alternatives(tree) flatMap (_.typeParams) + + withDisambiguation(locals, allTypes: _*) { + treeSymTypeMsg(tree) + msg + asParams(argtpes) + resType + } + } + def disambiguate(ss: List[String]) = ss match { case Nil => Nil case s :: ss => s :: (ss map { case `s` => "(some other)"+s ; case x => x }) @@ -362,10 +405,8 @@ trait TypeDiagnostics { trait TyperDiagnostics { self: Typer => - private def contextError(pos: Position, msg: String) { contextError(context, pos, msg) } - private def contextError(context0: Analyzer#Context, pos: Position, msg: String) { context0.error(pos, msg) } - private def contextError(pos: Position, err: Throwable) { contextError(context, pos, err) } - private def contextError(context0: Analyzer#Context, pos: Position, err: Throwable) { context0.error(pos, err) } + private def contextError(pos: Position, msg: String) = context.error(pos, msg) + private def contextError(pos: Position, err: Throwable) = context.error(pos, err) object checkDead { private var expr: Symbol = NoSymbol @@ -399,46 +440,36 @@ trait TypeDiagnostics { } } - private def symWasOverloaded(sym: Symbol) = sym.owner.isClass && sym.owner.info.member(sym.name).isOverloaded - private def cyclicAdjective(sym: Symbol) = if (symWasOverloaded(sym)) "overloaded" else "recursive" + def symWasOverloaded(sym: Symbol) = sym.owner.isClass && sym.owner.info.member(sym.name).isOverloaded + def cyclicAdjective(sym: Symbol) = if (symWasOverloaded(sym)) "overloaded" else "recursive" /** Returns Some(msg) if the given tree is untyped apparently due * to a cyclic reference, and None otherwise. */ - private def cyclicReferenceMessage(sym: Symbol, tree: Tree) = condOpt(tree) { + def cyclicReferenceMessage(sym: Symbol, tree: Tree) = condOpt(tree) { case ValDef(_, _, tpt, _) if tpt.tpe == null => "recursive "+sym+" needs type" case DefDef(_, _, _, _, tpt, _) if tpt.tpe == null => List(cyclicAdjective(sym), sym, "needs result type") mkString " " } - def reportTypeError(pos: Position, ex: TypeError) { - reportTypeError(context, pos, ex) - } - /** Report a type error. * * @param pos0 The position where to report the error * @param ex The exception that caused the error */ - def reportTypeError(context0: Analyzer#Context, pos: Position, ex: TypeError) { + def reportTypeError(pos: Position, ex: TypeError) { if (ex.pos == NoPosition) ex.pos = pos - if (!context0.reportGeneralErrors) throw ex + if (!context.reportGeneralErrors) throw ex if (settings.debug.value) ex.printStackTrace() ex match { case CyclicReference(sym, info: TypeCompleter) => - contextError(context0, ex.pos, cyclicReferenceMessage(sym, info.tree) getOrElse ex.getMessage()) + contextError(ex.pos, cyclicReferenceMessage(sym, info.tree) getOrElse ex.getMessage()) if (sym == ObjectClass) throw new FatalError("cannot redefine root "+sym) case _ => - contextError(context0, ex.pos, ex) + contextError(ex.pos, ex) } } - - def emitAllErrorTrees(tree: Tree, context: Context) = - errorTreesFinder(tree).foreach(_.emit(context)) - - def findAllNestedErrors(trees: List[Tree]): List[ErrorTree] = - trees.map(errorTreesFinder(_)).flatten } } |