Skip to content

Commit 1aed088

Browse files
committed
Add printing of type lambda trees
Also fix printing of variances in typedefs and params; they were suppressed before.
1 parent 6449aae commit 1aed088

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/dotty/tools/dotc/core/Flags.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,9 @@ object Flags {
436436

437437
/** Flags representing modifiers that can appear in trees */
438438
final val ModifierFlags =
439-
SourceModifierFlags | Module | Param | Synthetic | Package | Local | commonFlags(Mutable)
439+
SourceModifierFlags | Module | Param | Synthetic | Package | Local |
440+
CovariantOrOuter | ContravariantOrLabel |
441+
commonFlags(Mutable)
440442
// | Trait is subsumed by commonFlags(Lazy) from SourceModifierFlags
441443

442444
assert(ModifierFlags.isTermFlags && ModifierFlags.isTypeFlags)

src/dotty/tools/dotc/printing/RefinedPrinter.scala

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
207207

208208
import untpd.{modsDeco => _, _}
209209

210-
/** Print modifiers form symbols if tree has type, overriding the untpd behavior. */
210+
/** Print modifiers from symbols if tree has type, overriding the untpd behavior. */
211211
implicit def modsDeco(mdef: untpd.MemberDef)(implicit ctx: Context): untpd.ModsDeco =
212212
tpd.modsDeco(mdef.asInstanceOf[tpd.MemberDef]).asInstanceOf[untpd.ModsDeco]
213213

@@ -264,6 +264,11 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
264264
Text(mods.annotations.map(annotText), " ") ~~ flagsText ~~ (kw provided !suppressKw)
265265
}
266266

267+
def varianceText(mods: untpd.Modifiers) =
268+
if (mods is Covariant) "+"
269+
else if (mods is Contravariant) "-"
270+
else ""
271+
267272
def argText(arg: Tree): Text = arg match {
268273
case arg: TypeBoundsTree => "_" ~ toTextGlobal(arg)
269274
case arg: TypeTree =>
@@ -398,6 +403,8 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
398403
toTextLocal(tpt) ~ " " ~ blockText(refines)
399404
case AppliedTypeTree(tpt, args) =>
400405
toTextLocal(tpt) ~ "[" ~ Text(args map argText, ", ") ~ "]"
406+
case TypeLambdaTree(tparams, body) =>
407+
tparamsText(tparams) ~ " -> " ~ toText(body)
401408
case ByNameTypeTree(tpt) =>
402409
"=> " ~ toTextLocal(tpt)
403410
case TypeBoundsTree(lo, hi) =>
@@ -431,7 +438,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
431438
case tree @ TypeDef(name, rhs) =>
432439
def typeDefText(rhsText: Text) =
433440
dclTextOr {
434-
modText(tree.mods, "type") ~~ nameIdText(tree) ~
441+
modText(tree.mods, "type") ~~ (varianceText(tree.mods) ~ nameIdText(tree)) ~
435442
withEnclosingDef(tree) {
436443
val rhsText1 = if (tree.hasType) toText(tree.symbol.info) else rhsText
437444
tparamsText(tree.tparams) ~ rhsText1

0 commit comments

Comments
 (0)