@@ -465,7 +465,7 @@ trait Printers
465
465
(new Buffer ).printTypeOrBoundsTree(tpt).result()
466
466
467
467
def showTypeOrBounds (tpe : TypeOrBounds )(implicit ctx : Context ): String =
468
- (new Buffer ).printTypeOrBound(tpe).result()
468
+ (new Buffer ).printTypeOrBound(tpe)( None ) .result()
469
469
470
470
def showConstant (const : Constant )(implicit ctx : Context ): String =
471
471
(new Buffer ).printConstant(const).result()
@@ -544,7 +544,7 @@ trait Printers
544
544
def lineBreak (): String = " \n " + (" " * indent)
545
545
def doubleLineBreak (): String = " \n\n " + (" " * indent)
546
546
547
- def printTree (tree : Tree ): Buffer = tree match {
547
+ def printTree (tree : Tree )( implicit elideThis : Option [ Symbol ] = None ) : Buffer = tree match {
548
548
case PackageObject (body)=>
549
549
printTree(body) // Print package object
550
550
@@ -609,19 +609,19 @@ trait Printers
609
609
610
610
def printParent (parent : TermOrTypeTree , needEmptyParens : Boolean = false ): Unit = parent match {
611
611
case IsTypeTree (parent) =>
612
- printTypeTree(parent)
612
+ printTypeTree(parent)( Some (cdef.symbol))
613
613
case IsTerm (Term .TypeApply (fun, targs)) =>
614
614
printParent(fun)
615
615
case IsTerm (Term .Apply (fun@ Term .Apply (_,_), args)) =>
616
616
printParent(fun, true )
617
617
if (! args.isEmpty || needEmptyParens)
618
- inParens(printTrees(args, " , " ))
618
+ inParens(printTrees(args, " , " )( Some (cdef.symbol)) )
619
619
case IsTerm (Term .Apply (fun, args)) =>
620
620
printParent(fun)
621
621
if (! args.isEmpty || needEmptyParens)
622
- inParens(printTrees(args, " , " ))
622
+ inParens(printTrees(args, " , " )( Some (cdef.symbol)) )
623
623
case IsTerm (Term .Select (Term .New (tpt), _)) =>
624
- printTypeTree(tpt)
624
+ printTypeTree(tpt)( Some (cdef.symbol))
625
625
case IsTerm (parent) =>
626
626
throw new MatchError (parent.show)
627
627
}
@@ -673,7 +673,7 @@ trait Printers
673
673
indented {
674
674
val name1 = if (name == " _" ) " this" else name
675
675
this += " " += highlightValDef(name1, color) += " : "
676
- printTypeTree(tpt)
676
+ printTypeTree(tpt)( Some (cdef.symbol))
677
677
this += " =>"
678
678
}
679
679
}
@@ -966,7 +966,7 @@ trait Printers
966
966
(flatStats.result(), flatExpr)
967
967
}
968
968
969
- def printFlatBlock (stats : List [Statement ], expr : Term ): Buffer = {
969
+ def printFlatBlock (stats : List [Statement ], expr : Term )( implicit elideThis : Option [ Symbol ]) : Buffer = {
970
970
val (stats1, expr1) = flatBlock(stats, expr)
971
971
// Remove Term.Lambda nodes, lambdas are printed by their definition
972
972
val stats2 = stats1.filter { case Term .Lambda (_, _) => false ; case _ => true }
@@ -987,7 +987,7 @@ trait Printers
987
987
}
988
988
}
989
989
990
- def printStats (stats : List [Tree ], expr : Tree ): Unit = {
990
+ def printStats (stats : List [Tree ], expr : Tree )( implicit elideThis : Option [ Symbol ]) : Unit = {
991
991
def printSeparator (next : Tree ): Unit = {
992
992
// Avoid accidental application of opening `{` on next line with a double break
993
993
def rec (next : Tree ): Unit = next match {
@@ -1033,13 +1033,13 @@ trait Printers
1033
1033
this
1034
1034
}
1035
1035
1036
- def printTrees (trees : List [Tree ], sep : String ): Buffer =
1037
- printList(trees, sep, printTree)
1036
+ def printTrees (trees : List [Tree ], sep : String )( implicit elideThis : Option [ Symbol ]) : Buffer =
1037
+ printList(trees, sep, ( t : Tree ) => printTree(t) )
1038
1038
1039
- def printTypeTrees (trees : List [TypeTree ], sep : String ): Buffer =
1040
- printList(trees, sep, printTypeTree)
1039
+ def printTypeTrees (trees : List [TypeTree ], sep : String )( implicit elideThis : Option [ Symbol ] = None ) : Buffer =
1040
+ printList(trees, sep, ( t : TypeTree ) => printTypeTree(t) )
1041
1041
1042
- def printTypes (trees : List [Type ], sep : String ): Buffer = {
1042
+ def printTypes (trees : List [Type ], sep : String )( implicit elideThis : Option [ Symbol ]) : Buffer = {
1043
1043
def printSeparated (list : List [Type ]): Unit = list match {
1044
1044
case Nil =>
1045
1045
case x :: Nil => printType(x)
@@ -1105,7 +1105,7 @@ trait Printers
1105
1105
this
1106
1106
}
1107
1107
1108
- def printTypeOrBoundsTrees (typesTrees : List [TypeOrBoundsTree ], sep : String ): Buffer = {
1108
+ def printTypeOrBoundsTrees (typesTrees : List [TypeOrBoundsTree ], sep : String )( implicit elideThis : Option [ Symbol ]) : Buffer = {
1109
1109
def printSeparated (list : List [TypeOrBoundsTree ]): Unit = list match {
1110
1110
case Nil =>
1111
1111
case x :: Nil => printTypeOrBoundsTree(x)
@@ -1118,7 +1118,7 @@ trait Printers
1118
1118
this
1119
1119
}
1120
1120
1121
- def printTypesOrBounds (types : List [TypeOrBounds ], sep : String ): Buffer = {
1121
+ def printTypesOrBounds (types : List [TypeOrBounds ], sep : String )( implicit elideThis : Option [ Symbol ]) : Buffer = {
1122
1122
def printSeparated (list : List [TypeOrBounds ]): Unit = list match {
1123
1123
case Nil =>
1124
1124
case x :: Nil => printTypeOrBound(x)
@@ -1131,7 +1131,7 @@ trait Printers
1131
1131
this
1132
1132
}
1133
1133
1134
- def printTargsDefs (targs : List [(TypeDef , TypeDef )], isDef: Boolean = true ): Unit = {
1134
+ def printTargsDefs (targs : List [(TypeDef , TypeDef )], isDef: Boolean = true )( implicit elideThis : Option [ Symbol ]) : Unit = {
1135
1135
if (! targs.isEmpty) {
1136
1136
def printSeparated (list : List [(TypeDef , TypeDef )]): Unit = list match {
1137
1137
case Nil =>
@@ -1146,7 +1146,7 @@ trait Printers
1146
1146
}
1147
1147
}
1148
1148
1149
- def printTargDef (arg : (TypeDef , TypeDef ), isMember : Boolean = false , isDef: Boolean = true ): Buffer = {
1149
+ def printTargDef (arg : (TypeDef , TypeDef ), isMember : Boolean = false , isDef: Boolean = true )( implicit elideThis : Option [ Symbol ]) : Buffer = {
1150
1150
val (argDef, argCons) = arg
1151
1151
1152
1152
if (isDef) {
@@ -1196,7 +1196,7 @@ trait Printers
1196
1196
}
1197
1197
}
1198
1198
1199
- def printArgsDefs (args : List [ValDef ]): Unit = inParens {
1199
+ def printArgsDefs (args : List [ValDef ])( implicit elideThis : Option [ Symbol ]) : Unit = inParens {
1200
1200
args match {
1201
1201
case Nil =>
1202
1202
case arg :: _ =>
@@ -1216,7 +1216,7 @@ trait Printers
1216
1216
printSeparated(args)
1217
1217
}
1218
1218
1219
- def printAnnotations (trees : List [Term ]): Buffer = {
1219
+ def printAnnotations (trees : List [Term ])( implicit elideThis : Option [ Symbol ]) : Buffer = {
1220
1220
def printSeparated (list : List [Term ]): Unit = list match {
1221
1221
case Nil =>
1222
1222
case x :: Nil => printAnnotation(x)
@@ -1229,7 +1229,7 @@ trait Printers
1229
1229
this
1230
1230
}
1231
1231
1232
- def printParamDef (arg : ValDef ): Unit = {
1232
+ def printParamDef (arg : ValDef )( implicit elideThis : Option [ Symbol ]) : Unit = {
1233
1233
val name = arg.name
1234
1234
arg.symbol.owner match {
1235
1235
case IsDefSymbol (sym) if sym.name == " <init>" =>
@@ -1267,7 +1267,7 @@ trait Printers
1267
1267
indented {
1268
1268
caseDef.rhs match {
1269
1269
case Term .Block (stats, expr) =>
1270
- printStats(stats, expr)
1270
+ printStats(stats, expr)( None )
1271
1271
case body =>
1272
1272
this += lineBreak()
1273
1273
printTree(body)
@@ -1341,7 +1341,7 @@ trait Printers
1341
1341
this += highlightLiteral(" '" + v.name, color)
1342
1342
}
1343
1343
1344
- def printTypeOrBoundsTree (tpt : TypeOrBoundsTree ): Buffer = tpt match {
1344
+ def printTypeOrBoundsTree (tpt : TypeOrBoundsTree )( implicit elideThis : Option [ Symbol ] = None ) : Buffer = tpt match {
1345
1345
case TypeBoundsTree (lo, hi) =>
1346
1346
this += " _ >: "
1347
1347
printTypeTree(lo)
@@ -1353,7 +1353,15 @@ trait Printers
1353
1353
printTypeTree(tpt)
1354
1354
}
1355
1355
1356
- def printTypeTree (tree : TypeTree ): Buffer = tree match {
1356
+ /** Print type tree
1357
+ *
1358
+ * @param elideThis Shoud printing elide `C.this` for the given class `C`?
1359
+ * None means no eliding.
1360
+ *
1361
+ * Self type annotation and types in parent list should elide current class
1362
+ * prefix `C.this` to avoid type checking errors.
1363
+ */
1364
+ def printTypeTree (tree : TypeTree )(implicit elideThis : Option [Symbol ] = None ): Buffer = tree match {
1357
1365
case TypeTree .Inferred () =>
1358
1366
// TODO try to move this logic into `printType`
1359
1367
def printTypeAndAnnots (tpe : Type ): Buffer = tpe match {
@@ -1449,7 +1457,7 @@ trait Printers
1449
1457
1450
1458
}
1451
1459
1452
- def printTypeOrBound (tpe : TypeOrBounds ): Buffer = tpe match {
1460
+ def printTypeOrBound (tpe : TypeOrBounds )( implicit elideThis : Option [ Symbol ]) : Buffer = tpe match {
1453
1461
case tpe@ TypeBounds (lo, hi) =>
1454
1462
this += " _ >: "
1455
1463
printType(lo)
@@ -1458,7 +1466,15 @@ trait Printers
1458
1466
case IsType (tpe) => printType(tpe)
1459
1467
}
1460
1468
1461
- def printType (tpe : Type ): Buffer = tpe match {
1469
+ /** Print type
1470
+ *
1471
+ * @param elideThis Shoud printing elide `C.this` for the given class `C`?
1472
+ * None means no eliding.
1473
+ *
1474
+ * Self type annotation and types in parent list should elide current class
1475
+ * prefix `C.this` to avoid type checking errors.
1476
+ */
1477
+ def printType (tpe : Type )(implicit elideThis : Option [Symbol ] = None ): Buffer = tpe match {
1462
1478
case Type .ConstantType (const) =>
1463
1479
printConstant(const)
1464
1480
@@ -1468,6 +1484,8 @@ trait Printers
1468
1484
case IsType (prefix @ Type .SymRef (IsClassSymbol (_), _)) =>
1469
1485
printType(prefix)
1470
1486
this += " #"
1487
+ case IsType (Type .ThisType (Type .SymRef (cdef, _)))
1488
+ if elideThis.nonEmpty && cdef == elideThis.get =>
1471
1489
case IsType (prefix) =>
1472
1490
printType(prefix)
1473
1491
this += " ."
@@ -1600,7 +1618,7 @@ trait Printers
1600
1618
case PackageDef (name, _) => this += highlightTypeDef(name, color)
1601
1619
}
1602
1620
1603
- def printAnnotation (annot : Term ): Buffer = {
1621
+ def printAnnotation (annot : Term )( implicit elideThis : Option [ Symbol ]) : Buffer = {
1604
1622
val Annotation (ref, args) = annot
1605
1623
this += " @"
1606
1624
printTypeTree(ref)
@@ -1610,7 +1628,7 @@ trait Printers
1610
1628
inParens(printTrees(args, " , " ))
1611
1629
}
1612
1630
1613
- def printDefAnnotations (definition : Definition ): Buffer = {
1631
+ def printDefAnnotations (definition : Definition )( implicit elideThis : Option [ Symbol ]) : Buffer = {
1614
1632
val annots = definition.symbol.annots.filter {
1615
1633
case Annotation (annot, _) =>
1616
1634
annot.tpe match {
@@ -1625,7 +1643,7 @@ trait Printers
1625
1643
else this
1626
1644
}
1627
1645
1628
- def printRefinement (tpe : Type ): Buffer = {
1646
+ def printRefinement (tpe : Type )( implicit elideThis : Option [ Symbol ]) : Buffer = {
1629
1647
def printMethodicType (tp : TypeOrBounds ): Unit = tp match {
1630
1648
case tp @ Type .MethodType (paramNames, params, res) =>
1631
1649
inParens(printMethodicTypeParams(paramNames, params))
@@ -1665,7 +1683,7 @@ trait Printers
1665
1683
this += lineBreak() += " }"
1666
1684
}
1667
1685
1668
- def printMethodicTypeParams (paramNames : List [String ], params : List [TypeOrBounds ]): Unit = {
1686
+ def printMethodicTypeParams (paramNames : List [String ], params : List [TypeOrBounds ])( implicit elideThis : Option [ Symbol ]) : Unit = {
1669
1687
def printInfo (info : TypeOrBounds ) = info match {
1670
1688
case IsTypeBounds (info) => printBounds(info)
1671
1689
case IsType (info) =>
@@ -1686,7 +1704,7 @@ trait Printers
1686
1704
printSeparated(paramNames.zip(params))
1687
1705
}
1688
1706
1689
- def printBoundsTree (bounds : TypeBoundsTree ): Buffer = {
1707
+ def printBoundsTree (bounds : TypeBoundsTree )( implicit elideThis : Option [ Symbol ]) : Buffer = {
1690
1708
bounds.low match {
1691
1709
case TypeTree .Inferred () =>
1692
1710
case low =>
@@ -1701,7 +1719,7 @@ trait Printers
1701
1719
}
1702
1720
}
1703
1721
1704
- def printBounds (bounds : TypeBounds ): Buffer = {
1722
+ def printBounds (bounds : TypeBounds )( implicit elideThis : Option [ Symbol ]) : Buffer = {
1705
1723
this += " >: "
1706
1724
printType(bounds.low)
1707
1725
this += " <: "
0 commit comments