@@ -10,12 +10,15 @@ import dotc.core.Contexts._
10
10
import dotc .core .Denotations .Denotation
11
11
import dotc .core .Flags
12
12
import dotc .core .Flags ._
13
+ import dotc .core .NameOps .*
13
14
import dotc .core .Symbols .{Symbol , defn }
14
15
import dotc .core .StdNames .{nme , str }
15
16
import dotc .printing .ReplPrinter
16
17
import dotc .reporting .Diagnostic
17
18
import dotc .transform .ValueClasses
18
19
20
+ import scala .util .control .NonFatal
21
+
19
22
/** This rendering object uses `ClassLoader`s to accomplish crossing the 4th
20
23
* wall (i.e. fetching back values from the compiled class files put into a
21
24
* specific class loader capable of loading from memory) and rendering them.
@@ -106,7 +109,7 @@ private[repl] class Rendering(parentClassLoader: Option[ClassLoader] = None):
106
109
*
107
110
* Calling this method evaluates the expression using reflection
108
111
*/
109
- private def valueOf (sym : Symbol )(using Context ): Option [String ] =
112
+ private def valueOf (sym : Symbol )(using Context ): Option [String ] = try
110
113
val objectName = sym.owner.fullName.encode.toString.stripSuffix(" $" )
111
114
val resObj : Class [? ] = Class .forName(objectName, true , classLoader())
112
115
val symValue = resObj
@@ -123,6 +126,7 @@ private[repl] class Rendering(parentClassLoader: Option[ClassLoader] = None):
123
126
else
124
127
s
125
128
}
129
+ catch case e : ReflectiveOperationException => throw InvocationTargetException (e)
126
130
127
131
/** Rewrap value class to their Wrapper class
128
132
*
@@ -131,7 +135,13 @@ private[repl] class Rendering(parentClassLoader: Option[ClassLoader] = None):
131
135
*/
132
136
private def rewrapValueClass (sym : Symbol , value : Object )(using Context ): Option [Object ] =
133
137
if ValueClasses .isDerivedValueClass(sym) then
134
- val valueClassName = sym.flatName.encode.toString
138
+ val pkg = sym.enclosingPackageClass
139
+ val pkgName = if pkg.isEmptyPackage then " " else s " ${pkg.fullName.mangledString}. "
140
+ val clsFlatName = if sym.isOneOf(JavaDefined | ConstructorProxy ) then
141
+ // See ExtractDependencies.recordDependency
142
+ sym.flatName.stripModuleClassSuffix
143
+ else sym.flatName
144
+ val valueClassName = pkgName + clsFlatName.mangledString
135
145
val valueClass = Class .forName(valueClassName, true , classLoader())
136
146
valueClass.getConstructors.headOption.map(_.newInstance(value))
137
147
else
@@ -161,7 +171,6 @@ private[repl] class Rendering(parentClassLoader: Option[ClassLoader] = None):
161
171
162
172
/** Force module initialization in the absence of members. */
163
173
def forceModule (sym : Symbol )(using Context ): Seq [Diagnostic ] =
164
- import scala .util .control .NonFatal
165
174
def load () =
166
175
val objectName = sym.fullName.encode.toString
167
176
Class .forName(objectName, true , classLoader())
0 commit comments