From 7561db09c19bff7871cfd96c327f6f7882480ebd Mon Sep 17 00:00:00 2001 From: Felix Mulder Date: Tue, 27 Sep 2016 17:27:59 +0200 Subject: Fix TypeMismatch not getting nonsensical tags in some cases Thanks @smarter! --- src/dotty/tools/dotc/reporting/diagnostic/messages.scala | 4 ++-- src/dotty/tools/dotc/typer/ErrorReporting.scala | 6 +++--- tests/repl/errmsgs.check | 16 ++++++++-------- tests/repl/imports.check | 4 ++-- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/dotty/tools/dotc/reporting/diagnostic/messages.scala b/src/dotty/tools/dotc/reporting/diagnostic/messages.scala index 76b2fd3e9..034e14267 100644 --- a/src/dotty/tools/dotc/reporting/diagnostic/messages.scala +++ b/src/dotty/tools/dotc/reporting/diagnostic/messages.scala @@ -213,7 +213,7 @@ object messages { } } - case class TypeMismatch(found: Type, expected: Type, whyNoMatch: String = "")(implicit ctx: Context) + case class TypeMismatch(found: Type, expected: Type, whyNoMatch: String = "", implicitFailure: String = "")(implicit ctx: Context) extends Message("E006") { val kind = "Type Mismatch" private val (where, printCtx) = Formatting.disambiguateTypes(found, expected) @@ -222,7 +222,7 @@ object messages { s"""|found: $fnd |required: $exp | - |$where""".stripMargin + whyNoMatch + |$where""".stripMargin + whyNoMatch + implicitFailure val explanation = "" } diff --git a/src/dotty/tools/dotc/typer/ErrorReporting.scala b/src/dotty/tools/dotc/typer/ErrorReporting.scala index 1fd4fc96e..1d22dc646 100644 --- a/src/dotty/tools/dotc/typer/ErrorReporting.scala +++ b/src/dotty/tools/dotc/typer/ErrorReporting.scala @@ -102,7 +102,7 @@ object ErrorReporting { def patternConstrStr(tree: Tree): String = ??? def typeMismatch(tree: Tree, pt: Type, implicitFailure: SearchFailure = NoImplicitMatches): Tree = - errorTree(tree, typeMismatchMsg(normalize(tree.tpe, pt), pt) /*+ implicitFailure.postscript*/) + 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) = @@ -111,7 +111,7 @@ object ErrorReporting { else "" - def typeMismatchMsg(found: Type, expected: Type) = { + def typeMismatchMsg(found: Type, expected: Type, postScript: String = "") = { // replace constrained polyparams and their typevars by their bounds where possible object reported extends TypeMap { def setVariance(v: Int) = variance = v @@ -133,7 +133,7 @@ object ErrorReporting { val found1 = reported(found) reported.setVariance(-1) val expected1 = reported(expected) - TypeMismatch(found1, expected1, whyNoMatchStr(found, expected)) + TypeMismatch(found1, expected1, whyNoMatchStr(found, expected), postScript) } /** Format `raw` implicitNotFound argument, replacing all diff --git a/tests/repl/errmsgs.check b/tests/repl/errmsgs.check index b791123f4..b8cff5ba2 100644 --- a/tests/repl/errmsgs.check +++ b/tests/repl/errmsgs.check @@ -5,34 +5,34 @@ scala> val x: List[String] = List(1) 3:val x: List[String] = List(1) ^ found: Int(1) - required: Int(1) + required: String scala> val y: List[List[String]] = List(List(1)) -- [E006] Type Mismatch Error: ------------------------------------------------------------------------------- 3:val y: List[List[String]] = List(List(1)) ^ found: Int(1) - required: Int(1) + required: String scala> val z: (List[String], List[Int]) = (List(1), List("a")) -- [E006] Type Mismatch Error: ------------------------------------------------------------------------------- 3:val z: (List[String], List[Int]) = (List(1), List("a")) ^ found: Int(1) - required: Int(1) + required: String -- [E006] Type Mismatch Error: ------------------------------------------------------------------------------- 3:val z: (List[String], List[Int]) = (List(1), List("a")) ^^^ found: String("a") - required: String("a") + required: Int scala> val a: Inv[String] = new Inv(new Inv(1)) -- [E006] Type Mismatch Error: ------------------------------------------------------------------------------- 4:val a: Inv[String] = new Inv(new Inv(1)) ^^^^^ found: Inv[T] - required: Inv[T] + required: String where: T is a type variable with constraint >: Int(1) scala> val b: Inv[String] = new Inv(1) @@ -40,7 +40,7 @@ scala> val b: Inv[String] = new Inv(1) 4:val b: Inv[String] = new Inv(1) ^ found: Int(1) - required: Int(1) + required: String scala> abstract class C { type T @@ -61,7 +61,7 @@ scala> abstract class C { 8: var y: T = x ^ found: C.this.T(C.this.x) - required: C.this.T(C.this.x) + required: T' where: T is a type in class C T' is a type in the initalizer of value s which is an alias of String @@ -69,7 +69,7 @@ scala> abstract class C { 12: val z: T = y ^ found: T(y) - required: T(y) + required: T' where: T is a type in the initalizer of value s which is an alias of String T' is a type in method f which is an alias of Int diff --git a/tests/repl/imports.check b/tests/repl/imports.check index 817adae87..2e8d5dcf9 100644 --- a/tests/repl/imports.check +++ b/tests/repl/imports.check @@ -11,13 +11,13 @@ scala> buf += xs 10:buf += xs ^^ found: scala.collection.immutable.List[Int](o.xs) - required: scala.collection.immutable.List[Int](o.xs) + required: String -- [E006] Type Mismatch Error: ------------------------------------------------------------------------------- 10:buf += xs ^^^^^^^^^ found: String - required: String + required: scala.collection.mutable.ListBuffer[Int] scala> buf ++= xs res1: scala.collection.mutable.ListBuffer[Int] = ListBuffer(1, 2, 3) -- cgit v1.2.3