summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/actors/scala/actors/ActorTask.scala13
-rw-r--r--src/actors/scala/actors/ReplyReactorTask.scala13
-rw-r--r--src/compiler/scala/reflect/internal/Types.scala14
-rw-r--r--src/compiler/scala/reflect/internal/pickling/UnPickler.scala2
-rw-r--r--src/compiler/scala/reflect/runtime/ToolBoxes.scala13
-rw-r--r--src/compiler/scala/tools/nsc/interactive/Global.scala4
-rw-r--r--src/compiler/scala/tools/nsc/transform/CleanUp.scala4
-rw-r--r--src/compiler/scala/tools/nsc/transform/Erasure.scala2
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Duplicators.scala2
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Infer.scala6
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Namers.scala6
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/NamesDefaults.scala4
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Typers.scala6
-rw-r--r--src/compiler/scala/tools/util/EditDistance.scala2
-rw-r--r--src/library/scala/Either.scala8
-rw-r--r--src/library/scala/Enumeration.scala35
16 files changed, 80 insertions, 54 deletions
diff --git a/src/actors/scala/actors/ActorTask.scala b/src/actors/scala/actors/ActorTask.scala
index 8d0379c095..090d0448f0 100644
--- a/src/actors/scala/actors/ActorTask.scala
+++ b/src/actors/scala/actors/ActorTask.scala
@@ -12,12 +12,16 @@ package scala.actors
/**
* @author Philipp Haller
+ * @note This class inherits a public var called 'msg' from ReactorTask,
+ * and also defines a constructor parameter which shadows it (which makes any
+ * changes to the underlying var invisible.) I can't figure out what's supposed
+ * to happen, so I renamed the constructor parameter to at least be less confusing.
*/
private[actors] class ActorTask(actor: Actor,
fun: () => Unit,
handler: PartialFunction[Any, Any],
- msg: Any)
- extends ReplyReactorTask(actor, fun, handler, msg) {
+ initialMsg: Any)
+ extends ReplyReactorTask(actor, fun, handler, initialMsg) {
protected override def beginExecution() {
super.beginExecution()
@@ -31,8 +35,11 @@ private[actors] class ActorTask(actor: Actor,
val senderInfo = try { Some(actor.sender) } catch {
case _: Exception => None
}
+ // !!! If this is supposed to be setting the current contents of the
+ // inherited mutable var rather than always the value given in the constructor,
+ // then it should be changed from initialMsg to msg.
val uncaught = UncaughtException(actor,
- if (msg != null) Some(msg) else None,
+ if (initialMsg != null) Some(initialMsg) else None,
senderInfo,
Thread.currentThread,
e)
diff --git a/src/actors/scala/actors/ReplyReactorTask.scala b/src/actors/scala/actors/ReplyReactorTask.scala
index 1db722f89b..cb63d7e000 100644
--- a/src/actors/scala/actors/ReplyReactorTask.scala
+++ b/src/actors/scala/actors/ReplyReactorTask.scala
@@ -12,18 +12,25 @@ package scala.actors
/**
* @author Philipp Haller
+ * @note This class inherits a public var called 'reactor' from ReactorTask,
+ * and also defines a constructor parameter which shadows it (which makes any
+ * changes to the underlying var invisible.) I can't figure out what's supposed
+ * to happen, so I renamed the constructor parameter to at least be less confusing.
*/
-private[actors] class ReplyReactorTask(reactor: ReplyReactor,
+private[actors] class ReplyReactorTask(replyReactor: ReplyReactor,
fun: () => Unit,
handler: PartialFunction[Any, Any],
msg: Any)
- extends ReactorTask(reactor, fun, handler, msg) {
+ extends ReactorTask(replyReactor, fun, handler, msg) {
var saved: ReplyReactor = _
protected override def beginExecution() {
saved = Actor.tl.get
- Actor.tl set reactor
+ // !!! If this is supposed to be setting the current contents of the
+ // inherited mutable var rather than always the value given in the constructor,
+ // then it should be changed to "set reactor".
+ Actor.tl set replyReactor
}
protected override def suspendExecution() {
diff --git a/src/compiler/scala/reflect/internal/Types.scala b/src/compiler/scala/reflect/internal/Types.scala
index 265261f594..d17747e22a 100644
--- a/src/compiler/scala/reflect/internal/Types.scala
+++ b/src/compiler/scala/reflect/internal/Types.scala
@@ -649,7 +649,11 @@ trait Types extends api.Types { self: SymbolTable =>
}
/** Returns all parts of this type which satisfy predicate `p` */
- def filter(p: Type => Boolean): List[Type] = new FilterTypeCollector(p).collect(this).toList
+ def filter(p: Type => Boolean): List[Type] = new FilterTypeCollector(p) collect this
+ def withFilter(p: Type => Boolean) = new FilterTypeCollector(p) {
+ def foreach[U](f: Type => U): Unit = collect(Type.this) foreach f
+ def map[T](f: Type => T): List[T] = collect(Type.this) map f
+ }
/** Returns optionally first type (in a preorder traversal) which satisfies predicate `p`,
* or None if none exists.
@@ -4094,9 +4098,13 @@ A type's typeSymbol should never be inspected directly.
}
/** A map to implement the `filter` method. */
- class FilterTypeCollector(p: Type => Boolean) extends TypeCollector(new ListBuffer[Type]) {
+ class FilterTypeCollector(p: Type => Boolean) extends TypeCollector[List[Type]](Nil) {
+ def withFilter(q: Type => Boolean) = new FilterTypeCollector(tp => p(tp) && q(tp))
+
+ override def collect(tp: Type) = super.collect(tp).reverse
+
def traverse(tp: Type) {
- if (p(tp)) result += tp
+ if (p(tp)) result ::= tp
mapOver(tp)
}
}
diff --git a/src/compiler/scala/reflect/internal/pickling/UnPickler.scala b/src/compiler/scala/reflect/internal/pickling/UnPickler.scala
index 9aa3d8a2c3..1a8540c158 100644
--- a/src/compiler/scala/reflect/internal/pickling/UnPickler.scala
+++ b/src/compiler/scala/reflect/internal/pickling/UnPickler.scala
@@ -46,7 +46,7 @@ abstract class UnPickler /*extends reflect.generic.UnPickler*/ {
}
}
- class Scan(bytes: Array[Byte], offset: Int, classRoot: Symbol, moduleRoot: Symbol, filename: String) extends PickleBuffer(bytes, offset, -1) {
+ class Scan(_bytes: Array[Byte], offset: Int, classRoot: Symbol, moduleRoot: Symbol, filename: String) extends PickleBuffer(_bytes, offset, -1) {
//println("unpickle " + classRoot + " and " + moduleRoot)//debug
protected def debug = settings.debug.value
diff --git a/src/compiler/scala/reflect/runtime/ToolBoxes.scala b/src/compiler/scala/reflect/runtime/ToolBoxes.scala
index e617239398..03947574db 100644
--- a/src/compiler/scala/reflect/runtime/ToolBoxes.scala
+++ b/src/compiler/scala/reflect/runtime/ToolBoxes.scala
@@ -42,11 +42,10 @@ trait ToolBoxes extends { self: Universe =>
def wrapInObject(expr: Tree, fvs: List[Symbol]): ModuleDef = {
val obj = EmptyPackageClass.newModule(NoPosition, nextWrapperModuleName())
- val minfo = ClassInfoType(List(ObjectClass.tpe), new Scope, obj.moduleClass)
+ val minfo = ClassInfoType(List(ObjectClass.tpe, ScalaObjectClass.tpe), new Scope, obj.moduleClass)
obj.moduleClass setInfo minfo
obj setInfo obj.moduleClass.tpe
val meth = obj.moduleClass.newMethod(NoPosition, wrapperMethodName)
- meth setFlag Flags.STATIC
def makeParam(fv: Symbol) = meth.newValueParameter(NoPosition, fv.name) setInfo fv.tpe
meth setInfo MethodType(fvs map makeParam, expr.tpe)
minfo.decls enter meth
@@ -88,11 +87,19 @@ trait ToolBoxes extends { self: Universe =>
def runExpr(expr: Tree): Any = {
val etpe = expr.tpe
val fvs = (expr filter isFree map (_.symbol)).distinct
+
+ reporter.reset()
val className = compileExpr(expr, fvs)
+ if (reporter.hasErrors) {
+ throw new Error("reflective compilation has failed")
+ }
+
if (settings.debug.value) println("generated: "+className)
val jclazz = jClass.forName(moduleFileName(className), true, classLoader)
val jmeth = jclazz.getDeclaredMethods.find(_.getName == wrapperMethodName).get
- val result = jmeth.invoke(null, fvs map (sym => sym.asInstanceOf[FreeVar].value.asInstanceOf[AnyRef]): _*)
+ val jfield = jclazz.getDeclaredFields.find(_.getName == NameTransformer.MODULE_INSTANCE_NAME).get
+ val singleton = jfield.get(null)
+ val result = jmeth.invoke(singleton, fvs map (sym => sym.asInstanceOf[FreeVar].value.asInstanceOf[AnyRef]): _*)
if (etpe.typeSymbol != FunctionClass(0)) result
else {
val applyMeth = result.getClass.getMethod("apply")
diff --git a/src/compiler/scala/tools/nsc/interactive/Global.scala b/src/compiler/scala/tools/nsc/interactive/Global.scala
index 7fea76c7b1..f900859f46 100644
--- a/src/compiler/scala/tools/nsc/interactive/Global.scala
+++ b/src/compiler/scala/tools/nsc/interactive/Global.scala
@@ -22,8 +22,8 @@ import symtab.Flags.{ACCESSOR, PARAMACCESSOR}
/** The main class of the presentation compiler in an interactive environment such as an IDE
*/
-class Global(settings: Settings, reporter: Reporter, projectName: String = "")
- extends scala.tools.nsc.Global(settings, reporter)
+class Global(settings: Settings, _reporter: Reporter, projectName: String = "")
+ extends scala.tools.nsc.Global(settings, _reporter)
with CompilerControl
with RangePositions
with ContextTrees
diff --git a/src/compiler/scala/tools/nsc/transform/CleanUp.scala b/src/compiler/scala/tools/nsc/transform/CleanUp.scala
index d001a0af8b..98345dd01e 100644
--- a/src/compiler/scala/tools/nsc/transform/CleanUp.scala
+++ b/src/compiler/scala/tools/nsc/transform/CleanUp.scala
@@ -297,7 +297,7 @@ abstract class CleanUp extends Transform with ast.TreeDSL {
case nme.toDouble => "toDouble"
case _ => return None
}
- Some(newName, runtimeTest)
+ Some((newName, runtimeTest))
}
def infixTest(name: Name): Option[(String, Tree => Tree)] = {
val (newName, runtimeTest) = name match {
@@ -322,7 +322,7 @@ abstract class CleanUp extends Transform with ast.TreeDSL {
case nme.ZAND => ("takeConditionalAnd", testForBoolean)
case _ => return None
}
- Some(newName, runtimeTest)
+ Some((newName, runtimeTest))
}
/** The Tree => Tree function in the return is necessary to prevent the original qual
diff --git a/src/compiler/scala/tools/nsc/transform/Erasure.scala b/src/compiler/scala/tools/nsc/transform/Erasure.scala
index 9806857ff2..1a421eb82f 100644
--- a/src/compiler/scala/tools/nsc/transform/Erasure.scala
+++ b/src/compiler/scala/tools/nsc/transform/Erasure.scala
@@ -421,7 +421,7 @@ abstract class Erasure extends AddInterfaces
*/
/** The modifier typer which retypes with erased types. */
- class Eraser(context: Context) extends Typer(context) {
+ class Eraser(_context: Context) extends Typer(_context) {
private def safeToRemoveUnbox(cls: Symbol): Boolean =
(cls == definitions.NullClass) || isBoxedValueClass(cls)
diff --git a/src/compiler/scala/tools/nsc/typechecker/Duplicators.scala b/src/compiler/scala/tools/nsc/typechecker/Duplicators.scala
index 031be21f24..2bed5bffd4 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Duplicators.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Duplicators.scala
@@ -69,7 +69,7 @@ abstract class Duplicators extends Analyzer {
* tree, except for TypeTrees, are erased prior to type checking. TypeTrees
* are fixed by substituting invalid symbols for the new ones.
*/
- class BodyDuplicator(context: Context) extends Typer(context: Context) {
+ class BodyDuplicator(_context: Context) extends Typer(_context) {
class FixInvalidSyms extends TypeMap {
diff --git a/src/compiler/scala/tools/nsc/typechecker/Infer.scala b/src/compiler/scala/tools/nsc/typechecker/Infer.scala
index 79db9ab000..5b38ddd092 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Infer.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Infer.scala
@@ -1311,7 +1311,11 @@ trait Infer {
case TypeRef(_, sym, _) if isLocalBinding(sym) =>
;
case _ =>
- patternWarning(arg, "non variable type-argument ")
+ // Want to warn about type arguments, not type parameters. Otherwise we'll
+ // see warnings about "invisible" types, like: val List(x0) = x1 leading to "non
+ // variable type-argument A in type pattern List[A]..."
+ if (!arg.typeSymbol.isTypeParameterOrSkolem)
+ patternWarning(arg, "non variable type-argument ")
}
}
}
diff --git a/src/compiler/scala/tools/nsc/typechecker/Namers.scala b/src/compiler/scala/tools/nsc/typechecker/Namers.scala
index 0f57285480..364e887939 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Namers.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Namers.scala
@@ -422,7 +422,7 @@ trait Namers extends MethodSynthesis {
* @return the companion object symbol.
*/
def ensureCompanionObject(cdef: ClassDef, creator: ClassDef => Tree = companionModuleDef(_)): Symbol = {
- val m = companionModuleOf(cdef.symbol, context)
+ val m = companionSymbolOf(cdef.symbol, context)
// @luc: not sure why "currentRun.compiles(m)" is needed, things breaks
// otherwise. documentation welcome.
//
@@ -855,7 +855,7 @@ trait Namers extends MethodSynthesis {
// @check: this seems to work only if the type completer of the class runs before the one of the
// module class: the one from the module class removes the entry from classOfModuleClass (see above).
if (clazz.isClass && !clazz.hasModuleFlag) {
- val modClass = companionModuleOf(clazz, context).moduleClass
+ val modClass = companionSymbolOf(clazz, context).moduleClass
Namers.this.classOfModuleClass get modClass map { cdefRef =>
val cdef = cdefRef()
@@ -1082,7 +1082,7 @@ trait Namers extends MethodSynthesis {
val parentNamer = if (isConstr) {
val (cdef, nmr) = moduleNamer.getOrElse {
- val module = companionModuleOf(clazz, context)
+ val module = companionSymbolOf(clazz, context)
module.initialize // call type completer (typedTemplate), adds the
// module's templateNamer to classAndNamerOfModule
classAndNamerOfModule get module match {
diff --git a/src/compiler/scala/tools/nsc/typechecker/NamesDefaults.scala b/src/compiler/scala/tools/nsc/typechecker/NamesDefaults.scala
index e4ebe13217..8611fafe52 100644
--- a/src/compiler/scala/tools/nsc/typechecker/NamesDefaults.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/NamesDefaults.scala
@@ -189,7 +189,7 @@ trait NamesDefaults { self: Analyzer =>
if (pre == NoType) {
None
} else {
- val module = companionModuleOf(baseFun.symbol.owner, context)
+ val module = companionSymbolOf(baseFun.symbol.owner, context)
if (module == NoSymbol) None
else {
val ref = atPos(pos.focus)(gen.mkAttributedRef(pre, module))
@@ -414,7 +414,7 @@ trait NamesDefaults { self: Analyzer =>
if (i > 0) {
val defGetterName = nme.defaultGetterName(param.owner.name, i)
if (param.owner.isConstructor) {
- val mod = companionModuleOf(param.owner.owner, context)
+ val mod = companionSymbolOf(param.owner.owner, context)
mod.info.member(defGetterName)
}
else {
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
index 7671ccbed7..9b03d59216 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
@@ -1361,7 +1361,7 @@ trait Typers extends Modes with Adaptations with PatMatVirtualiser {
"you want, you must write the annotation class in Java.")
if (!isPastTyper) {
for (ann <- clazz.getAnnotation(DeprecatedAttr)) {
- val m = companionModuleOf(clazz, context)
+ val m = companionSymbolOf(clazz, context)
if (m != NoSymbol)
m.moduleClass.addAnnotation(AnnotationInfo(ann.atp, ann.args, List()))
}
@@ -1377,7 +1377,7 @@ trait Typers extends Modes with Adaptations with PatMatVirtualiser {
def typedModuleDef(mdef: ModuleDef): Tree = {
// initialize all constructors of the linked class: the type completer (Namer.methodSig)
// might add default getters to this object. example: "object T; class T(x: Int = 1)"
- val linkedClass = companionClassOf(mdef.symbol, context)
+ val linkedClass = companionSymbolOf(mdef.symbol, context)
if (linkedClass != NoSymbol)
linkedClass.info.decl(nme.CONSTRUCTOR).alternatives foreach (_.initialize)
@@ -2223,7 +2223,7 @@ trait Typers extends Modes with Adaptations with PatMatVirtualiser {
(methCtx != NoContext) && {
val contextFun = methCtx.tree.symbol
contextFun.isPrimaryConstructor && contextFun.owner.isModuleClass &&
- companionModuleOf(calledFun.owner, context).moduleClass == contextFun.owner
+ companionSymbolOf(calledFun.owner, context).moduleClass == contextFun.owner
}
}
}
diff --git a/src/compiler/scala/tools/util/EditDistance.scala b/src/compiler/scala/tools/util/EditDistance.scala
index a8d7408532..b705a1eac4 100644
--- a/src/compiler/scala/tools/util/EditDistance.scala
+++ b/src/compiler/scala/tools/util/EditDistance.scala
@@ -33,7 +33,7 @@ object EditDistance {
0 to n foreach (x => d(x)(0) = x)
0 to m foreach (x => d(0)(x) = x)
- for (i <- 1 to n ; val s_i = s(i - 1) ; j <- 1 to m) {
+ for (i <- 1 to n ; s_i = s(i - 1) ; j <- 1 to m) {
val t_j = t(j - 1)
val cost = if (s_i == t_j) 0 else 1
diff --git a/src/library/scala/Either.scala b/src/library/scala/Either.scala
index bc75f0f088..e454cdf5ec 100644
--- a/src/library/scala/Either.scala
+++ b/src/library/scala/Either.scala
@@ -575,15 +575,15 @@ object Either {
}
}
- /** If the condition is satisfied, return the given `A` in `Left`,
- * otherwise, return the given `B` in `Right`.
+ /** If the condition is satisfied, return the given `B` in `Right`,
+ * otherwise, return the given `A` in `Left`.
*
* {{{
* val userInput: String = ...
* Either.cond(
* userInput.forall(_.isDigit) && userInput.size == 10,
- * "The input (%s) does not look like a phone number".format(userInput),
- * PhoneNumber(userInput)
+ * PhoneNumber(userInput),
+ * "The input (%s) does not look like a phone number".format(userInput)
* }}}
*/
def cond[A, B](test: Boolean, right: => B, left: => A): Either[A, B] =
diff --git a/src/library/scala/Enumeration.scala b/src/library/scala/Enumeration.scala
index c967a48abc..3d85f2f52f 100644
--- a/src/library/scala/Enumeration.scala
+++ b/src/library/scala/Enumeration.scala
@@ -48,19 +48,20 @@ import java.util.regex.Pattern
*
* @param initial The initial value from which to count the integers that
* identifies values at run-time.
- * @param names The sequence of names to give to this enumeration's values.
- *
* @author Matthias Zenger
*/
@SerialVersionUID(8476000850333817230L)
-abstract class Enumeration(initial: Int,
- @deprecated("Names should be specified individually or discovered via reflection", "2.10")
- names: String*) extends Serializable {
+abstract class Enumeration (initial: Int) extends Serializable {
thisenum =>
def this() = this(0)
-
- @deprecated("Names should be specified individually or discovered via reflection", "2.10")
+
+ @deprecated("Names should be specified individually or discovered via reflection", "2.10.0")
+ def this(initial: Int, names: String*) = {
+ this(initial)
+ this.nextName = names.iterator
+ }
+ @deprecated("Names should be specified individually or discovered via reflection", "2.10.0")
def this(names: String*) = this(0, names: _*)
/* Note that `readResolve` cannot be private, since otherwise
@@ -97,12 +98,13 @@ abstract class Enumeration(initial: Int,
}
/** The integer to use to identify the next created value. */
- protected var nextId = initial
+ protected var nextId: Int = initial
/** The string to use to name the next created value. */
- protected var nextName = names.iterator
+ protected var nextName: Iterator[String] = _
+
private def nextNameOrNull =
- if (nextName.hasNext) nextName.next else null
+ if (nextName != null && nextName.hasNext) nextName.next else null
/** The highest integer amongst those used to identify values in this
* enumeration. */
@@ -120,17 +122,8 @@ abstract class Enumeration(initial: Int,
*/
final def apply(x: Int): Value = vmap(x)
- /**
- * Return a `Value` from this `Enumeration` whose name matches
- * the argument `s`.
- *
- * You can pass a String* set of names to the constructor, or initialize
- * each `Enumeration` with `Value(String)`. Otherwise, the names are
- * determined automatically through reflection.
- *
- * Note the change here wrt 2.7 is intentional. You should know whether
- * a name is in an `Enumeration` beforehand. If not, just use find on
- * values.
+ /** Return a `Value` from this `Enumeration` whose name matches
+ * the argument `s`. The names are determined automatically via reflection.
*
* @param s an `Enumeration` name
* @return the `Value` of this `Enumeration` if its name matches `s`