From 340080290322fc1c24cb6b35a04fbb23497a17f6 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Fri, 23 Apr 2010 13:11:03 +0000 Subject: Fixed potential duplicate error annotation "Err... Fixed potential duplicate error annotation "Error occurred in an application involving default arguments." --- .../scala/tools/nsc/typechecker/Contexts.scala | 30 ++++++++++++---------- .../scala/tools/nsc/typechecker/Typers.scala | 3 ++- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/compiler/scala/tools/nsc/typechecker/Contexts.scala b/src/compiler/scala/tools/nsc/typechecker/Contexts.scala index a922d2ad68..759457cb70 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Contexts.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Contexts.scala @@ -46,7 +46,7 @@ trait Contexts { self: Analyzer => assert(ScalaPackage ne null, "Scala package is null") imps += ScalaPackage if (!(treeInfo.isUnitInScala(unit.body, nme.Predef) || - treeInfo.isUnitInScala(unit.body, nme.ScalaObject.toTypeName) || + treeInfo.isUnitInScala(unit.body, nme.ScalaObject) || treeInfo.containsLeadingPredefImport(List(unit.body)))) imps += PredefModule } @@ -256,23 +256,25 @@ trait Contexts { self: Analyzer => if (diagnostic.isEmpty) "" else diagnostic.mkString("\n","\n", "") - def error(pos: Position, err: Throwable) { - val msg = err.getMessage() + diagString - if (reportGeneralErrors) - unit.error(pos, if (checking) "**** ERROR DURING INTERNAL CHECKING ****\n" + msg else msg) - else - throw err + private def addDiagString(msg: String) = { + val ds = diagString + if (msg endsWith ds) msg else msg + ds } - def error(pos: Position, msg: String) { - val msg1 = msg + diagString - if (reportGeneralErrors) - unit.error(pos, if (checking) "**** ERROR DURING INTERNAL CHECKING ****\n" + msg1 else msg1) - else - throw new TypeError(pos, msg1) + private def unitError(pos: Position, msg: String) = + unit.error(pos, if (checking) "**** ERROR DURING INTERNAL CHECKING ****\n" + msg else msg) + + def error(pos: Position, err: Throwable) = + if (reportGeneralErrors) unitError(pos, addDiagString(err.getMessage())) + else throw err + + def error(pos: Position, msg: String) = { + val msg1 = addDiagString(msg) + if (reportGeneralErrors) unitError(pos, msg1) + else throw new TypeError(pos, msg1) } - def warning(pos: Position, msg: String) { + def warning(pos: Position, msg: String) = { if (reportGeneralErrors) unit.warning(pos, msg) } diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index 1a3f270c9a..879592c444 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -2313,7 +2313,8 @@ trait Typers { self: Analyzer => val (allArgs, missing) = addDefaults(args, qual, targs, previousArgss, params, fun.pos.focus, context) if (allArgs.length == formals.length) { // useful when a default doesn't match parameter type, e.g. def f[T](x:T="a"); f[Int]() - context.diagnostic = "Error occurred in an application involving default arguments." :: context.diagnostic + val note = "Error occurred in an application involving default arguments." + if (!(context.diagnostic contains note)) context.diagnostic = note :: context.diagnostic doTypedApply(tree, if (blockIsEmpty) fun else fun1, allArgs, mode, pt) } else { tryTupleApply.getOrElse { -- cgit v1.2.3