Skip to content

Commit 82d4d0f

Browse files
committed
Add show on Tasty.Pattern
1 parent 9bf9e9d commit 82d4d0f

File tree

6 files changed

+16
-4
lines changed

6 files changed

+16
-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
@@ -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]]

library/src/scala/tasty/Tasty.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff 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]

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff 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

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff 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

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff 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

tests/run/tasty-custom-show/quoted_1.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff 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"

0 commit comments

Comments
 (0)