diff options
author | Martin Odersky <odersky@gmail.com> | 2013-10-10 12:31:59 +0200 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2013-10-10 12:31:59 +0200 |
commit | d13fa248d5c53b165ab4f927099d0e25303ef39a (patch) | |
tree | ebb509625a45ebb9b07b0b31430b2d460e0b2418 | |
parent | f703e4d9c006a119250e1b0202712fe3e09521b4 (diff) | |
download | dotty-d13fa248d5c53b165ab4f927099d0e25303ef39a.tar.gz dotty-d13fa248d5c53b165ab4f927099d0e25303ef39a.tar.bz2 dotty-d13fa248d5c53b165ab4f927099d0e25303ef39a.zip |
Added disambiguation for reported messages.
Added method disambiguate which disambiguates any string-returning operation. Disambiguation is done by adding owners and qualifiers each symbol has a unique string representation.
-rw-r--r-- | src/dotty/tools/dotc/core/TypeComparer.scala | 11 | ||||
-rw-r--r-- | src/dotty/tools/dotc/typer/ErrorReporting.scala | 3 |
2 files changed, 9 insertions, 5 deletions
diff --git a/src/dotty/tools/dotc/core/TypeComparer.scala b/src/dotty/tools/dotc/core/TypeComparer.scala index c54312e01..46eabb606 100644 --- a/src/dotty/tools/dotc/core/TypeComparer.scala +++ b/src/dotty/tools/dotc/core/TypeComparer.scala @@ -6,6 +6,7 @@ import Types._, Contexts._, Symbols._, Flags._, Names._ import Decorators.sourcePos import StdNames.{nme, tpnme} import collection.mutable +import printing.Disambiguation.disambiguated import util.SimpleMap /** Provides methods to compare types. @@ -681,7 +682,10 @@ class TypeComparer(initctx: Context) extends DotClass { */ private def andConflict(tp1: Type, tp2: Type): Type = { val winner = if (isAsGood(tp2, tp1) && !isAsGood(tp1, tp2)) tp2 else tp1 - ctx.warning(s"${mergeErrorMsg(tp1, tp2)} as members of one type; keeping only ${showType(winner)}", ctx.tree.pos) + def msg = disambiguated { implicit ctx => + s"${mergeErrorMsg(tp1, tp2)} as members of one type; keeping only ${showType(winner)}" + } + ctx.warning(msg, ctx.tree.pos) winner } @@ -698,16 +702,15 @@ class TypeComparer(initctx: Context) extends DotClass { }.toList /** Show type, handling type types better than the default */ - private def showType(tp: Type) = tp match { + private def showType(tp: Type)(implicit ctx: Context) = tp match { case ClassInfo(_, cls, _, _, _) => cls.showLocated case bounds: TypeBounds => "type bounds" + bounds.show case _ => tp.show } /** The error message kernel for a merge conflict */ - private def mergeErrorMsg(tp1: Type, tp2: Type) = { + private def mergeErrorMsg(tp1: Type, tp2: Type)(implicit ctx: Context) = s"cannot merge ${showType(tp1)} with ${showType(tp2)}" - } /** A comparison function to pick a winner in case of a merge conflict */ private def isAsGood(tp1: Type, tp2: Type): Boolean = tp1 match { diff --git a/src/dotty/tools/dotc/typer/ErrorReporting.scala b/src/dotty/tools/dotc/typer/ErrorReporting.scala index 314ef9899..16f994e90 100644 --- a/src/dotty/tools/dotc/typer/ErrorReporting.scala +++ b/src/dotty/tools/dotc/typer/ErrorReporting.scala @@ -9,6 +9,7 @@ import Types._, Inferencing._, Contexts._, Decorators._, Denotations._, Symbols. import Applications._, Implicits._ import util.Positions._ import printing.Showable +import printing.Disambiguation.disambiguated import reporting.Reporter.SuppressedMessage object ErrorReporting { @@ -67,7 +68,7 @@ object ErrorReporting { errorTree(tree, typeMismatchStr(tree.tpe, pt) + implicitFailure.postscript) } - def typeMismatchStr(found: Type, expected: Type) = { + def typeMismatchStr(found: Type, expected: Type) = disambiguated { implicit ctx => val (typerStateStr, explanationStr) = if (ctx.settings.explaintypes.value) { val nestedCtx = ctx.fresh.withTypeComparerFn(new ExplainingTypeComparer(_)) |