Skip to content

Commit b9159b7

Browse files
committed
Print self types
1 parent 70eb907 commit b9159b7

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,14 +145,30 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
145145
case stat@Import(_, _) => stat
146146
case stat@Term() => stat
147147
}
148-
if (stats1.nonEmpty) {
148+
149+
def printBody(printSelf: Boolean) = {
149150
this += " {"
150151
indented {
152+
if (printSelf) {
153+
val Some(ValDef(name, tpt, _)) = self
154+
indented {
155+
val name1 = if (name == "_") "this" else name
156+
this += " " += name1 += ": "
157+
printTypeTree(tpt)
158+
this += " =>"
159+
}
160+
}
151161
this += lineBreak()
152162
printTrees(stats1, lineBreak())
153163
}
154164
this += lineBreak() += "}"
155165
}
166+
self match {
167+
case Some(ValDef(_, TypeTree.Singleton(_), _)) =>
168+
if (stats1.nonEmpty) printBody(printSelf = false)
169+
case Some(ValDef(_, _, _)) => printBody(printSelf = true)
170+
case _ => if (stats1.nonEmpty) printBody(printSelf = false)
171+
}
156172
this
157173

158174
case tdef @ TypeDef(name, rhs) =>

tests/pos/selftypes.decompiled

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/** Decompiled from out/posTestFromTasty/pos/selftypes/selftypes.class */
2+
object selftypes {
3+
trait A() extends java.lang.Object { self: selftypes.AB =>
4+
type AA = scala.List[this.BX]
5+
class AX()
6+
}
7+
trait B() extends java.lang.Object { self: selftypes.AB =>
8+
type BB = B.this.AA
9+
class BX()
10+
}
11+
class AB() extends selftypes.A with selftypes.B
12+
}

0 commit comments

Comments
 (0)