diff options
author | Eugene Burmako <xeno.by@gmail.com> | 2012-09-12 20:18:15 +0200 |
---|---|---|
committer | Eugene Burmako <xeno.by@gmail.com> | 2012-09-12 20:18:15 +0200 |
commit | 33d43db1b83745ac6717de1f7c70a0a07a5a07c7 (patch) | |
tree | 4e4fc761d7a8bf7caa5655f9897789a57c39af4e /src | |
parent | b7e08723d142c8227181eed283e7c982f449425a (diff) | |
download | scala-33d43db1b83745ac6717de1f7c70a0a07a5a07c7.tar.gz scala-33d43db1b83745ac6717de1f7c70a0a07a5a07c7.tar.bz2 scala-33d43db1b83745ac6717de1f7c70a0a07a5a07c7.zip |
magic classes are no longer entered twice
Previously magic classes such as NothingClass were entered twice
into root mirrors of java universes. No idea how this managed not to blow up.
Now this problem is fixed.
Also, as usual when I gain understanding of something, this allows to come up
with better names. `magicSymbols` are now split into three collections:
`magicallyEnteredClasses`, `magicallyEnteredMethods` and `magicallyHijackedSymbols`.
Diffstat (limited to 'src')
-rw-r--r-- | src/reflect/scala/reflect/internal/Definitions.scala | 11 | ||||
-rw-r--r-- | src/reflect/scala/reflect/runtime/JavaMirrors.scala | 23 |
2 files changed, 21 insertions, 13 deletions
diff --git a/src/reflect/scala/reflect/internal/Definitions.scala b/src/reflect/scala/reflect/internal/Definitions.scala index c21ebfe997..7c950d9de0 100644 --- a/src/reflect/scala/reflect/internal/Definitions.scala +++ b/src/reflect/scala/reflect/internal/Definitions.scala @@ -1113,7 +1113,7 @@ trait Definitions extends api.StandardDefinitions { /** Is symbol a phantom class for which no runtime representation exists? */ lazy val isPhantomClass = Set[Symbol](AnyClass, AnyValClass, NullClass, NothingClass) - lazy val magicSymbols = List( + lazy val magicallyEnteredClasses = List( AnnotationDefaultAttr, // #2264 RepeatedParamClass, JavaRepeatedParamClass, @@ -1124,7 +1124,9 @@ trait Definitions extends api.StandardDefinitions { NullClass, NothingClass, SingletonClass, - EqualsPatternClass, + EqualsPatternClass + ) + lazy val magicallyEnteredMethods = List( Any_==, Any_!=, Any_equals, @@ -1142,10 +1144,13 @@ trait Definitions extends api.StandardDefinitions { Object_synchronized, Object_isInstanceOf, Object_asInstanceOf, - String_+, + String_+ + ) + lazy val magicallyHijackedSymbols = List( ComparableClass, JavaSerializableClass ) + lazy val magicSymbols = magicallyEnteredClasses ++ magicallyEnteredMethods ++ magicallyHijackedSymbols /** Is the symbol that of a parent which is added during parsing? */ lazy val isPossibleSyntheticParent = ProductClass.toSet[Symbol] + ProductRootClass + SerializableClass diff --git a/src/reflect/scala/reflect/runtime/JavaMirrors.scala b/src/reflect/scala/reflect/runtime/JavaMirrors.scala index 9f2c3fc79c..4cc7fc66e7 100644 --- a/src/reflect/scala/reflect/runtime/JavaMirrors.scala +++ b/src/reflect/scala/reflect/runtime/JavaMirrors.scala @@ -23,7 +23,7 @@ import language.existentials import scala.runtime.{ScalaRunTime, BoxesRunTime} import scala.reflect.internal.util.Collections._ -trait JavaMirrors extends internal.SymbolTable with api.JavaUniverse { self: SymbolTable => +trait JavaMirrors extends internal.SymbolTable with api.JavaUniverse { thisUniverse: SymbolTable => private lazy val mirrors = new WeakHashMap[ClassLoader, WeakReference[JavaMirror]]() @@ -62,9 +62,9 @@ trait JavaMirrors extends internal.SymbolTable with api.JavaUniverse { self: Sym class JavaMirror(owner: Symbol, /** Class loader that is a mastermind behind the reflexive mirror */ val classLoader: ClassLoader - ) extends Roots(owner) with super.JavaMirror { wholemirror => + ) extends Roots(owner) with super.JavaMirror { thisMirror => - val universe: self.type = self + val universe: thisUniverse.type = thisUniverse import definitions._ @@ -172,7 +172,7 @@ trait JavaMirrors extends internal.SymbolTable with api.JavaUniverse { self: Sym private class JavaInstanceMirror[T: ClassTag](val instance: T) extends InstanceMirror { - def symbol = wholemirror.classSymbol(preciseClass(instance)) + def symbol = thisMirror.classSymbol(preciseClass(instance)) def reflectField(field: TermSymbol): FieldMirror = { checkMemberOf(field, symbol) if ((field.isMethod && !field.isAccessor) || field.isModule) ErrorNotField(field) @@ -452,7 +452,7 @@ trait JavaMirrors extends internal.SymbolTable with api.JavaUniverse { self: Sym } private object unpickler extends UnPickler { - val global: self.type = self + val global: thisUniverse.type = thisUniverse } /** how connected???? @@ -599,7 +599,7 @@ trait JavaMirrors extends internal.SymbolTable with api.JavaUniverse { self: Sym completeRest() } - def completeRest(): Unit = self.synchronized { + def completeRest(): Unit = thisUniverse.synchronized { val tparams = clazz.rawInfo.typeParams val parents = try { @@ -1183,9 +1183,9 @@ trait JavaMirrors extends internal.SymbolTable with api.JavaUniverse { self: Sym mirrors(rootToLoader getOrElseUpdate(root, findLoader)).get.get } - private lazy val magicClasses: Map[(String, Name), Symbol] = { + private lazy val magicallyEnteredClasses: Map[(String, Name), Symbol] = { def mapEntry(sym: Symbol): ((String, Name), Symbol) = (sym.owner.fullName, sym.name) -> sym - Map() ++ (definitions.magicSymbols filter (_.isType) map mapEntry) + Map() ++ (definitions.magicallyEnteredClasses filter (_.isType) map mapEntry) } /** 1. If `owner` is a package class (but not the empty package) and `name` is a term name, make a new package @@ -1204,9 +1204,12 @@ trait JavaMirrors extends internal.SymbolTable with api.JavaUniverse { self: Sym if (name.isTermName && !owner.isEmptyPackageClass) return mirror.makeScalaPackage( if (owner.isRootSymbol) name.toString else owner.fullName+"."+name) - magicClasses get (owner.fullName, name) match { + magicallyEnteredClasses get (owner.fullName, name) match { case Some(tsym) => - owner.info.decls enter tsym + // magically entered classes are only present in root mirrors + // because Definitions.scala, which initializes and enters them, only affects rootMirror + // therefore we need to enter them manually for non-root mirrors + if (mirror ne thisUniverse.rootMirror) owner.info.decls enter tsym return tsym case None => } |