aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2016-08-01 14:34:48 +0200
committerMartin Odersky <odersky@gmail.com>2016-08-16 17:32:54 +0200
commita57b4a3ec5b139711ad7e729040165e58751a49c (patch)
tree51f2cd5eb681e9a846eabbde1769769625a17777
parenta7fab6d84854c5b1006427cca8b1ed32b8172689 (diff)
downloaddotty-a57b4a3ec5b139711ad7e729040165e58751a49c.tar.gz
dotty-a57b4a3ec5b139711ad7e729040165e58751a49c.tar.bz2
dotty-a57b4a3ec5b139711ad7e729040165e58751a49c.zip
Fix #1430: Avoid constrained polyparams in error message
When issuing a type mismatch error, avoid mentioning polyparams in the current constraint set and their associated typevars. Mention instead the bound that caused the constrained to become unsatisfiable (if that bound is unique, i.e. the parameter appears co- or contravariantly in the type).
-rw-r--r--src/dotty/tools/dotc/typer/ErrorReporting.scala16
1 files changed, 15 insertions, 1 deletions
diff --git a/src/dotty/tools/dotc/typer/ErrorReporting.scala b/src/dotty/tools/dotc/typer/ErrorReporting.scala
index d3303628e..6f7d427cb 100644
--- a/src/dotty/tools/dotc/typer/ErrorReporting.scala
+++ b/src/dotty/tools/dotc/typer/ErrorReporting.scala
@@ -113,9 +113,23 @@ object ErrorReporting {
case tp: TypeRef => s"with info ${tp.info} / ${tp.prefix.toString} / ${tp.prefix.dealias.toString}"
case _ => ""
}
+ // replace constrained polyparams and their typevars by their bounds where possible
+ val reported = new TypeMap {
+ def apply(tp: Type): Type = tp match {
+ case tp: PolyParam =>
+ val e = ctx.typerState.constraint.entry(tp)
+ if (e.exists)
+ if (variance > 0) e.bounds.hi
+ else if (variance < 0) e.bounds.lo
+ else tp
+ else tp
+ case tp: TypeVar => apply(tp.stripTypeVar)
+ case _ => mapOver(tp)
+ }
+ }
d"""type mismatch:
| found : $found
- | required: $expected""".stripMargin + whyNoMatchStr(found, expected)
+ | required: ${reported(expected)}""".stripMargin + whyNoMatchStr(found, expected)
}
/** Format `raw` implicitNotFound argument, replacing all