@@ -8,7 +8,7 @@ import StdNames.nme
8
8
import ast .Trees ._
9
9
import typer .Implicits ._
10
10
import typer .ImportInfo
11
- import Variances .varianceString
11
+ import Variances .{ varianceString , varianceToInt }
12
12
import util .SourcePosition
13
13
import java .lang .Integer .toOctalString
14
14
import config .Config .summarizeDepth
@@ -327,14 +327,39 @@ class PlainPrinter(_ctx: Context) extends Printer {
327
327
case None => " ?"
328
328
}
329
329
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
+
330
351
/** String representation of a definition's type following its name */
331
352
protected def toTextRHS (tp : Type ): Text = controlled {
332
353
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
338
363
case tp @ ClassInfo (pre, cls, cparents, decls, selfInfo) =>
339
364
val preText = toTextLocal(pre)
340
365
val (tparams, otherDecls) = decls.toList partition treatAsTypeParam
0 commit comments