Skip to content

Print self types #4696

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 32 additions & 4 deletions library/src/scala/tasty/util/ShowSourceCode.scala
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,34 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
case stat@Import(_, _) => stat
case stat@Term() => stat
}
if (stats1.nonEmpty) {

def printBody(printSelf: Boolean) = {
this += " {"
indented {
if (printSelf) {
val Some(ValDef(name, tpt, _)) = self
indented {
val name1 = if (name == "_") "this" else name
this += " " += name1 += ": "
printTypeTree(tpt)
this += " =>"
}
}
this += lineBreak()
printTrees(stats1, lineBreak())
}
this += lineBreak() += "}"
}
self match {
case Some(ValDef(_, TypeTree.Singleton(_), _)) =>
if (stats1.nonEmpty)
printBody(printSelf = false)
case Some(ValDef(_, _, _)) =>
printBody(printSelf = true)
case _ =>
if (stats1.nonEmpty)
printBody(printSelf = false)
}
this

case tdef @ TypeDef(name, rhs) =>
Expand Down Expand Up @@ -853,10 +873,18 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
printType(tp)

case Type.ThisType(tp) =>
printType(tp)
tp match {
case Type.SymRef(cdef @ ClassDef(_, _, _, _, _), _) if !cdef.flags.isObject => this += ".this"
case _ => this
case Type.SymRef(cdef @ ClassDef(name, _, _, _, _), prefix) if !cdef.flags.isObject =>
def printPrefix(prefix: TypeOrBounds): Unit = prefix match {
case Type.SymRef(ClassDef(name, _, _, _, _), prefix2) =>
printPrefix(prefix2)
this += name += "."
case _ =>
}
printPrefix(prefix)
this += name
this += ".this"
case _ => printType(tp)
}

case Type.TypeLambda(paramNames, tparams, body) =>
Expand Down
12 changes: 12 additions & 0 deletions tests/pos/selftypes.decompiled
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/** Decompiled from out/posTestFromTasty/pos/selftypes/selftypes.class */
object selftypes {
trait A() extends java.lang.Object { self: selftypes.AB =>
type AA = scala.List[this.BX]
class AX()
}
trait B() extends java.lang.Object { self: selftypes.AB =>
type BB = B.this.AA
class BX()
}
class AB() extends selftypes.A with selftypes.B
}