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