Skip to content

Commit e907e31

Browse files
committed
implicitNotFound: prettier printing for type funs
1 parent 3d2b107 commit e907e31

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

src/compiler/scala/tools/nsc/typechecker/Implicits.scala

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1657,18 +1657,28 @@ trait Implicits {
16571657
def formatParameterMessage(fun: Tree): String = {
16581658
val paramNames = referencedTypeParams
16591659
val paramSyms = paramNames.map(lookupTypeParam).filterNot(_ == NoSymbol)
1660-
val paramTypeRefs = paramSyms.map(sym => typeRef(NoPrefix, sym, sym.typeParams.map(_ => WildcardType)))
1660+
val paramTypeRefs = paramSyms.map(_.typeConstructor.etaExpand) // make polytypes for type constructors -- we'll abbreviate them below
16611661
val prefix = fun match {
1662-
case TypeApply(Select(qual, _), _) => qual.tpe
1663-
case Select(qual, _) => qual.tpe
1662+
case treeInfo.Applied(Select(qual, _), _, _) => qual.tpe
16641663
case _ => NoType
16651664
}
1665+
16661666
val argTypes1 = if (prefix == NoType) paramTypeRefs else paramTypeRefs.map(t => t.asSeenFrom(prefix, fun.symbol.owner))
16671667
val argTypes2 = fun match {
16681668
case TypeApply(_, targs) => argTypes1.map(_.instantiateTypeParams(fun.symbol.info.typeParams, targs.map(_.tpe)))
16691669
case _ => argTypes1
16701670
}
1671-
val argTypes = argTypes2.map(_.toString)
1671+
1672+
val argTypes = argTypes2.map{
1673+
case PolyType(tps, tr@TypeRef(_, _, tprefs)) =>
1674+
if (tps.corresponds(tprefs)((p, r) => p == r.typeSymbol)) tr.typeConstructor.toString
1675+
else {
1676+
val freshTpars = tps.mapConserve { case p if p.name == tpnme.WILDCARD => p.cloneSymbol.setName(newTypeName("?T" + tps.indexOf(p))) case p => p }
1677+
freshTpars.map(_.name).mkString("[", ", ", "] -> ") + tr.instantiateTypeParams(tps, freshTpars.map(_.typeConstructor)).toString
1678+
}
1679+
1680+
case tp => tp.toString
1681+
}
16721682
interpolate(msg, Map(paramNames zip argTypes: _*))
16731683
}
16741684

test/files/neg/t2462c.check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ t2462c.scala:33: error: No C of Foo[Int]
1010
t2462c.scala:36: error: I see no C[Foo[Int]]
1111
h[Foo[Int]]
1212
^
13-
t2462c.scala:40: error: String List[?] List[C[_]] Int Option[Long] -- .
13+
t2462c.scala:40: error: String List [?T0, ZZ] -> List[C[_]] Int Option[Long] -- .
1414
i.m[Option[Long]]
1515
^
1616
5 errors found

0 commit comments

Comments
 (0)