summaryrefslogtreecommitdiff
path: root/src/reflect/scala/reflect/internal/pickling
diff options
context:
space:
mode:
authorLukas Rytz <lukas.rytz@gmail.com>2014-07-01 16:19:34 +0200
committerLukas Rytz <lukas.rytz@gmail.com>2014-07-07 10:41:11 +0200
commit14fa7bef120cbb996d042daba6095530167c49ed (patch)
tree7bb6a7674fb22ff5146eb2ab5c8f6b4d9514d200 /src/reflect/scala/reflect/internal/pickling
parent3f79f8eabfa4c55e167a4ca742fc46106f84b2e1 (diff)
downloadscala-14fa7bef120cbb996d042daba6095530167c49ed.tar.gz
scala-14fa7bef120cbb996d042daba6095530167c49ed.tar.bz2
scala-14fa7bef120cbb996d042daba6095530167c49ed.zip
SI-8708 Fix pickling of LOCAL_CHILD child of sealed classes
When a sealed class or trait has local children, they are not pickled in as part of the children of the symbol (introduced in 12a2b3b to fix Aladdin bug 1055). Instead the compiler adds a single child class named LOCAL_CHILD. The parents of its ClassInfoType were wrong: the first parent should be a class. For sealed traits, we were using the trait itself. Also, the LOCAL_CHILD dummy class was entered as a member of its enclosing class, which is wrong: it represents a local (non-member) class, and it's a synthetic dummy anyway.
Diffstat (limited to 'src/reflect/scala/reflect/internal/pickling')
-rw-r--r--src/reflect/scala/reflect/internal/pickling/UnPickler.scala42
1 files changed, 37 insertions, 5 deletions
diff --git a/src/reflect/scala/reflect/internal/pickling/UnPickler.scala b/src/reflect/scala/reflect/internal/pickling/UnPickler.scala
index 64a1a44722..b808666360 100644
--- a/src/reflect/scala/reflect/internal/pickling/UnPickler.scala
+++ b/src/reflect/scala/reflect/internal/pickling/UnPickler.scala
@@ -290,6 +290,25 @@ abstract class UnPickler {
def pflags = flags & PickledFlags
def finishSym(sym: Symbol): Symbol = {
+ /**
+ * member symbols (symbols owned by a class) are added to the class's scope, with a number
+ * of exceptions:
+ *
+ * (.) ...
+ * (1) `local child` represents local child classes, see comment in Pickler.putSymbol.
+ * Since it is not a member, it should not be entered in the owner's scope.
+ */
+ def shouldEnterInOwnerScope = {
+ sym.owner.isClass &&
+ sym != classRoot &&
+ sym != moduleRoot &&
+ !sym.isModuleClass &&
+ !sym.isRefinementClass &&
+ !sym.isTypeParameter &&
+ !sym.isExistentiallyBound &&
+ sym.rawname != tpnme.LOCAL_CHILD // (1)
+ }
+
markFlagsCompleted(sym)(mask = AllFlags)
sym.privateWithin = privateWithin
sym.info = (
@@ -302,8 +321,7 @@ abstract class UnPickler {
newLazyTypeRefAndAlias(inforef, readNat())
}
)
- if (sym.owner.isClass && sym != classRoot && sym != moduleRoot &&
- !sym.isModuleClass && !sym.isRefinementClass && !sym.isTypeParameter && !sym.isExistentiallyBound)
+ if (shouldEnterInOwnerScope)
symScope(sym.owner) enter sym
sym
@@ -681,10 +699,24 @@ abstract class UnPickler {
private val p = phase
protected def completeInternal(sym: Symbol) : Unit = try {
val tp = at(i, () => readType(sym.isTerm)) // after NMT_TRANSITION, revert `() => readType(sym.isTerm)` to `readType`
- if (p ne null)
- slowButSafeEnteringPhase(p) (sym setInfo tp)
+
+ // This is a temporary fix allowing to read classes generated by an older, buggy pickler.
+ // See the generation of the LOCAL_CHILD class in Pickler.scala. In an earlier version, the
+ // pickler did not add the ObjectTpe superclass, it used a trait as the first parent. This
+ // tripped an assertion in AddInterfaces which checks that the first parent is not a trait.
+ // This workaround can probably be removed in 2.12, because the 2.12 compiler is supposed
+ // to only read classfiles generated by 2.12.
+ val fixLocalChildTp = if (sym.rawname == tpnme.LOCAL_CHILD) tp match {
+ case ClassInfoType(superClass :: traits, decls, typeSymbol) if superClass.typeSymbol.isTrait =>
+ ClassInfoType(definitions.ObjectTpe :: superClass :: traits, decls, typeSymbol)
+ case _ => tp
+ } else tp
+
+ if (p ne null) {
+ slowButSafeEnteringPhase(p)(sym setInfo fixLocalChildTp)
+ }
if (currentRunId != definedAtRunId)
- sym.setInfo(adaptToNewRunMap(tp))
+ sym.setInfo(adaptToNewRunMap(fixLocalChildTp))
}
catch {
case e: MissingRequirementError => throw toTypeError(e)