Skip to content

Commit fc35797

Browse files
committed
Add show on Tasty.Pattern
1 parent 2087635 commit fc35797

File tree

5 files changed

+15
-4
lines changed

5 files changed

+15
-4
lines changed

compiler/src/dotty/tools/dotc/tastyreflect/TastyImpl.scala

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -448,9 +448,10 @@ object TastyImpl extends scala.tasty.Tasty {
448448

449449
type Pattern = tpd.Tree
450450

451-
def PatternDeco(x: Pattern): AbstractPattern = new AbstractPattern {
452-
def pos(implicit ctx: Context): Position = x.pos
453-
def tpe(implicit ctx: Context): Types.Type = x.tpe.stripTypeVar
451+
def PatternDeco(pattern: Pattern): AbstractPattern = new AbstractPattern {
452+
def show(implicit ctx: Context, s: Show[TastyImpl.this.type]): String = s.showPattern(pattern)
453+
def pos(implicit ctx: Context): Position = pattern.pos
454+
def tpe(implicit ctx: Context): Types.Type = pattern.tpe.stripTypeVar
454455
}
455456

456457
def patternClassTag: ClassTag[Pattern] = implicitly[ClassTag[Pattern]]

library/src/scala/tasty/Tasty.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,9 @@ abstract class Tasty { tasty =>
314314

315315
type Pattern
316316

317-
trait AbstractPattern extends Typed with Positioned
317+
trait AbstractPattern extends Typed with Positioned {
318+
def show(implicit ctx: Context, s: Show[tasty.type]): String
319+
}
318320
implicit def PatternDeco(x: Pattern): AbstractPattern
319321

320322
implicit def patternClassTag: ClassTag[Pattern]

library/src/scala/tasty/util/Show.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ abstract class Show[T <: Tasty with Singleton](val tasty: T) {
66

77
def showTree(tree: tasty.Tree)(implicit ctx: tasty.Context): String
88

9+
def showPattern(pattern: tasty.Pattern)(implicit ctx: tasty.Context): String
10+
911
def showTypeOrBoundsTree(tpt: tasty.TypeOrBoundsTree)(implicit ctx: tasty.Context): String
1012

1113
def showTypeOrBounds(tpe: tasty.TypeOrBounds)(implicit ctx: tasty.Context): String

library/src/scala/tasty/util/ShowExtractors.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ class ShowExtractors[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
88
def showTree(tree: Tree)(implicit ctx: Context): String =
99
new Buffer().visitTree(tree).result()
1010

11+
def showPattern(pattern: tasty.Pattern)(implicit ctx: tasty.Context): String =
12+
new Buffer().visitPattern(pattern).result()
13+
1114
def showTypeOrBoundsTree(tpt: TypeOrBoundsTree)(implicit ctx: Context): String =
1215
new Buffer().visitTypeTree(tpt).result()
1316

library/src/scala/tasty/util/ShowSourceCode.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
77
def showTree(tree: Tree)(implicit ctx: Context): String =
88
(new Buffer).printTree(tree).result()
99

10+
def showPattern(pattern: Pattern)(implicit ctx: Context): String =
11+
(new Buffer).printPattern(pattern).result()
12+
1013
def showTypeOrBoundsTree(tpt: TypeOrBoundsTree)(implicit ctx: Context): String =
1114
(new Buffer).printTypeOrBoundsTree(tpt).result()
1215

0 commit comments

Comments
 (0)