Skip to content

Commit 3655f31

Browse files
committed
Fix confusing error message
On 2514a.scala, we got found : Int expected: Int It turns out that the real found type was `implicit Int => Int`, so we should print that.
1 parent 30e5f26 commit 3655f31

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,12 @@ object ErrorReporting {
104104

105105
def patternConstrStr(tree: Tree): String = ???
106106

107-
def typeMismatch(tree: Tree, pt: Type, implicitFailure: SearchFailure = NoImplicitMatches): Tree =
108-
errorTree(tree, typeMismatchMsg(normalize(tree.tpe, pt), pt, implicitFailure.postscript))
107+
def typeMismatch(tree: Tree, pt: Type, implicitFailure: SearchFailure = NoImplicitMatches): Tree = {
108+
val normTp = normalize(tree.tpe, pt)
109+
val treeTp = if (normTp <:< pt) tree.tpe else normTp
110+
// use normalized type if that also shows an error, original type otherwise
111+
errorTree(tree, typeMismatchMsg(treeTp, pt, implicitFailure.postscript))
112+
}
109113

110114
/** A subtype log explaining why `found` does not conform to `expected` */
111115
def whyNoMatchStr(found: Type, expected: Type) = {

0 commit comments

Comments
 (0)