diff options
-rw-r--r-- | sources/scala/collection/Map.scala | 22 | ||||
-rw-r--r-- | sources/scala/collection/Set.scala | 24 | ||||
-rw-r--r-- | sources/scala/tools/nsc/Settings.scala | 1 | ||||
-rwxr-xr-x | sources/scala/tools/nsc/symtab/StdNames.scala | 2 | ||||
-rwxr-xr-x | sources/scala/tools/nsc/symtab/Symbols.scala | 42 | ||||
-rwxr-xr-x | sources/scala/tools/nsc/symtab/classfile/ClassfileParser.scala | 1 | ||||
-rwxr-xr-x | sources/scala/tools/nsc/symtab/classfile/UnPickler.scala | 2 | ||||
-rwxr-xr-x | sources/scala/tools/nsc/transform/Mixin.scala | 27 | ||||
-rwxr-xr-x | sources/scala/tools/nsc/transform/UnCurry.scala | 13 | ||||
-rwxr-xr-x | test-nsc/files/pos/expressions-current.scala | 5 | ||||
-rwxr-xr-x | test-nsc/files/pos/traits.scala | 3 |
11 files changed, 66 insertions, 76 deletions
diff --git a/sources/scala/collection/Map.scala b/sources/scala/collection/Map.scala index 1ee5869224..14546e9e71 100644 --- a/sources/scala/collection/Map.scala +++ b/sources/scala/collection/Map.scala @@ -136,18 +136,16 @@ trait Map[A, +B] extends AnyRef with PartialFunction[A, B] with Iterable[Pair[A, * * @return true, iff both maps contain exactly the same mappings. */ - override def equals(that: Any): Boolean = ( - that.isInstanceOf[Map[A, B]] && - { val other = that.asInstanceOf[Map[A, B]]; - (this.size == other.size && - this.elements.forall { - case Pair(key, value) => other.get(key) match { - case None => false; - case Some(otherval) => value == otherval; - } - }) - } - ); + override def equals(that: Any): Boolean = that match { + case other: Map[A, B] => + this.size == other.size && this.elements.forall { + case Pair(key, value) => other.get(key) match { + case None => false; + case Some(otherval) => value == otherval; + } + } + case _ => false + } /** Returns the mappings of this map as a list. * diff --git a/sources/scala/collection/Set.scala b/sources/scala/collection/Set.scala index 4251d2fa0f..00ac17f6df 100644 --- a/sources/scala/collection/Set.scala +++ b/sources/scala/collection/Set.scala @@ -67,12 +67,12 @@ trait Set[A] extends AnyRef with Function1[A, Boolean] with Iterable[A] { * @return true, iff this set and the other set contain the same * elements. */ - override def equals(that: Any): Boolean = ( - that.isInstanceOf[Set[A]] && - { val other = that.asInstanceOf[Set[A]]; - (this.size == other.size && - this.elements.forall(other.contains)) } - ); + override def equals(that: Any): Boolean = that match { + case other: Set[A] => + this.size == other.size && this.elements.forall(other.contains) + case _ => + false + } /** Returns the elements of this set as a list. * @@ -85,15 +85,5 @@ trait Set[A] extends AnyRef with Function1[A, Boolean] with Iterable[A] { * @return a string showing all elements of this set. */ override def toString(): String = - if (size == 0) - "{}" - else - "{" + { - val iter = elements; - var res = iter.next.toString(); - while (iter.hasNext) { - res = res + ", " + iter.next; - } - res; - } + "}"; + if (size == 0) "{}" else elements.toList.mkString("{", ", ", "}"); } diff --git a/sources/scala/tools/nsc/Settings.scala b/sources/scala/tools/nsc/Settings.scala index 6e80f5f66a..a7a5dfe73c 100644 --- a/sources/scala/tools/nsc/Settings.scala +++ b/sources/scala/tools/nsc/Settings.scala @@ -11,6 +11,7 @@ class Settings(error: String => unit) { val debuginfo = BooleanSetting("-g", "Generate debugging info"); val nowarnings = BooleanSetting("-nowarn", "Generate no warnings"); + val noassertions = BooleanSetting("-noassert", "Generate no assertions and assumptions"); val verbose = BooleanSetting("-verbose", "Output messages about what the compiler is doing"); val classpath = StringSetting ("-classpath", "path", "Specify where to find user class files", System.getProperty("scala.class.path", diff --git a/sources/scala/tools/nsc/symtab/StdNames.scala b/sources/scala/tools/nsc/symtab/StdNames.scala index 1ecfa8bec8..2b8b8692f5 100755 --- a/sources/scala/tools/nsc/symtab/StdNames.scala +++ b/sources/scala/tools/nsc/symtab/StdNames.scala @@ -213,6 +213,8 @@ import scala.tools.nsc.util.NameTransformer; val While = newTermName("While"); val apply = newTermName("apply"); val array = newTermName("array"); + val assert_ = newTermName("assert"); + val assume_ = newTermName("assume"); val asInstanceOf = newTermName("asInstanceOf"); val asInstanceOfErased = newTermName("asInstanceOf$erased"); val box = newTermName("box"); diff --git a/sources/scala/tools/nsc/symtab/Symbols.scala b/sources/scala/tools/nsc/symtab/Symbols.scala index 80b7bf3a6d..7dc213164f 100755 --- a/sources/scala/tools/nsc/symtab/Symbols.scala +++ b/sources/scala/tools/nsc/symtab/Symbols.scala @@ -365,28 +365,28 @@ import Flags._; /** Return info without checking for initialization or completing */ final def rawInfo: Type = { if (limit < phase.id) { - if (validForRun == currentRun) { - val current = phase; - var itr = infoTransformers.nextFrom(limit); - infoTransformers = itr; // caching optimization - while (itr.pid != NoPhase.id && itr.pid < current.id) { - phase = phaseWithId(itr.pid); - val info1 = itr.transform(this, infos.info); - limit = phase.id + 1; - if (info1 ne infos.info) { - infos = new TypeHistory(limit, info1, infos); - } - itr = itr.nextFrom(limit) - } - phase = current; - limit = current.id; - } - assert(infos != null, name); - infos.info + if (validForRun == currentRun) { + val current = phase; + var itr = infoTransformers.nextFrom(limit); + infoTransformers = itr; // caching optimization + while (itr.pid != NoPhase.id && itr.pid < current.id) { + phase = phaseWithId(itr.pid); + val info1 = itr.transform(this, infos.info); + limit = phase.id + 1; + if (info1 ne infos.info) { + infos = new TypeHistory(limit, info1, infos); + } + itr = itr.nextFrom(limit) + } + phase = current; + limit = current.id; + } + assert(infos != null, name); + infos.info } else { - var infos = this.infos; - while (phase.id < infos.start && infos.prev != null) infos = infos.prev; - infos.info + var infos = this.infos; + while (phase.id < infos.start && infos.prev != null) infos = infos.prev; + infos.info } } diff --git a/sources/scala/tools/nsc/symtab/classfile/ClassfileParser.scala b/sources/scala/tools/nsc/symtab/classfile/ClassfileParser.scala index e7585e933e..0e56cf8824 100755 --- a/sources/scala/tools/nsc/symtab/classfile/ClassfileParser.scala +++ b/sources/scala/tools/nsc/symtab/classfile/ClassfileParser.scala @@ -325,7 +325,6 @@ abstract class ClassfileParser { case nme.ConstantValueATTR => val c = pool.getConstant(in.nextChar()); val c1 = c convertTo symtype; - assert(c1 != null, "cannot convert " + c + " to " + symtype); sym.setInfo(ConstantType(c1)); case nme.InnerClassesATTR => parseInnerClasses() diff --git a/sources/scala/tools/nsc/symtab/classfile/UnPickler.scala b/sources/scala/tools/nsc/symtab/classfile/UnPickler.scala index 40ed7cc255..70c50e592b 100755 --- a/sources/scala/tools/nsc/symtab/classfile/UnPickler.scala +++ b/sources/scala/tools/nsc/symtab/classfile/UnPickler.scala @@ -67,7 +67,7 @@ abstract class UnPickler { private def isRefinementSymbolEntry(i: int): boolean = { val savedIndex = readIndex; readIndex = index(i); - assert(readByte() == CLASSsym); + if (readByte() != CLASSsym) assert(false); readNat(); val result = readNameRef() == nme.REFINE_CLASS_NAME.toTypeName; readIndex = savedIndex; diff --git a/sources/scala/tools/nsc/transform/Mixin.scala b/sources/scala/tools/nsc/transform/Mixin.scala index 32c325a61f..d20deb8b85 100755 --- a/sources/scala/tools/nsc/transform/Mixin.scala +++ b/sources/scala/tools/nsc/transform/Mixin.scala @@ -335,6 +335,9 @@ abstract class Mixin extends InfoTransform { val parents1 = currentOwner.info.parents map (t => TypeTree(t) setPos tree.pos); val body1 = addNewDefs(currentOwner, body); copy.Template(tree, parents1, body1) + case Apply(TypeApply(sel @ Select(qual, name), List(targ)), List()) + if (tree.symbol == Object_asInstanceOf && (qual.tpe <:< targ.tpe)) => + qual case Apply(Select(qual, _), args) => def staticCall(target: Symbol) = { if (target == NoSymbol) @@ -371,26 +374,18 @@ abstract class Mixin extends InfoTransform { } case This(_) if tree.symbol.isImplClass => - assert(tree.symbol == currentOwner.enclClass, "" + tree + " " + tree.symbol + " " + currentOwner.enclClass); + assert(tree.symbol == currentOwner.enclClass); selfRef(tree.pos) case Select(Super(_, _), name) => tree case Select(qual, name) if sym.owner.isImplClass && !isStatic(sym) => - if (sym.isMethod) { - assert(false, sym);//!!! - assert(sym hasFlag (LIFTED | BRIDGE), sym); - val sym1 = toInterface(qual.tpe).member(sym.name); - assert(sym1 != NoSymbol, sym);//debug - assert(!(sym1 hasFlag OVERLOADED), sym);//debug - tree setSymbol sym1 - } else { - val getter = sym.getter(enclInterface); - assert(getter != NoSymbol); - localTyper.typed { - atPos(tree.pos) { - Apply(Select(qual, getter), List()) - } - } + assert(!sym.isMethod, sym); + val getter = sym.getter(enclInterface); + assert(getter != NoSymbol); + localTyper.typed { + atPos(tree.pos) { + Apply(Select(qual, getter), List()) + } } case Assign(Apply(lhs @ Select(qual, _), List()), rhs) => localTyper.typed { diff --git a/sources/scala/tools/nsc/transform/UnCurry.scala b/sources/scala/tools/nsc/transform/UnCurry.scala index 941b5df414..dfa8252a73 100755 --- a/sources/scala/tools/nsc/transform/UnCurry.scala +++ b/sources/scala/tools/nsc/transform/UnCurry.scala @@ -253,9 +253,16 @@ abstract class UnCurry extends InfoTransform { } case Apply(fn, args) => - withNeedLift(true) { - val formals = fn.tpe.paramTypes; - copy.Apply(tree, transform(fn), transformTrees(transformArgs(tree.pos, args, formals))) + if (settings.noassertions.value && + fn.symbol != null && + (fn.symbol.name == nme.assert_ || fn.symbol.name == nme.assume_) && + fn.symbol.owner == PredefModule.moduleClass) { + Literal(()).setPos(tree.pos).setType(UnitClass.tpe) + } else { + withNeedLift(true) { + val formals = fn.tpe.paramTypes; + copy.Apply(tree, transform(fn), transformTrees(transformArgs(tree.pos, args, formals))) + } } case Assign(Select(_, _), _) => diff --git a/test-nsc/files/pos/expressions-current.scala b/test-nsc/files/pos/expressions-current.scala index f3def81931..b343dbf68b 100755 --- a/test-nsc/files/pos/expressions-current.scala +++ b/test-nsc/files/pos/expressions-current.scala @@ -39,10 +39,9 @@ abstract class Lang2 extends Lang { class Show2(result: Ref[String]): visitor extends Visitor2 { def caseNum(n: int) = result.elem = n.toString(); def casePlus(l: Exp, r: Exp) = - result.elem = ( + result.elem = "(" + { l.visit(this); result.elem } + - "+" + { r.visit(this); result.elem }+ ")" - ) + "+" + { r.visit(this); result.elem }+ ")"; } } diff --git a/test-nsc/files/pos/traits.scala b/test-nsc/files/pos/traits.scala index 605395c5a6..5fdf4b342e 100755 --- a/test-nsc/files/pos/traits.scala +++ b/test-nsc/files/pos/traits.scala @@ -19,11 +19,10 @@ object Test { } trait BorderedColoredShape extends Shape with Bordered with Colored { override def equals(other: Any) = other match { - case that: BorderedColoredShape => ( + case that: BorderedColoredShape => super.equals(that) && super[Bordered].equals(that) && super[Colored].equals(that) - ) case _ => false } } |