@@ -10,12 +10,15 @@ import dotc.core.Contexts._
1010import dotc .core .Denotations .Denotation
1111import dotc .core .Flags
1212import dotc .core .Flags ._
13+ import dotc .core .NameOps .*
1314import dotc .core .Symbols .{Symbol , defn }
1415import dotc .core .StdNames .{nme , str }
1516import dotc .printing .ReplPrinter
1617import dotc .reporting .Diagnostic
1718import dotc .transform .ValueClasses
1819
20+ import scala .util .control .NonFatal
21+
1922/** This rendering object uses `ClassLoader`s to accomplish crossing the 4th
2023 * wall (i.e. fetching back values from the compiled class files put into a
2124 * specific class loader capable of loading from memory) and rendering them.
@@ -106,7 +109,7 @@ private[repl] class Rendering(parentClassLoader: Option[ClassLoader] = None):
106109 *
107110 * Calling this method evaluates the expression using reflection
108111 */
109- private def valueOf (sym : Symbol )(using Context ): Option [String ] =
112+ private def valueOf (sym : Symbol )(using Context ): Option [String ] = try
110113 val objectName = sym.owner.fullName.encode.toString.stripSuffix(" $" )
111114 val resObj : Class [? ] = Class .forName(objectName, true , classLoader())
112115 val symValue = resObj
@@ -123,6 +126,9 @@ private[repl] class Rendering(parentClassLoader: Option[ClassLoader] = None):
123126 else
124127 s
125128 }
129+ catch
130+ case e : InvocationTargetException => throw e
131+ case e : ReflectiveOperationException => throw InvocationTargetException (e)
126132
127133 /** Rewrap value class to their Wrapper class
128134 *
@@ -131,7 +137,13 @@ private[repl] class Rendering(parentClassLoader: Option[ClassLoader] = None):
131137 */
132138 private def rewrapValueClass (sym : Symbol , value : Object )(using Context ): Option [Object ] =
133139 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
135147 val valueClass = Class .forName(valueClassName, true , classLoader())
136148 valueClass.getConstructors.headOption.map(_.newInstance(value))
137149 else
@@ -161,7 +173,6 @@ private[repl] class Rendering(parentClassLoader: Option[ClassLoader] = None):
161173
162174 /** Force module initialization in the absence of members. */
163175 def forceModule (sym : Symbol )(using Context ): Seq [Diagnostic ] =
164- import scala .util .control .NonFatal
165176 def load () =
166177 val objectName = sym.fullName.encode.toString
167178 Class .forName(objectName, true , classLoader())
0 commit comments