Skip to content

Commit 88b62e8

Browse files
Actually call .toString instead going thought generated *Show method
1 parent 9793424 commit 88b62e8

File tree

2 files changed

+4
-50
lines changed

2 files changed

+4
-50
lines changed

compiler/src/dotty/tools/repl/Rendering.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,9 @@ private[repl] class Rendering(compiler: ReplCompiler,
5151
val defn = ctx.definitions
5252
val objectName = sym.owner.fullName.encode.toString.dropRight(1) // gotta drop the '$'
5353
val resObj: Class[_] = Class.forName(objectName, true, classLoader())
54-
5554
val res =
5655
resObj
57-
.getDeclaredMethods.find(_.getName == sym.name.toString + "Show").get
56+
.getDeclaredMethods.find(_.getName == sym.name.toString).get
5857
.invoke(null).toString
5958

6059
if (!sym.is(Flags.Method) && sym.info == defn.UnitType)

compiler/src/dotty/tools/repl/ReplCompiler.scala

Lines changed: 3 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -74,67 +74,22 @@ class ReplCompiler(val directory: AbstractFile) extends Compiler {
7474

7575
implicit val ctx: Context = state.run.runContext
7676

77-
def createShow(name: TermName, pos: Position) = {
78-
val showName = name ++ "Show"
79-
val select = Select(Ident(name), nme.toString_)
80-
val valAsAnyRef = TypeApply(Select(Ident(name), nme.asInstanceOf_),
81-
List(Ident(tpnme.AnyRef)))
82-
val cond = InfixOp(valAsAnyRef,
83-
Ident(nme.EQ),
84-
Literal(Constant(null)))
85-
val showWithNullCheck = If(cond, Literal(Constant("null")), select)
86-
DefDef(showName, Nil, Nil, TypeTree(), showWithNullCheck).withFlags(Synthetic).withPos(pos)
87-
}
88-
89-
def createPatDefShows(patDef: PatDef) = {
90-
def createDeepShows(tree: untpd.Tree) = {
91-
class PatFolder extends UntypedDeepFolder[List[DefDef]] (
92-
(acc, tree) => tree match {
93-
case Ident(name) if name.isVariableName && name != nme.WILDCARD =>
94-
createShow(name.toTermName, tree.pos) :: acc
95-
case Bind(name, _) if name.isVariableName && name != nme.WILDCARD =>
96-
createShow(name.toTermName, tree.pos) :: acc
97-
case _ =>
98-
acc
99-
}
100-
)
101-
(new PatFolder).apply(Nil, tree).reverse
102-
}
103-
104-
// cannot fold over the whole tree because we need to generate show methods
105-
// for top level identifier starting with an uppercase (e.g. val X, Y = 2)
106-
patDef.pats.flatMap {
107-
case id @ Ident(name) if name != nme.WILDCARD =>
108-
List(createShow(name.toTermName, id.pos))
109-
case bd @ Bind(name, body) if name != nme.WILDCARD =>
110-
createShow(name.toTermName, bd.pos) :: createDeepShows(body)
111-
case other =>
112-
createDeepShows(other)
113-
}
114-
}
115-
11677
var valIdx = state.valIndex
11778

11879
val defs = trees.flatMap {
119-
case vd: ValDef =>
120-
List(vd, createShow(vd.name, vd.pos))
121-
case pd: PatDef =>
122-
pd :: createPatDefShows(pd)
12380
case expr @ Assign(id: Ident, rhs) =>
12481
// special case simple reassignment (e.g. x = 3)
12582
// in order to print the new value in the REPL
12683
val assignName = (id.name ++ str.REPL_ASSIGN_SUFFIX).toTermName
12784
val assign = ValDef(assignName, TypeTree(), id).withPos(expr.pos)
128-
val show = createShow(assignName, expr.pos)
129-
List(expr, assign, show)
85+
List(expr, assign)
13086
case expr if expr.isTerm =>
13187
val resName = (str.REPL_RES_PREFIX + valIdx).toTermName
13288
valIdx += 1
133-
val show = createShow(resName, expr.pos)
13489
val vd = ValDef(resName, TypeTree(), expr).withPos(expr.pos)
135-
List(vd, show)
90+
vd :: Nil
13691
case other =>
137-
List(other)
92+
other :: Nil
13893
}
13994

14095
Definitions(

0 commit comments

Comments
 (0)