summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2012-01-25 17:22:11 +0100
committerMartin Odersky <odersky@gmail.com>2012-01-25 17:22:11 +0100
commit469af446c7f739022313011f822bd52c1c5637fd (patch)
tree77e58882c788bb900238423b4b58f648d27d8c2f
parent97eca9b09af84e881aef347ff32441a1037e36f6 (diff)
downloadscala-469af446c7f739022313011f822bd52c1c5637fd.tar.gz
scala-469af446c7f739022313011f822bd52c1c5637fd.tar.bz2
scala-469af446c7f739022313011f822bd52c1c5637fd.zip
Protecting the constructors of Scopes and Symbols so that everyone is forced to go through the factory method, which adds on synchronization when run under reflection.
-rw-r--r--src/compiler/scala/reflect/internal/BaseTypeSeqs.scala6
-rw-r--r--src/compiler/scala/reflect/internal/Scopes.scala8
2 files changed, 11 insertions, 3 deletions
diff --git a/src/compiler/scala/reflect/internal/BaseTypeSeqs.scala b/src/compiler/scala/reflect/internal/BaseTypeSeqs.scala
index 53e89b3d1e..9e5c93753f 100644
--- a/src/compiler/scala/reflect/internal/BaseTypeSeqs.scala
+++ b/src/compiler/scala/reflect/internal/BaseTypeSeqs.scala
@@ -32,7 +32,11 @@ trait BaseTypeSeqs {
protected def newBaseTypeSeq(parents: List[Type], elems: Array[Type]) =
new BaseTypeSeq(parents, elems)
- class BaseTypeSeq(private[BaseTypeSeqs] val parents: List[Type], private[BaseTypeSeqs] val elems: Array[Type]) {
+ /** Note: constructor is protected to force everyone to use the factory method newBaseTypeSeq instead.
+ * This is necessary because when run from reflection every base type sequence needs to have a
+ * SynchronizedBaseTypeSeq as mixin.
+ */
+ class BaseTypeSeq protected[BaseTypeSeqs] (private[BaseTypeSeqs] val parents: List[Type], private[BaseTypeSeqs] val elems: Array[Type]) {
self =>
incCounter(baseTypeSeqCount)
incCounter(baseTypeSeqLenTotal, elems.length)
diff --git a/src/compiler/scala/reflect/internal/Scopes.scala b/src/compiler/scala/reflect/internal/Scopes.scala
index 8861386bc8..54d3de09cd 100644
--- a/src/compiler/scala/reflect/internal/Scopes.scala
+++ b/src/compiler/scala/reflect/internal/Scopes.scala
@@ -37,9 +37,13 @@ trait Scopes extends api.Scopes { self: SymbolTable =>
def unapplySeq(decls: Scope): Some[Seq[Symbol]] = Some(decls.toList)
}
- class Scope(initElems: ScopeEntry = null) extends Iterable[Symbol] {
+ /** Note: constructor is protected to force everyone to use the factory methods newScope or newNestedScope instead.
+ * This is necessary because when run from reflection every scope needs to have a
+ * SynchronizedScope as mixin.
+ */
+ class Scope protected[Scopes] (initElems: ScopeEntry = null) extends Iterable[Symbol] {
- def this(base: Scope) = {
+ protected[Scopes] def this(base: Scope) = {
this(base.elems)
nestinglevel = base.nestinglevel + 1
}