File tree Expand file tree Collapse file tree 1 file changed +17
-16
lines changed
compiler/src/dotty/tools/repl Expand file tree Collapse file tree 1 file changed +17
-16
lines changed Original file line number Diff line number Diff line change @@ -106,24 +106,25 @@ private[repl] class Rendering(parentClassLoader: Option[ClassLoader] = None) {
106
106
*
107
107
* Calling this method evaluates the expression using reflection
108
108
*/
109
- private def valueOf (sym : Symbol )(using Context ): Option [String ] = {
109
+ private def valueOf (sym : Symbol )(using Context ): Option [String ] =
110
+ if ! sym.is(Flags .Method ) && sym.info == defn.UnitType
111
+ then return None
112
+
110
113
val objectName = sym.owner.fullName.encode.toString.stripSuffix(" $" )
111
114
val resObj : Class [? ] = Class .forName(objectName, true , classLoader())
112
- val value =
113
- resObj
114
- .getDeclaredMethods.find(_.getName == sym.name.encode.toString)
115
- .map(_.invoke(null ))
116
- val string = value.map(replStringOf(_))
117
- if (! sym.is(Flags .Method ) && sym.info == defn.UnitType )
118
- None
119
- else
120
- string.map { s =>
121
- if (s.startsWith(str.REPL_SESSION_LINE ))
122
- s.drop(str.REPL_SESSION_LINE .length).dropWhile(c => c.isDigit || c == '$' )
123
- else
124
- s
125
- }
126
- }
115
+
116
+ resObj.getDeclaredMethods.find(_.getName == sym.name.encode.toString).map { method =>
117
+ val value = method.invoke(null )
118
+ val resultType = method.getReturnType()
119
+ val rawStringRepr = replStringOf(value)
120
+ val stringRepr =
121
+ if rawStringRepr.startsWith(str.REPL_SESSION_LINE )
122
+ then rawStringRepr.drop(str.REPL_SESSION_LINE .length).dropWhile(c => c.isDigit || c == '$' )
123
+ else rawStringRepr
124
+
125
+ if resultType == classOf [String ] then s """ " $stringRepr" """ else stringRepr
126
+ }
127
+ end valueOf
127
128
128
129
/** Formats errors using the `messageRenderer` */
129
130
def formatError (dia : Diagnostic )(implicit state : State ): Diagnostic =
You can’t perform that action at this time.
0 commit comments