Github user retronym commented on a diff in the pull request:
https://github.com/apache/spark/pull/11410#discussion_r54557328
--- Diff:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/encoders/OuterScopes.scala
---
@@ -39,4 +41,35 @@ object OuterScopes {
def addOuterScope(outer: AnyRef): Unit = {
outerScopes.putIfAbsent(outer.getClass.getName, outer)
}
+
+ def getOuterScope(innerCls: Class[_]): AnyRef = {
+ assert(innerCls.isMemberClass)
+ val outerCls = innerCls.getDeclaringClass.getName
+ val outer = outerScopes.get(outerCls)
+ if (outer == null) {
+ outerCls match {
+ case REPLClass(line) =>
+ val loader = Utils.getContextOrSparkClassLoader
+ def loadCls(clsName: String): Class[_] = Class.forName(clsName,
true, loader)
+
+ val cls1 = loadCls(line + "$read$")
+ val obj1 = cls1.getField("MODULE$").get(null)
+
+ val obj2 = cls1.getMethod("INSTANCE").invoke(obj1)
+ val cls2 = loadCls(line + "$read")
+
+ val obj3 = cls2.getMethod("$iw").invoke(obj2)
+ val cls3 = loadCls(line + "$read$$iw")
+
+ cls3.getMethod("$iw").invoke(obj3)
+
+ case _ => null
+ }
+ } else {
+ outer
+ }
+ }
+
+ // The format of REPL generated wrapper class's name, e.g.
`$line12.$read$$iw$$iw`
--- End diff --
The assumption is incorrect. Additional nested `iw` names are needed to
typecheck when previous lines include imports.
```
â¡ (export X='getClass.getName.mkString("\u200B")'; printf "$X\n$X\nval
foo = 0\nimport foo._\n$X\n" | scala -Yrepl-class-based)
Welcome to Scala 2.11.8 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_71).
Type in expressions for evaluation. Or try :help.
scala> getClass.getName.mkString("")
res0: String = $line3.$read$$iw$$iw
scala> getClass.getName.mkString("")
res1: String = $line4.$read$$iw$$iw
scala> val foo = 0
foo: Int = 0
scala> import foo._
import foo._
scala> getClass.getName.mkString("")
res2: String = $line10.$read$$iw$$iw$$iw$$iw
scala> :quit
```
Re running this with `-Xprint-parser` helps see the structure.
Note that the REPL strips `$iw.` from output. I've inserted zero-width
spaces into the strings to be able to see them.
You can disable this feature programmatically:
```
scala> $intp.isettings.unwrapStrings = false
$intp.isettings.unwrapStrings: Boolean = false
scala> getClass.getName
res2: String = $line7.$read$$iw$$iw$
```
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]