aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2017-02-14 18:03:25 +0100
committerMartin Odersky <odersky@gmail.com>2017-02-14 18:03:25 +0100
commitef383a8a05547432c01d779976a4ea4ca2dffab9 (patch)
tree2938e1fc17a57aaa6b25c812df2e8fd6c9bdc754
parentb89738672662863168453a1bd6c6c47a6ff07f11 (diff)
downloaddotty-ef383a8a05547432c01d779976a4ea4ca2dffab9.tar.gz
dotty-ef383a8a05547432c01d779976a4ea4ca2dffab9.tar.bz2
dotty-ef383a8a05547432c01d779976a4ea4ca2dffab9.zip
Better error message for Java/Scala method discrepancies
-rw-r--r--compiler/src/dotty/tools/dotc/typer/ErrorReporting.scala16
1 files changed, 14 insertions, 2 deletions
diff --git a/compiler/src/dotty/tools/dotc/typer/ErrorReporting.scala b/compiler/src/dotty/tools/dotc/typer/ErrorReporting.scala
index 1238ad568..9d6a01ab7 100644
--- a/compiler/src/dotty/tools/dotc/typer/ErrorReporting.scala
+++ b/compiler/src/dotty/tools/dotc/typer/ErrorReporting.scala
@@ -111,11 +111,23 @@ object ErrorReporting {
errorTree(tree, typeMismatchMsg(normalize(tree.tpe, pt), pt, implicitFailure.postscript))
/** A subtype log explaining why `found` does not conform to `expected` */
- def whyNoMatchStr(found: Type, expected: Type) =
- if (ctx.settings.explaintypes.value)
+ def whyNoMatchStr(found: Type, expected: Type) = {
+ def dropJavaMethod(tp: Type): Type = tp match {
+ case tp: PolyType =>
+ tp.derivedPolyType(resType = dropJavaMethod(tp.resultType))
+ case tp: JavaMethodType =>
+ MethodType(tp.paramNames, tp.paramTypes, dropJavaMethod(tp.resultType))
+ case tp => tp
+ }
+ val found1 = dropJavaMethod(found)
+ val expected1 = dropJavaMethod(expected)
+ if ((found1 eq found) != (expected eq expected1) && (found1 <:< expected1))
+ "\n (Note that Scala's and Java's representation of this type differs)"
+ else if (ctx.settings.explaintypes.value)
"\n" + ctx.typerState.show + "\n" + TypeComparer.explained((found <:< expected)(_))
else
""
+ }
def typeMismatchMsg(found: Type, expected: Type, postScript: String = "") = {
// replace constrained polyparams and their typevars by their bounds where possible