summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Zaugg <jzaugg@gmail.com>2015-09-02 10:27:47 +1000
committerJason Zaugg <jzaugg@gmail.com>2015-09-02 10:27:47 +1000
commit32da6dce10586f9ac54877ba776447b353293851 (patch)
treeda95275a6f3078c231f3772e5c647c63c9f636c6
parent2ca3f8b7a0e526ee255dad60f79b0fb33bad5d39 (diff)
downloadscala-32da6dce10586f9ac54877ba776447b353293851.tar.gz
scala-32da6dce10586f9ac54877ba776447b353293851.tar.bz2
scala-32da6dce10586f9ac54877ba776447b353293851.zip
Try harder to avoid reporting unpositioned errors
Rather than issuing an error at NoPosition, which usually means an unpositioned tree is being typechecked, walk up the context chain for an enclosing positioned tree. I've tested this manually with ensime which was getting an unpositioned warning as a result of a unpositioned trees created by a macro in scalatest. ``` % ../scala-positioned-error/build/quick/bin/scalac @args.txt /Users/jason/code/ensime-server/core/src/it/scala/org/ensime/core/RichPresentationCompilerSpec.scala:216: warning: implicit numeric widening ) { (p, cc) => ^ ```
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Contexts.scala20
1 files changed, 12 insertions, 8 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Contexts.scala b/src/compiler/scala/tools/nsc/typechecker/Contexts.scala
index 43f2655311..c46bc7444a 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Contexts.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Contexts.scala
@@ -574,19 +574,23 @@ trait Contexts { self: Analyzer =>
/** Issue/buffer/throw the given implicit ambiguity error according to the current mode for error reporting. */
private[typechecker] def issueAmbiguousError(err: AbsAmbiguousTypeError) = reporter.issueAmbiguousError(err)(this)
/** Issue/throw the given error message according to the current mode for error reporting. */
- def error(pos: Position, msg: String) = reporter.error(pos, msg)
+ def error(pos: Position, msg: String) = reporter.error(fixPosition(pos), msg)
/** Issue/throw the given error message according to the current mode for error reporting. */
- def warning(pos: Position, msg: String) = reporter.warning(pos, msg)
- def echo(pos: Position, msg: String) = reporter.echo(pos, msg)
+ def warning(pos: Position, msg: String) = reporter.warning(fixPosition(pos), msg)
+ def echo(pos: Position, msg: String) = reporter.echo(fixPosition(pos), msg)
+ def fixPosition(pos: Position): Position = pos match {
+ case NoPosition => nextEnclosing(_.tree.pos != NoPosition).tree.pos
+ case _ => pos
+ }
def deprecationWarning(pos: Position, sym: Symbol, msg: String): Unit =
- currentRun.reporting.deprecationWarning(pos, sym, msg)
+ currentRun.reporting.deprecationWarning(fixPosition(pos), sym, msg)
def deprecationWarning(pos: Position, sym: Symbol): Unit =
- currentRun.reporting.deprecationWarning(pos, sym) // TODO: allow this to escalate to an error, and implicit search will ignore deprecated implicits
+ currentRun.reporting.deprecationWarning(fixPosition(pos), sym) // TODO: allow this to escalate to an error, and implicit search will ignore deprecated implicits
def featureWarning(pos: Position, featureName: String, featureDesc: String, featureTrait: Symbol, construct: => String = "", required: Boolean): Unit =
- currentRun.reporting.featureWarning(pos, featureName, featureDesc, featureTrait, construct, required)
+ currentRun.reporting.featureWarning(fixPosition(pos), featureName, featureDesc, featureTrait, construct, required)
// nextOuter determines which context is searched next for implicits
@@ -1239,7 +1243,7 @@ trait Contexts { self: Analyzer =>
type Error = AbsTypeError
type Warning = (Position, String)
- def issue(err: AbsTypeError)(implicit context: Context): Unit = handleError(err.errPos, addDiagString(err.errMsg))
+ def issue(err: AbsTypeError)(implicit context: Context): Unit = handleError(context.fixPosition(err.errPos), addDiagString(err.errMsg))
protected def handleError(pos: Position, msg: String): Unit
protected def handleSuppressedAmbiguous(err: AbsAmbiguousTypeError): Unit = ()
@@ -1256,7 +1260,7 @@ trait Contexts { self: Analyzer =>
* - else, let this context reporter decide
*/
final def issueAmbiguousError(err: AbsAmbiguousTypeError)(implicit context: Context): Unit =
- if (context.ambiguousErrors) reporter.error(err.errPos, addDiagString(err.errMsg)) // force reporting... see TODO above
+ if (context.ambiguousErrors) reporter.error(context.fixPosition(err.errPos), addDiagString(err.errMsg)) // force reporting... see TODO above
else handleSuppressedAmbiguous(err)
@inline final def withFreshErrorBuffer[T](expr: => T): T = {