@@ -69,15 +69,28 @@ object ErrorReporting {
6969 " \n (Note that variables need to be initialized to be defined)"
7070 else " "
7171
72+ /** Reveal arguments in FunProtos that are proteted by an IgnoredProto but were
73+ * revealed during type inference. This gives clearer error messages for overloading
74+ * resolution errors that need to show argument lists after the first. We do not
75+ * reveal other kinds of ignored prototypes since these might be misleading because
76+ * there might be a possible implicit conversion on the result.
77+ */
78+ def revealDeepenedArgs (tp : Type ): Type = tp match
79+ case tp @ IgnoredProto (deepTp : FunProto ) if tp.wasDeepened => deepTp
80+ case _ => tp
81+
7282 def expectedTypeStr (tp : Type ): String = tp match {
7383 case tp : PolyProto =>
74- em " type arguments [ ${tp.targs.tpes}%, %] and ${expectedTypeStr(tp.resultType)}"
84+ em " type arguments [ ${tp.targs.tpes}%, %] and ${expectedTypeStr(revealDeepenedArgs( tp.resultType) )}"
7585 case tp : FunProto =>
76- val result = tp.resultType match {
77- case _ : WildcardType | _ : IgnoredProto => " "
78- case tp => em " and expected result type $tp"
79- }
80- em " arguments ( ${tp.typedArgs().tpes}%, %) $result"
86+ def argStr (tp : FunProto ): String =
87+ val result = revealDeepenedArgs(tp.resultType) match {
88+ case restp : FunProto => argStr(restp)
89+ case _ : WildcardType | _ : IgnoredProto => " "
90+ case tp => em " and expected result type $tp"
91+ }
92+ em " ( ${tp.typedArgs().tpes}%, %) $result"
93+ s " arguments ${argStr(tp)}"
8194 case _ =>
8295 em " expected type $tp"
8396 }
@@ -125,25 +138,25 @@ object ErrorReporting {
125138 def typeMismatch (tree : Tree , pt : Type , implicitFailure : SearchFailureType = NoMatchingImplicits ): Tree = {
126139 val normTp = normalize(tree.tpe, pt)
127140 val normPt = normalize(pt, pt)
128-
141+
129142 def contextFunctionCount (tp : Type ): Int = tp.stripped match
130143 case defn.ContextFunctionType (_, restp, _) => 1 + contextFunctionCount(restp)
131144 case _ => 0
132145 def strippedTpCount = contextFunctionCount(tree.tpe) - contextFunctionCount(normTp)
133146 def strippedPtCount = contextFunctionCount(pt) - contextFunctionCount(normPt)
134-
147+
135148 val (treeTp, expectedTp) =
136149 if normTp <:< normPt || strippedTpCount != strippedPtCount
137150 then (tree.tpe, pt)
138151 else (normTp, normPt)
139152 // use normalized types if that also shows an error, and both sides stripped
140153 // the same number of context functions. Use original types otherwise.
141-
154+
142155 def missingElse = tree match
143156 case If (_, _, elsep @ Literal (Constant (()))) if elsep.span.isSynthetic =>
144157 " \n Maybe you are missing an else part for the conditional?"
145158 case _ => " "
146-
159+
147160 errorTree(tree, TypeMismatch (treeTp, expectedTp, Some (tree), implicitFailure.whyNoConversion, missingElse))
148161 }
149162
0 commit comments