Skip to content

Commit 7561db0

Browse files
committed
Fix TypeMismatch not getting nonsensical tags in some cases
Thanks @smarter!
1 parent a7d3f6e commit 7561db0

File tree

4 files changed

+15
-15
lines changed

4 files changed

+15
-15
lines changed

src/dotty/tools/dotc/reporting/diagnostic/messages.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ object messages {
213213
}
214214
}
215215

216-
case class TypeMismatch(found: Type, expected: Type, whyNoMatch: String = "")(implicit ctx: Context)
216+
case class TypeMismatch(found: Type, expected: Type, whyNoMatch: String = "", implicitFailure: String = "")(implicit ctx: Context)
217217
extends Message("E006") {
218218
val kind = "Type Mismatch"
219219
private val (where, printCtx) = Formatting.disambiguateTypes(found, expected)
@@ -222,7 +222,7 @@ object messages {
222222
s"""|found: $fnd
223223
|required: $exp
224224
|
225-
|$where""".stripMargin + whyNoMatch
225+
|$where""".stripMargin + whyNoMatch + implicitFailure
226226

227227
val explanation = ""
228228
}

src/dotty/tools/dotc/typer/ErrorReporting.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ object ErrorReporting {
102102
def patternConstrStr(tree: Tree): String = ???
103103

104104
def typeMismatch(tree: Tree, pt: Type, implicitFailure: SearchFailure = NoImplicitMatches): Tree =
105-
errorTree(tree, typeMismatchMsg(normalize(tree.tpe, pt), pt) /*+ implicitFailure.postscript*/)
105+
errorTree(tree, typeMismatchMsg(normalize(tree.tpe, pt), pt, implicitFailure.postscript))
106106

107107
/** A subtype log explaining why `found` does not conform to `expected` */
108108
def whyNoMatchStr(found: Type, expected: Type) =
@@ -111,7 +111,7 @@ object ErrorReporting {
111111
else
112112
""
113113

114-
def typeMismatchMsg(found: Type, expected: Type) = {
114+
def typeMismatchMsg(found: Type, expected: Type, postScript: String = "") = {
115115
// replace constrained polyparams and their typevars by their bounds where possible
116116
object reported extends TypeMap {
117117
def setVariance(v: Int) = variance = v
@@ -133,7 +133,7 @@ object ErrorReporting {
133133
val found1 = reported(found)
134134
reported.setVariance(-1)
135135
val expected1 = reported(expected)
136-
TypeMismatch(found1, expected1, whyNoMatchStr(found, expected))
136+
TypeMismatch(found1, expected1, whyNoMatchStr(found, expected), postScript)
137137
}
138138

139139
/** Format `raw` implicitNotFound argument, replacing all

tests/repl/errmsgs.check

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,42 +5,42 @@ scala> val x: List[String] = List(1)
55
3:val x: List[String] = List(1)
66
^
77
found: Int(1)
8-
required: Int(1)
8+
required: String
99

1010
scala> val y: List[List[String]] = List(List(1))
1111
-- [E006] Type Mismatch Error: <console> -------------------------------------------------------------------------------
1212
3:val y: List[List[String]] = List(List(1))
1313
^
1414
found: Int(1)
15-
required: Int(1)
15+
required: String
1616

1717
scala> val z: (List[String], List[Int]) = (List(1), List("a"))
1818
-- [E006] Type Mismatch Error: <console> -------------------------------------------------------------------------------
1919
3:val z: (List[String], List[Int]) = (List(1), List("a"))
2020
^
2121
found: Int(1)
22-
required: Int(1)
22+
required: String
2323

2424
-- [E006] Type Mismatch Error: <console> -------------------------------------------------------------------------------
2525
3:val z: (List[String], List[Int]) = (List(1), List("a"))
2626
^^^
2727
found: String("a")
28-
required: String("a")
28+
required: Int
2929

3030
scala> val a: Inv[String] = new Inv(new Inv(1))
3131
-- [E006] Type Mismatch Error: <console> -------------------------------------------------------------------------------
3232
4:val a: Inv[String] = new Inv(new Inv(1))
3333
^^^^^
3434
found: Inv[T]
35-
required: Inv[T]
35+
required: String
3636

3737
where: T is a type variable with constraint >: Int(1)
3838
scala> val b: Inv[String] = new Inv(1)
3939
-- [E006] Type Mismatch Error: <console> -------------------------------------------------------------------------------
4040
4:val b: Inv[String] = new Inv(1)
4141
^
4242
found: Int(1)
43-
required: Int(1)
43+
required: String
4444

4545
scala> abstract class C {
4646
type T
@@ -61,15 +61,15 @@ scala> abstract class C {
6161
8: var y: T = x
6262
^
6363
found: C.this.T(C.this.x)
64-
required: C.this.T(C.this.x)
64+
required: T'
6565

6666
where: T is a type in class C
6767
T' is a type in the initalizer of value s which is an alias of String
6868
-- [E006] Type Mismatch Error: <console> -------------------------------------------------------------------------------
6969
12: val z: T = y
7070
^
7171
found: T(y)
72-
required: T(y)
72+
required: T'
7373

7474
where: T is a type in the initalizer of value s which is an alias of String
7575
T' is a type in method f which is an alias of Int

tests/repl/imports.check

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ scala> buf += xs
1111
10:buf += xs
1212
^^
1313
found: scala.collection.immutable.List[Int](o.xs)
14-
required: scala.collection.immutable.List[Int](o.xs)
14+
required: String
1515

1616
-- [E006] Type Mismatch Error: <console> -------------------------------------------------------------------------------
1717
10:buf += xs
1818
^^^^^^^^^
1919
found: String
20-
required: String
20+
required: scala.collection.mutable.ListBuffer[Int]
2121

2222
scala> buf ++= xs
2323
res1: scala.collection.mutable.ListBuffer[Int] = ListBuffer(1, 2, 3)

0 commit comments

Comments
 (0)