aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelix Mulder <felix.mulder@gmail.com>2016-09-27 17:27:59 +0200
committerFelix Mulder <felix.mulder@gmail.com>2016-10-10 13:25:36 +0200
commit7561db09c19bff7871cfd96c327f6f7882480ebd (patch)
tree11ab91c7abd83b6b835d0eed7f81a85c7bf9c76c
parenta7d3f6e1b85f772bb343c5d006fd1e4edc844a93 (diff)
downloaddotty-7561db09c19bff7871cfd96c327f6f7882480ebd.zip
dotty-7561db09c19bff7871cfd96c327f6f7882480ebd.tar.gz
dotty-7561db09c19bff7871cfd96c327f6f7882480ebd.tar.bz2
Fix TypeMismatch not getting nonsensical tags in some cases
Thanks @smarter!
-rw-r--r--src/dotty/tools/dotc/reporting/diagnostic/messages.scala4
-rw-r--r--src/dotty/tools/dotc/typer/ErrorReporting.scala6
-rw-r--r--tests/repl/errmsgs.check16
-rw-r--r--tests/repl/imports.check4
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 76b2fd3..034e142 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 1fd4fc9..1d22dc6 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 b791123..b8cff5b 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: <console> -------------------------------------------------------------------------------
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: <console> -------------------------------------------------------------------------------
3:val z: (List[String], List[Int]) = (List(1), List("a"))
^
found: Int(1)
- required: Int(1)
+ required: String
-- [E006] Type Mismatch Error: <console> -------------------------------------------------------------------------------
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: <console> -------------------------------------------------------------------------------
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 817adae..2e8d5dc 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: <console> -------------------------------------------------------------------------------
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)