@@ -69,15 +69,28 @@ object ErrorReporting {
69
69
" \n (Note that variables need to be initialized to be defined)"
70
70
else " "
71
71
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
+
72
82
def expectedTypeStr (tp : Type ): String = tp match {
73
83
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) )}"
75
85
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)}"
81
94
case _ =>
82
95
em " expected type $tp"
83
96
}
@@ -125,25 +138,25 @@ object ErrorReporting {
125
138
def typeMismatch (tree : Tree , pt : Type , implicitFailure : SearchFailureType = NoMatchingImplicits ): Tree = {
126
139
val normTp = normalize(tree.tpe, pt)
127
140
val normPt = normalize(pt, pt)
128
-
141
+
129
142
def contextFunctionCount (tp : Type ): Int = tp.stripped match
130
143
case defn.ContextFunctionType (_, restp, _) => 1 + contextFunctionCount(restp)
131
144
case _ => 0
132
145
def strippedTpCount = contextFunctionCount(tree.tpe) - contextFunctionCount(normTp)
133
146
def strippedPtCount = contextFunctionCount(pt) - contextFunctionCount(normPt)
134
-
147
+
135
148
val (treeTp, expectedTp) =
136
149
if normTp <:< normPt || strippedTpCount != strippedPtCount
137
150
then (tree.tpe, pt)
138
151
else (normTp, normPt)
139
152
// use normalized types if that also shows an error, and both sides stripped
140
153
// the same number of context functions. Use original types otherwise.
141
-
154
+
142
155
def missingElse = tree match
143
156
case If (_, _, elsep @ Literal (Constant (()))) if elsep.span.isSynthetic =>
144
157
" \n Maybe you are missing an else part for the conditional?"
145
158
case _ => " "
146
-
159
+
147
160
errorTree(tree, TypeMismatch (treeTp, expectedTp, Some (tree), implicitFailure.whyNoConversion, missingElse))
148
161
}
149
162
0 commit comments