File tree Expand file tree Collapse file tree 6 files changed +16
-4
lines changed
compiler/src/dotty/tools/dotc/tastyreflect
tests/run/tasty-custom-show Expand file tree Collapse file tree 6 files changed +16
-4
lines changed Original file line number Diff line number Diff line change @@ -454,9 +454,10 @@ object TastyImpl extends scala.tasty.Tasty {
454454
455455 type Pattern = tpd.Tree
456456
457- def PatternDeco (x : Pattern ): AbstractPattern = new AbstractPattern {
458- def pos (implicit ctx : Context ): Position = x.pos
459- def tpe (implicit ctx : Context ): Types .Type = x.tpe.stripTypeVar
457+ def PatternDeco (pattern : Pattern ): AbstractPattern = new AbstractPattern {
458+ def show (implicit ctx : Context , s : Show [TastyImpl .this .type ]): String = s.showPattern(pattern)
459+ def pos (implicit ctx : Context ): Position = pattern.pos
460+ def tpe (implicit ctx : Context ): Types .Type = pattern.tpe.stripTypeVar
460461 }
461462
462463 def patternClassTag : ClassTag [Pattern ] = implicitly[ClassTag [Pattern ]]
Original file line number Diff line number Diff line change @@ -324,7 +324,9 @@ abstract class Tasty { tasty =>
324324
325325 type Pattern
326326
327- trait AbstractPattern extends Typed with Positioned
327+ trait AbstractPattern extends Typed with Positioned {
328+ def show (implicit ctx : Context , s : Show [tasty.type ]): String
329+ }
328330 implicit def PatternDeco (x : Pattern ): AbstractPattern
329331
330332 implicit def patternClassTag : ClassTag [Pattern ]
Original file line number Diff line number Diff line change @@ -8,6 +8,8 @@ abstract class Show[T <: Tasty with Singleton](val tasty: T) {
88
99 def showCaseDef (caseDef : tasty.CaseDef )(implicit ctx : tasty.Context ): String
1010
11+ def showPattern (pattern : tasty.Pattern )(implicit ctx : tasty.Context ): String
12+
1113 def showTypeOrBoundsTree (tpt : tasty.TypeOrBoundsTree )(implicit ctx : tasty.Context ): String
1214
1315 def showTypeOrBounds (tpe : tasty.TypeOrBounds )(implicit ctx : tasty.Context ): String
Original file line number Diff line number Diff line change @@ -11,6 +11,9 @@ class ShowExtractors[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
1111 def showCaseDef (caseDef : CaseDef )(implicit ctx : Context ): String =
1212 new Buffer ().visitCaseDef(caseDef).result()
1313
14+ def showPattern (pattern : tasty.Pattern )(implicit ctx : tasty.Context ): String =
15+ new Buffer ().visitPattern(pattern).result()
16+
1417 def showTypeOrBoundsTree (tpt : TypeOrBoundsTree )(implicit ctx : Context ): String =
1518 new Buffer ().visitTypeTree(tpt).result()
1619
Original file line number Diff line number Diff line change @@ -10,6 +10,9 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
1010 def showCaseDef (caseDef : CaseDef )(implicit ctx : Context ): String =
1111 (new Buffer ).printCaseDef(caseDef).result()
1212
13+ def showPattern (pattern : Pattern )(implicit ctx : Context ): String =
14+ (new Buffer ).printPattern(pattern).result()
15+
1316 def showTypeOrBoundsTree (tpt : TypeOrBoundsTree )(implicit ctx : Context ): String =
1417 (new Buffer ).printTypeOrBoundsTree(tpt).result()
1518
Original file line number Diff line number Diff line change @@ -49,6 +49,7 @@ class DummyShow[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty0) {
4949 import tasty ._
5050 def showTree (tree : Tree )(implicit ctx : Context ): String = " Tree"
5151 def showCaseDef (caseDef : CaseDef )(implicit ctx : Context ): String = " CaseDef"
52+ def showPattern (pattern : Pattern )(implicit ctx : Context ): String = " Pattern"
5253 def showTypeOrBoundsTree (tpt : TypeOrBoundsTree )(implicit ctx : Context ): String = " TypeOrBoundsTree"
5354 def showTypeOrBounds (tpe : TypeOrBounds )(implicit ctx : Context ): String = " TypeOrBounds"
5455 def showConstant (const : Constant )(implicit ctx : Context ): String = " Constant"
You can’t perform that action at this time.
0 commit comments