Skip to content

Commit a57b4a3

Browse files
committed
Fix #1430: Avoid constrained polyparams in error message
When issuing a type mismatch error, avoid mentioning polyparams in the current constraint set and their associated typevars. Mention instead the bound that caused the constrained to become unsatisfiable (if that bound is unique, i.e. the parameter appears co- or contravariantly in the type).
1 parent a7fab6d commit a57b4a3

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,23 @@ object ErrorReporting {
113113
case tp: TypeRef => s"with info ${tp.info} / ${tp.prefix.toString} / ${tp.prefix.dealias.toString}"
114114
case _ => ""
115115
}
116+
// replace constrained polyparams and their typevars by their bounds where possible
117+
val reported = new TypeMap {
118+
def apply(tp: Type): Type = tp match {
119+
case tp: PolyParam =>
120+
val e = ctx.typerState.constraint.entry(tp)
121+
if (e.exists)
122+
if (variance > 0) e.bounds.hi
123+
else if (variance < 0) e.bounds.lo
124+
else tp
125+
else tp
126+
case tp: TypeVar => apply(tp.stripTypeVar)
127+
case _ => mapOver(tp)
128+
}
129+
}
116130
d"""type mismatch:
117131
| found : $found
118-
| required: $expected""".stripMargin + whyNoMatchStr(found, expected)
132+
| required: ${reported(expected)}""".stripMargin + whyNoMatchStr(found, expected)
119133
}
120134

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

0 commit comments

Comments
 (0)