@@ -8,7 +8,7 @@ import StdNames.nme
88import ast .Trees ._
99import typer .Implicits ._
1010import typer .ImportInfo
11- import Variances .varianceString
11+ import Variances .{ varianceString , varianceToInt }
1212import util .SourcePosition
1313import java .lang .Integer .toOctalString
1414import config .Config .summarizeDepth
@@ -327,14 +327,39 @@ class PlainPrinter(_ctx: Context) extends Printer {
327327 case None => " ?"
328328 }
329329
330+ protected def decomposeLambdas (bounds : TypeBounds ): (String , TypeBounds ) =
331+ def decompose (tp : Type ) = tp.stripTypeVar match
332+ case lam : HKTypeLambda =>
333+ val names =
334+ if lam.isVariant then
335+ lam.paramNames.lazyZip(lam.givenVariances).map((name, v) =>
336+ varianceString(varianceToInt(v)) + name)
337+ else lam.paramNames
338+ (names.mkString(" [" , " , " , " ]" ), lam.resType)
339+ case _ =>
340+ (" " , tp)
341+ bounds match
342+ case bounds : AliasingBounds =>
343+ val (tparamStr, aliasRhs) = decompose(bounds.alias)
344+ (tparamStr, bounds.derivedAlias(aliasRhs))
345+ case TypeBounds (lo, hi) =>
346+ val (_, loRhs) = decompose(lo)
347+ val (tparamStr, hiRhs) = decompose(hi)
348+ (tparamStr, bounds.derivedTypeBounds(loRhs, hiRhs))
349+ end decomposeLambdas
350+
330351 /** String representation of a definition's type following its name */
331352 protected def toTextRHS (tp : Type ): Text = controlled {
332353 homogenize(tp) match {
333- case tp : AliasingBounds =>
334- " = " ~ toText(tp.alias)
335- case tp @ TypeBounds (lo, hi) =>
336- (if (lo isRef defn.NothingClass ) Text () else " >: " ~ toText(lo)) ~
337- (if (hi isRef defn.AnyClass ) Text () else " <: " ~ toText(hi))
354+ case tp : TypeBounds =>
355+ val (tparamStr, rhs) = decomposeLambdas(tp)
356+ val binder = rhs match
357+ case tp : AliasingBounds =>
358+ " = " ~ toText(tp.alias)
359+ case TypeBounds (lo, hi) =>
360+ (if (lo isRef defn.NothingClass ) Text () else " >: " ~ toText(lo))
361+ ~ (if (hi isRef defn.AnyClass ) Text () else " <: " ~ toText(hi))
362+ tparamStr ~ binder
338363 case tp @ ClassInfo (pre, cls, cparents, decls, selfInfo) =>
339364 val preText = toTextLocal(pre)
340365 val (tparams, otherDecls) = decls.toList partition treatAsTypeParam
0 commit comments