Skip to content

Commit d557ae1

Browse files
committed
Parse and print variances according to new scheme
The old encoding using semantic parameter name is still in place. The new recording inside TypeBounds exists alongside the old one.
1 parent dcff28c commit d557ae1

File tree

2 files changed

+31
-7
lines changed

2 files changed

+31
-7
lines changed

compiler/src/dotty/tools/dotc/core/Types.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import Uniques._
3131
import collection.mutable
3232
import config.Config
3333
import annotation.{tailrec, constructorOnly}
34-
3534
import language.implicitConversions
3635
import scala.util.hashing.{ MurmurHash3 => hashing }
3736
import config.Printers.{core, typr}

compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import StdNames.nme
88
import ast.Trees._
99
import typer.Implicits._
1010
import typer.ImportInfo
11-
import Variances.varianceString
11+
import Variances.{varianceString, varianceToInt}
1212
import util.SourcePosition
1313
import java.lang.Integer.toOctalString
1414
import 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

Comments
 (0)