@@ -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,9 @@ private[repl] class Rendering(parentClassLoader: Option[ClassLoader] = None):
123
126
else
124
127
s
125
128
}
129
+ catch
130
+ case e : InvocationTargetException => throw e
131
+ case e : ReflectiveOperationException => throw InvocationTargetException (e)
126
132
127
133
/** Rewrap value class to their Wrapper class
128
134
*
@@ -131,7 +137,13 @@ private[repl] class Rendering(parentClassLoader: Option[ClassLoader] = None):
131
137
*/
132
138
private def rewrapValueClass (sym : Symbol , value : Object )(using Context ): Option [Object ] =
133
139
if ValueClasses .isDerivedValueClass(sym) then
134
- val valueClassName = sym.flatName.encode.toString
140
+ val pkg = sym.enclosingPackageClass
141
+ val pkgName = if pkg.isEmptyPackage then " " else s " ${pkg.fullName.mangledString}. "
142
+ val clsFlatName = if sym.isOneOf(JavaDefined | ConstructorProxy ) then
143
+ // See ExtractDependencies.recordDependency
144
+ sym.flatName.stripModuleClassSuffix
145
+ else sym.flatName
146
+ val valueClassName = pkgName + clsFlatName.mangledString
135
147
val valueClass = Class .forName(valueClassName, true , classLoader())
136
148
valueClass.getConstructors.headOption.map(_.newInstance(value))
137
149
else
@@ -161,7 +173,6 @@ private[repl] class Rendering(parentClassLoader: Option[ClassLoader] = None):
161
173
162
174
/** Force module initialization in the absence of members. */
163
175
def forceModule (sym : Symbol )(using Context ): Seq [Diagnostic ] =
164
- import scala .util .control .NonFatal
165
176
def load () =
166
177
val objectName = sym.fullName.encode.toString
167
178
Class .forName(objectName, true , classLoader())
0 commit comments