File tree 1 file changed +13
-9
lines changed
compiler/src/dotty/tools/repl
1 file changed +13
-9
lines changed Original file line number Diff line number Diff line change @@ -43,25 +43,29 @@ private[repl] class Rendering(compiler: ReplCompiler,
43
43
myClassLoader
44
44
}
45
45
46
- /** Load the value of the symbol using reflection
46
+ /** Load the value of the symbol using reflection.
47
47
*
48
48
* Calling this method evaluates the expression using reflection
49
49
*/
50
50
private [this ] def valueOf (sym : Symbol )(implicit ctx : Context ): Option [String ] = {
51
51
val defn = ctx.definitions
52
- val objectName = sym.owner.fullName.encode.toString.dropRight( 1 ) // gotta drop the '$'
52
+ val objectName = sym.owner.fullName.encode.toString.stripSuffix( " $ " )
53
53
val resObj : Class [_] = Class .forName(objectName, true , classLoader())
54
- val res =
54
+ val value =
55
55
resObj
56
- .getDeclaredMethods.find(_.getName == sym.name.toString).get
57
- .invoke(null ).toString
58
-
56
+ .getDeclaredMethods.find(_.getName == sym.name.encode.toString).get
57
+ .invoke(null )
58
+ val string = value match {
59
+ case null => " null" // Calling .toString on null => NPE
60
+ case " " => " \"\" " // Sepcial cased for empty string, following scalac
61
+ case x => x.toString
62
+ }
59
63
if (! sym.is(Flags .Method ) && sym.info == defn.UnitType )
60
64
None
61
- else if (res .startsWith(str.REPL_SESSION_LINE ))
62
- Some (res .drop(str.REPL_SESSION_LINE .length).dropWhile(c => c.isDigit || c == '$' ))
65
+ else if (string .startsWith(str.REPL_SESSION_LINE ))
66
+ Some (string .drop(str.REPL_SESSION_LINE .length).dropWhile(c => c.isDigit || c == '$' ))
63
67
else
64
- Some (res )
68
+ Some (string )
65
69
}
66
70
67
71
/** Render method definition result */
You can’t perform that action at this time.
0 commit comments