summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/NamesDefaults.scala9
-rw-r--r--src/interactive/scala/tools/nsc/interactive/ContextTrees.scala64
-rw-r--r--src/interactive/scala/tools/nsc/interactive/tests/InteractiveTest.scala2
-rw-r--r--src/interactive/scala/tools/nsc/interactive/tests/core/AskCommand.scala19
-rw-r--r--src/interactive/scala/tools/nsc/interactive/tests/core/CoreTestDefs.scala46
-rw-r--r--src/interactive/scala/tools/nsc/interactive/tests/core/TestMarker.scala4
-rw-r--r--src/library/scala/collection/immutable/IntMap.scala2
-rw-r--r--src/library/scala/collection/immutable/LongMap.scala2
-rw-r--r--src/library/scala/collection/mutable/AnyRefMap.scala451
-rw-r--r--src/library/scala/collection/mutable/LongMap.scala558
-rw-r--r--test/files/pos/t1014.scala16
-rw-r--r--test/files/pos/t1203a.scala13
-rw-r--r--test/files/pos/t2698.scala14
-rw-r--r--test/files/pos/t3160.scala6
-rw-r--r--test/files/pos/t6201.scala19
-rw-r--r--test/files/presentation/callcc-interpreter.check2
-rw-r--r--test/files/presentation/completion-implicit-chained.check2
-rw-r--r--test/files/presentation/ide-bug-1000349.check2
-rw-r--r--test/files/presentation/ide-bug-1000475.check6
-rw-r--r--test/files/presentation/ide-bug-1000531.check2
-rw-r--r--test/files/presentation/implicit-member.check2
-rw-r--r--test/files/presentation/ping-pong.check4
-rw-r--r--test/files/presentation/scope-completion-1.check19
-rw-r--r--test/files/presentation/scope-completion-1/Test.scala3
-rw-r--r--test/files/presentation/scope-completion-1/src/Completions.scala12
-rw-r--r--test/files/presentation/scope-completion-2.check35
-rw-r--r--test/files/presentation/scope-completion-2/Test.scala3
-rw-r--r--test/files/presentation/scope-completion-2/src/Completions.scala35
-rw-r--r--test/files/presentation/scope-completion-3.check111
-rw-r--r--test/files/presentation/scope-completion-3/Test.scala3
-rw-r--r--test/files/presentation/scope-completion-3/src/Completions.scala106
-rw-r--r--test/files/presentation/scope-completion-4.check293
-rw-r--r--test/files/presentation/scope-completion-4/Test.scala3
-rw-r--r--test/files/presentation/scope-completion-4/src/Completions.scala84
-rw-r--r--test/files/presentation/scope-completion-import.check141
-rw-r--r--test/files/presentation/scope-completion-import/Test.scala3
-rw-r--r--test/files/presentation/scope-completion-import/src/Completions.scala64
-rw-r--r--test/files/presentation/t1207.check12
-rw-r--r--test/files/presentation/t5708.check2
-rw-r--r--test/files/presentation/t7915.check11
-rw-r--r--test/files/presentation/t7915/Test.scala8
-rw-r--r--test/files/presentation/t7915/src/Foo.scala9
-rw-r--r--test/files/presentation/visibility.check10
-rw-r--r--test/files/run/fors.check28
-rw-r--r--test/files/run/fors.scala84
-rw-r--r--test/files/run/mutable-anyrefmap.scala91
-rw-r--r--test/files/run/mutable-longmap.scala79
-rw-r--r--test/files/run/repl-backticks.check2
-rw-r--r--test/files/run/repl-backticks.scala18
-rw-r--r--test/files/run/t1500.check3
-rw-r--r--test/files/run/t1500.scala46
-rw-r--r--test/files/run/t1501.check3
-rw-r--r--test/files/run/t1501.scala56
-rw-r--r--test/files/run/t4124.check4
-rw-r--r--test/files/run/t4124.scala24
55 files changed, 2588 insertions, 62 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/NamesDefaults.scala b/src/compiler/scala/tools/nsc/typechecker/NamesDefaults.scala
index 03aad71165..46ff98875f 100644
--- a/src/compiler/scala/tools/nsc/typechecker/NamesDefaults.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/NamesDefaults.scala
@@ -162,7 +162,7 @@ trait NamesDefaults { self: Analyzer =>
// never used for constructor calls, they always have a stable qualifier
def blockWithQualifier(qual: Tree, selected: Name) = {
- val sym = blockTyper.context.owner.newValue(unit.freshTermName("qual$"), qual.pos, newFlags = ARTIFACT) setInfo uncheckedBounds(qual.tpe)
+ val sym = blockTyper.context.owner.newValue(unit.freshTermName("qual$"), newFlags = ARTIFACT) setInfo uncheckedBounds(qual.tpe) setPos (qual.pos.makeTransparent)
blockTyper.context.scope enter sym
val vd = atPos(sym.pos)(ValDef(sym, qual) setType NoType)
// it stays in Vegas: SI-5720, SI-5727
@@ -173,13 +173,16 @@ trait NamesDefaults { self: Analyzer =>
// setSymbol below is important because the 'selected' function might be overloaded. by
// assigning the correct method symbol, typedSelect will just assign the type. the reason
// to still call 'typed' is to correctly infer singleton types, SI-5259.
- val f = blockTyper.typedOperator(Select(newQual, selected).setSymbol(baseFun1.symbol))
+ val selectPos =
+ if(qual.pos.isRange && baseFun.pos.isRange) qual.pos.union(baseFun.pos).withStart(Math.min(qual.pos.end, baseFun.pos.end))
+ else baseFun.pos
+ val f = blockTyper.typedOperator(Select(newQual, selected).setSymbol(baseFun1.symbol).setPos(selectPos))
if (funTargs.isEmpty) f
else TypeApply(f, funTargs).setType(baseFun.tpe)
}
val b = Block(List(vd), baseFunTransformed)
- .setType(baseFunTransformed.tpe).setPos(baseFun.pos)
+ .setType(baseFunTransformed.tpe).setPos(baseFun.pos.makeTransparent)
context.namedApplyBlockInfo =
Some((b, NamedApplyInfo(Some(newQual), defaultTargs, Nil, blockTyper)))
b
diff --git a/src/interactive/scala/tools/nsc/interactive/ContextTrees.scala b/src/interactive/scala/tools/nsc/interactive/ContextTrees.scala
index 93ef4c4d6c..4f67a22b8f 100644
--- a/src/interactive/scala/tools/nsc/interactive/ContextTrees.scala
+++ b/src/interactive/scala/tools/nsc/interactive/ContextTrees.scala
@@ -6,6 +6,7 @@ package scala.tools.nsc
package interactive
import scala.collection.mutable.ArrayBuffer
+import scala.annotation.tailrec
trait ContextTrees { self: Global =>
@@ -28,44 +29,59 @@ trait ContextTrees { self: Global =>
override def toString = "ContextTree("+pos+", "+children+")"
}
- /** Optionally returns the smallest context that contains given `pos`, or None if none exists.
+ /** Returns the most precise context possible for the given `pos`.
+ *
+ * It looks for the finest ContextTree containing `pos`, and then look inside
+ * this ContextTree for a child ContextTree located immediately before `pos`.
+ * If such a child exists, returns its context, otherwise returns the context of
+ * the parent ContextTree.
+ *
+ * This is required to always return a context which contains the all the imports
+ * declared up to `pos` (see SI-7280 for a test case).
+ *
+ * Can return None if `pos` is before any valid Scala code.
*/
def locateContext(contexts: Contexts, pos: Position): Option[Context] = synchronized {
- def locateNearestContextTree(contexts: Contexts, pos: Position, recent: Array[ContextTree]): Option[ContextTree] = {
- locateContextTree(contexts, pos) match {
- case Some(x) =>
- recent(0) = x
- locateNearestContextTree(x.children, pos, recent)
- case None => recent(0) match {
- case null => None
- case x => Some(x)
- }
+ @tailrec
+ def locateFinestContextTree(context: ContextTree): ContextTree = {
+ if (context.pos includes pos) {
+ locateContextTree(context.children, pos) match {
+ case Some(x) =>
+ locateFinestContextTree(x)
+ case None =>
+ context
+ }
+ } else {
+ context
}
}
- locateNearestContextTree(contexts, pos, new Array[ContextTree](1)) map (_.context)
+ locateContextTree(contexts, pos) map locateFinestContextTree map (_.context)
}
+ /** Returns the ContextTree containing `pos`, or the ContextTree positioned just before `pos`,
+ * or None if `pos` is located before all ContextTrees.
+ */
def locateContextTree(contexts: Contexts, pos: Position): Option[ContextTree] = {
if (contexts.isEmpty) None
else {
- val hi = contexts.length - 1
- if ((contexts(hi).pos properlyPrecedes pos) || (pos properlyPrecedes contexts(0).pos)) None
- else {
- def loop(lo: Int, hi: Int): Option[ContextTree] = {
+ @tailrec
+ def loop(lo: Int, hi: Int, previousSibling: Option[ContextTree]): Option[ContextTree] = {
+ if (pos properlyPrecedes contexts(lo).pos)
+ previousSibling
+ else if (contexts(hi).pos properlyPrecedes pos)
+ Some(contexts(hi))
+ else {
val mid = (lo + hi) / 2
val midpos = contexts(mid).pos
- if ((pos precedes midpos) && (mid < hi))
- loop(lo, mid)
- else if ((midpos precedes pos) && (lo < mid))
- loop(mid, hi)
- else if (midpos includes pos)
+ if (midpos includes pos)
Some(contexts(mid))
- else if (contexts(mid+1).pos includes pos)
- Some(contexts(mid+1))
- else None
+ else if (midpos properlyPrecedes pos)
+ loop(mid + 1, hi, Some(contexts(mid)))
+ else
+ loop(lo, mid, previousSibling)
}
- loop(0, hi)
}
+ loop(0, contexts.length - 1, None)
}
}
diff --git a/src/interactive/scala/tools/nsc/interactive/tests/InteractiveTest.scala b/src/interactive/scala/tools/nsc/interactive/tests/InteractiveTest.scala
index f30d896fb7..2cb4f5fd4a 100644
--- a/src/interactive/scala/tools/nsc/interactive/tests/InteractiveTest.scala
+++ b/src/interactive/scala/tools/nsc/interactive/tests/InteractiveTest.scala
@@ -61,7 +61,7 @@ abstract class InteractiveTest
* Override this member if you need to change the default set of executed test actions.
*/
protected lazy val testActions: ListBuffer[PresentationCompilerTestDef] = {
- ListBuffer(new CompletionAction(compiler), new TypeAction(compiler), new HyperlinkAction(compiler))
+ ListBuffer(new TypeCompletionAction(compiler), new ScopeCompletionAction(compiler), new TypeAction(compiler), new HyperlinkAction(compiler))
}
/** Add new presentation compiler actions to test. Presentation compiler's test
diff --git a/src/interactive/scala/tools/nsc/interactive/tests/core/AskCommand.scala b/src/interactive/scala/tools/nsc/interactive/tests/core/AskCommand.scala
index 8d446cbbf8..4f9df6808f 100644
--- a/src/interactive/scala/tools/nsc/interactive/tests/core/AskCommand.scala
+++ b/src/interactive/scala/tools/nsc/interactive/tests/core/AskCommand.scala
@@ -42,7 +42,7 @@ trait AskParse extends AskCommand {
import compiler.Tree
/** `sources` need to be entirely parsed before running the test
- * (else commands such as `AskCompletionAt` may fail simply because
+ * (else commands such as `AskTypeCompletionAt` may fail simply because
* the source's AST is not yet loaded).
*/
def askParse(sources: Seq[SourceFile]) {
@@ -72,10 +72,10 @@ trait AskReload extends AskCommand {
}
/** Ask the presentation compiler for completion at a given position. */
-trait AskCompletionAt extends AskCommand {
+trait AskTypeCompletionAt extends AskCommand {
import compiler.Member
- private[tests] def askCompletionAt(pos: Position)(implicit reporter: Reporter): Response[List[Member]] = {
+ private[tests] def askTypeCompletionAt(pos: Position)(implicit reporter: Reporter): Response[List[Member]] = {
reporter.println("\naskTypeCompletion at " + pos.source.file.name + ((pos.line, pos.column)))
ask {
@@ -84,6 +84,19 @@ trait AskCompletionAt extends AskCommand {
}
}
+/** Ask the presentation compiler for scope completion at a given position. */
+trait AskScopeCompletionAt extends AskCommand {
+ import compiler.Member
+
+ private[tests] def askScopeCompletionAt(pos: Position)(implicit reporter: Reporter): Response[List[Member]] = {
+ reporter.println("\naskScopeCompletion at " + pos.source.file.name + ((pos.line, pos.column)))
+
+ ask {
+ compiler.askScopeCompletion(pos, _)
+ }
+ }
+}
+
/** Ask the presentation compiler for type info at a given position. */
trait AskTypeAt extends AskCommand {
import compiler.Tree
diff --git a/src/interactive/scala/tools/nsc/interactive/tests/core/CoreTestDefs.scala b/src/interactive/scala/tools/nsc/interactive/tests/core/CoreTestDefs.scala
index e28bf20745..451cf70bc2 100644
--- a/src/interactive/scala/tools/nsc/interactive/tests/core/CoreTestDefs.scala
+++ b/src/interactive/scala/tools/nsc/interactive/tests/core/CoreTestDefs.scala
@@ -12,16 +12,16 @@ private[tests] trait CoreTestDefs
/** Ask the presentation compiler for completion at all locations
* (in all sources) where the defined `marker` is found. */
- class CompletionAction(override val compiler: Global)
+ class TypeCompletionAction(override val compiler: Global)
extends PresentationCompilerTestDef
- with AskCompletionAt {
+ with AskTypeCompletionAt {
override def runTest() {
- askAllSources(CompletionMarker) { pos =>
- askCompletionAt(pos)
+ askAllSources(TypeCompletionMarker) { pos =>
+ askTypeCompletionAt(pos)
} { (pos, members) =>
withResponseDelimiter {
- reporter.println("[response] askCompletionAt " + format(pos))
+ reporter.println("[response] askTypeCompletion at " + format(pos))
// we skip getClass because it changed signature between 1.5 and 1.6, so there is no
// universal check file that we can provide for this to work
reporter.println("retrieved %d members".format(members.size))
@@ -34,6 +34,40 @@ private[tests] trait CoreTestDefs
}
}
+ /** Ask the presentation compiler for completion at all locations
+ * (in all sources) where the defined `marker` is found. */
+ class ScopeCompletionAction(override val compiler: Global)
+ extends PresentationCompilerTestDef
+ with AskScopeCompletionAt {
+
+ def memberPrinter(member: compiler.Member): String =
+ "[accessible: %5s] ".format(member.accessible) + "`" + (member.sym.toString() + member.tpe.toString()).trim() + "`"
+
+ override def runTest() {
+ askAllSources(ScopeCompletionMarker) { pos =>
+ askScopeCompletionAt(pos)
+ } { (pos, members) =>
+ withResponseDelimiter {
+ reporter.println("[response] askScopeCompletion at " + format(pos))
+ try {
+ // exclude members not from source (don't have position), for more focused and self contained tests.
+ def eligible(sym: compiler.Symbol) = sym.pos != compiler.NoPosition
+ val filtered = members.filter(member => eligible(member.sym))
+
+ reporter.println("retrieved %d members".format(filtered.size))
+ compiler ask { () =>
+ reporter.println(filtered.map(_.forceInfoString).sorted mkString "\n")
+ }
+ } catch {
+ case t: Throwable =>
+ t.printStackTrace()
+ }
+
+ }
+ }
+ }
+ }
+
/** Ask the presentation compiler for type info at all locations
* (in all sources) where the defined `marker` is found. */
class TypeAction(override val compiler: Global)
@@ -57,7 +91,7 @@ private[tests] trait CoreTestDefs
class HyperlinkAction(override val compiler: Global)
extends PresentationCompilerTestDef
with AskTypeAt
- with AskCompletionAt {
+ with AskTypeCompletionAt {
override def runTest() {
askAllSources(HyperlinkMarker) { pos =>
diff --git a/src/interactive/scala/tools/nsc/interactive/tests/core/TestMarker.scala b/src/interactive/scala/tools/nsc/interactive/tests/core/TestMarker.scala
index a5c228a549..3f9b40277c 100644
--- a/src/interactive/scala/tools/nsc/interactive/tests/core/TestMarker.scala
+++ b/src/interactive/scala/tools/nsc/interactive/tests/core/TestMarker.scala
@@ -20,7 +20,9 @@ abstract case class TestMarker(marker: String) {
TestMarker.checkForDuplicate(this)
}
-object CompletionMarker extends TestMarker("/*!*/")
+object TypeCompletionMarker extends TestMarker("/*!*/")
+
+object ScopeCompletionMarker extends TestMarker("/*_*/")
object TypeMarker extends TestMarker("/*?*/")
diff --git a/src/library/scala/collection/immutable/IntMap.scala b/src/library/scala/collection/immutable/IntMap.scala
index 07e2ddaae2..8991d0b75a 100644
--- a/src/library/scala/collection/immutable/IntMap.scala
+++ b/src/library/scala/collection/immutable/IntMap.scala
@@ -213,7 +213,7 @@ sealed abstract class IntMap[+T] extends AbstractMap[Int, T]
}
/**
- * Loop over the keys of the map. The same as `keys.foreach(f)`, but may
+ * Loop over the values of the map. The same as `values.foreach(f)`, but may
* be more efficient.
*
* @param f The loop body
diff --git a/src/library/scala/collection/immutable/LongMap.scala b/src/library/scala/collection/immutable/LongMap.scala
index 506546c5ba..868c0c0f47 100644
--- a/src/library/scala/collection/immutable/LongMap.scala
+++ b/src/library/scala/collection/immutable/LongMap.scala
@@ -205,7 +205,7 @@ extends AbstractMap[Long, T]
}
/**
- * Loop over the keys of the map. The same as keys.foreach(f), but may
+ * Loop over the values of the map. The same as values.foreach(f), but may
* be more efficient.
*
* @param f The loop body
diff --git a/src/library/scala/collection/mutable/AnyRefMap.scala b/src/library/scala/collection/mutable/AnyRefMap.scala
new file mode 100644
index 0000000000..df74bb5187
--- /dev/null
+++ b/src/library/scala/collection/mutable/AnyRefMap.scala
@@ -0,0 +1,451 @@
+package scala
+package collection
+package mutable
+
+import generic.CanBuildFrom
+
+/** This class implements mutable maps with `AnyRef` keys based on a hash table with open addressing.
+ *
+ * Basic map operations on single entries, including `contains` and `get`,
+ * are typically significantly faster with `AnyRefMap` than [[HashMap]].
+ * Note that numbers and characters are not handled specially in AnyRefMap;
+ * only plain `equals` and `hashCode` are used in comparisons.
+ *
+ * Methods that traverse or regenerate the map, including `foreach` and `map`,
+ * are not in general faster than with `HashMap`. The methods `foreachKey`,
+ * `foreachValue`, `mapValuesNow`, and `transformValues` are, however, faster
+ * than alternative ways to achieve the same functionality.
+ *
+ * Maps with open addressing may become less efficient at lookup after
+ * repeated addition/removal of elements. Although `AnyRefMap` makes a
+ * decent attempt to remain efficient regardless, calling `repack`
+ * on a map that will no longer have elements removed but will be
+ * used heavily may save both time and storage space.
+ *
+ * This map is not indended to contain more than 2^29 entries (approximately
+ * 500 million). The maximum capacity is 2^30, but performance will degrade
+ * rapidly as 2^30 is approached.
+ *
+ */
+final class AnyRefMap[K <: AnyRef, V] private[collection] (defaultEntry: K => V, initialBufferSize: Int, initBlank: Boolean)
+extends AbstractMap[K, V]
+ with Map[K, V]
+ with MapLike[K, V, AnyRefMap[K, V]]
+{
+ import AnyRefMap._
+ def this() = this(AnyRefMap.exceptionDefault, 16, true)
+
+ /** Creates a new `AnyRefMap` that returns default values according to a supplied key-value mapping. */
+ def this(defaultEntry: K => V) = this(defaultEntry, 16, true)
+
+ /** Creates a new `AnyRefMap` with an initial buffer of specified size.
+ *
+ * An `AnyRefMap` can typically contain half as many elements as its buffer size
+ * before it requires resizing.
+ */
+ def this(initialBufferSize: Int) = this(AnyRefMap.exceptionDefault, initialBufferSize, true)
+
+ /** Creates a new `AnyRefMap` with specified default values and initial buffer size. */
+ def this(defaultEntry: K => V, initialBufferSize: Int) = this(defaultEntry, initialBufferSize, true)
+
+ private[this] var mask = 0
+ private[this] var _size = 0
+ private[this] var _vacant = 0
+ private[this] var _hashes: Array[Int] = null
+ private[this] var _keys: Array[AnyRef] = null
+ private[this] var _values: Array[AnyRef] = null
+
+ if (initBlank) defaultInitialize(initialBufferSize)
+
+ private[this] def defaultInitialize(n: Int) {
+ mask =
+ if (n<0) 0x7
+ else (((1 << (32 - java.lang.Integer.numberOfLeadingZeros(n-1))) - 1) & 0x3FFFFFFF) | 0x7
+ _hashes = new Array[Int](mask+1)
+ _keys = new Array[AnyRef](mask+1)
+ _values = new Array[AnyRef](mask+1)
+ }
+
+ private[collection] def initializeTo(
+ m: Int, sz: Int, vc: Int, hz: Array[Int], kz: Array[AnyRef], vz: Array[AnyRef]
+ ) {
+ mask = m; _size = sz; _vacant = vc; _hashes = hz; _keys = kz; _values = vz
+ }
+
+ override def size: Int = _size
+ override def empty: AnyRefMap[K,V] = new AnyRefMap(defaultEntry)
+
+ private def imbalanced: Boolean =
+ (_size + _vacant) > 0.5*mask || _vacant > _size
+
+ private def hashOf(key: K): Int = {
+ if (key eq null) 0x41081989
+ else {
+ val h = key.hashCode
+ // Part of the MurmurHash3 32 bit finalizer
+ val i = (h ^ (h >>> 16)) * 0x85EBCA6B
+ val j = (i ^ (i >>> 13))
+ if (j==0) 0x41081989 else j & 0x7FFFFFFF
+ }
+ }
+
+ private def seekEntry(h: Int, k: AnyRef): Int = {
+ var e = h & mask
+ var x = 0
+ var g = 0
+ while ({ g = _hashes(e); g != 0}) {
+ if (g == h && { val q = _keys(e); (q eq k) || ((q ne null) && (q equals k)) }) return e
+ x += 1
+ e = (e + 2*(x+1)*x - 3) & mask
+ }
+ e | MissingBit
+ }
+
+ private def seekEntryOrOpen(h: Int, k: AnyRef): Int = {
+ var e = h & mask
+ var x = 0
+ var g = 0
+ var o = -1
+ while ({ g = _hashes(e); g != 0}) {
+ if (g == h && { val q = _keys(e); (q eq k) || ((q ne null) && (q equals k)) }) return e
+ else if (o == -1 && g+g == 0) o = e
+ x += 1
+ e = (e + 2*(x+1)*x - 3) & mask
+ }
+ if (o >= 0) o | MissVacant else e | MissingBit
+ }
+
+ override def contains(key: K): Boolean = seekEntry(hashOf(key), key) >= 0
+
+ override def get(key: K): Option[V] = {
+ val i = seekEntry(hashOf(key), key)
+ if (i < 0) None else Some(_values(i).asInstanceOf[V])
+ }
+
+ override def getOrElse[V1 >: V](key: K, default: => V1): V1 = {
+ val i = seekEntry(hashOf(key), key)
+ if (i < 0) default else _values(i).asInstanceOf[V]
+ }
+
+ override def getOrElseUpdate(key: K, defaultValue: => V): V = {
+ val h = hashOf(key)
+ val i = seekEntryOrOpen(h, key)
+ if (i < 0) {
+ val value = defaultValue
+ _size += 1
+ val j = i & IndexMask
+ _hashes(j) = h
+ _keys(j) = key.asInstanceOf[AnyRef]
+ _values(j) = value.asInstanceOf[AnyRef]
+ if ((i & VacantBit) != 0) _vacant -= 1
+ else if (imbalanced) repack()
+ value
+ }
+ else _values(i).asInstanceOf[V]
+ }
+
+ /** Retrieves the value associated with a key, or the default for that type if none exists
+ * (null for AnyRef, 0 for floats and integers).
+ *
+ * Note: this is the fastest way to retrieve a value that may or
+ * may not exist, if the default null/zero is acceptable. For key/value
+ * pairs that do exist, `apply` (i.e. `map(key)`) is equally fast.
+ */
+ def getOrNull(key: K): V = {
+ val i = seekEntry(hashOf(key), key)
+ (if (i < 0) null else _values(i)).asInstanceOf[V]
+ }
+
+ /** Retrieves the value associated with a key.
+ * If the key does not exist in the map, the `defaultEntry` for that key
+ * will be returned instead; an exception will be thrown if no
+ * `defaultEntry` was supplied.
+ */
+ override def apply(key: K): V = {
+ val i = seekEntry(hashOf(key), key)
+ if (i < 0) defaultEntry(key) else _values(i).asInstanceOf[V]
+ }
+
+ /** Defers to defaultEntry to find a default value for the key. Throws an
+ * exception if no other default behavior was specified.
+ */
+ override def default(key: K) = defaultEntry(key)
+
+ private def repack(newMask: Int) {
+ val oh = _hashes
+ val ok = _keys
+ val ov = _values
+ mask = newMask
+ _hashes = new Array[Int](mask+1)
+ _keys = new Array[AnyRef](mask+1)
+ _values = new Array[AnyRef](mask+1)
+ _vacant = 0
+ var i = 0
+ while (i < oh.length) {
+ val h = oh(i)
+ if (h+h != 0) {
+ var e = h & mask
+ var x = 0
+ while (_hashes(e) != 0) { x += 1; e = (e + 2*(x+1)*x - 3) & mask }
+ _hashes(e) = h
+ _keys(e) = ok(i)
+ _values(e) = ov(i)
+ }
+ i += 1
+ }
+ }
+
+ /** Repacks the contents of this `AnyRefMap` for maximum efficiency of lookup.
+ *
+ * For maps that undergo a complex creation process with both addition and
+ * removal of keys, and then are used heavily with no further removal of
+ * elements, calling `repack` after the end of the creation can result in
+ * improved performance. Repacking takes time proportional to the number
+ * of entries in the map.
+ */
+ def repack() {
+ var m = mask
+ if (_size + _vacant >= 0.5*mask && !(_vacant > 0.2*mask)) m = ((m << 1) + 1) & IndexMask
+ while (m > 8 && 8*_size < m) m = m >>> 1
+ repack(m)
+ }
+
+ override def put(key: K, value: V): Option[V] = {
+ val h = hashOf(key)
+ val k = key
+ var i = seekEntryOrOpen(h, k)
+ if (i < 0) {
+ val j = i & IndexMask
+ _hashes(j) = h
+ _keys(j) = k
+ _values(j) = value.asInstanceOf[AnyRef]
+ _size += 1
+ if ((i & VacantBit) != 0) _vacant -= 1
+ else if (imbalanced) repack()
+ None
+ }
+ else {
+ val ans = Some(_values(i).asInstanceOf[V])
+ _hashes(i) = h
+ _keys(i) = k
+ _values(i) = value.asInstanceOf[AnyRef]
+ ans
+ }
+ }
+
+ /** Updates the map to include a new key-value pair.
+ *
+ * This is the fastest way to add an entry to an `AnyRefMap`.
+ */
+ override def update(key: K, value: V): Unit = {
+ val h = hashOf(key)
+ val k = key
+ var i = seekEntryOrOpen(h, k)
+ if (i < 0) {
+ val j = i & IndexMask
+ _hashes(j) = h
+ _keys(j) = k
+ _values(j) = value.asInstanceOf[AnyRef]
+ _size += 1
+ if ((i & VacantBit) != 0) _vacant -= 1
+ else if (imbalanced) repack()
+ }
+ else {
+ _hashes(i) = h
+ _keys(i) = k
+ _values(i) = value.asInstanceOf[AnyRef]
+ }
+ }
+
+ /** Adds a new key/value pair to this map and returns the map. */
+ def +=(key: K, value: V): this.type = { update(key, value); this }
+
+ def +=(kv: (K, V)): this.type = { update(kv._1, kv._2); this }
+
+ def -=(key: K): this.type = {
+ val i = seekEntry(hashOf(key), key)
+ if (i >= 0) {
+ _size -= 1
+ _vacant += 1
+ _hashes(i) = Int.MinValue
+ _keys(i) = null
+ _values(i) = null
+ }
+ this
+ }
+
+ def iterator: Iterator[(K, V)] = new Iterator[(K, V)] {
+ private[this] val hz = _hashes
+ private[this] val kz = _keys
+ private[this] val vz = _values
+
+ private[this] var index = 0
+ private[this] var found = false
+
+ def hasNext = found || (index<hz.length && {
+ var h = hz(index)
+ if (h+h != 0) found = true
+ else {
+ index += 1
+ while (index < hz.length && { h = hz(index); h+h == 0 }) index += 1
+ found = (index < hz.length)
+ }
+ found
+ })
+
+ def next = {
+ if (found || hasNext) {
+ val ans = (_keys(index).asInstanceOf[K], _values(index).asInstanceOf[V])
+ index += 1
+ found = false
+ ans
+ }
+ else throw new NoSuchElementException("next")
+ }
+ }
+
+ override def foreach[A](f: ((K,V)) => A) {
+ var i = 0
+ var e = _size
+ while (e > 0) {
+ while(i < _hashes.length && { val h = _hashes(i); h+h == 0 && i < _hashes.length}) i += 1
+ if (i < _hashes.length) {
+ f((_keys(i).asInstanceOf[K], _values(i).asInstanceOf[V]))
+ i += 1
+ e -= 1
+ }
+ else return
+ }
+ }
+
+ override def clone(): AnyRefMap[K, V] = {
+ val hz = java.util.Arrays.copyOf(_hashes, _hashes.length)
+ val kz = java.util.Arrays.copyOf(_keys, _keys.length)
+ val vz = java.util.Arrays.copyOf(_values, _values.length)
+ val arm = new AnyRefMap[K, V](defaultEntry, 1, false)
+ arm.initializeTo(mask, _size, _vacant, hz, kz, vz)
+ arm
+ }
+
+ private[this] def foreachElement[A,B](elems: Array[AnyRef], f: A => B) {
+ var i,j = 0
+ while (i < _hashes.length & j < _size) {
+ val h = _hashes(i)
+ if (h+h != 0) {
+ j += 1
+ f(elems(i).asInstanceOf[A])
+ }
+ i += 1
+ }
+ }
+
+ /** Applies a function to all keys of this map. */
+ def foreachKey[A](f: K => A) { foreachElement[K,A](_keys, f) }
+
+ /** Applies a function to all values of this map. */
+ def foreachValue[A](f: V => A) { foreachElement[V,A](_values, f) }
+
+ /** Creates a new `AnyRefMap` with different values.
+ * Unlike `mapValues`, this method generates a new
+ * collection immediately.
+ */
+ def mapValuesNow[V1](f: V => V1): AnyRefMap[K, V1] = {
+ val arm = new AnyRefMap[K,V1](AnyRefMap.exceptionDefault, 1, false)
+ val hz = java.util.Arrays.copyOf(_hashes, _hashes.length)
+ val kz = java.util.Arrays.copyOf(_keys, _keys.length)
+ val vz = new Array[AnyRef](_values.length)
+ var i,j = 0
+ while (i < _hashes.length & j < _size) {
+ val h = _hashes(i)
+ if (h+h != 0) {
+ j += 1
+ vz(i) = f(_values(i).asInstanceOf[V]).asInstanceOf[AnyRef]
+ }
+ i += 1
+ }
+ arm.initializeTo(mask, _size, _vacant, hz, kz, vz)
+ arm
+ }
+
+ /** Applies a transformation function to all values stored in this map.
+ * Note: the default, if any, is not transformed.
+ */
+ def transformValues(f: V => V): this.type = {
+ var i,j = 0
+ while (i < _hashes.length & j < _size) {
+ val h = _hashes(i)
+ if (h+h != 0) {
+ j += 1
+ _values(i) = f(_values(i).asInstanceOf[V]).asInstanceOf[AnyRef]
+ }
+ i += 1
+ }
+ this
+ }
+
+}
+
+object AnyRefMap {
+ private final val IndexMask = 0x3FFFFFFF
+ private final val MissingBit = 0x80000000
+ private final val VacantBit = 0x40000000
+ private final val MissVacant = 0xC0000000
+
+ private val exceptionDefault = (k: Any) => throw new NoSuchElementException(if (k == null) "(null)" else k.toString)
+
+ implicit def canBuildFrom[K <: AnyRef, V, J <: AnyRef, U]: CanBuildFrom[AnyRefMap[K,V], (J, U), AnyRefMap[J,U]] =
+ new CanBuildFrom[AnyRefMap[K,V], (J, U), AnyRefMap[J,U]] {
+ def apply(from: AnyRefMap[K,V]): AnyRefMapBuilder[J, U] = apply()
+ def apply(): AnyRefMapBuilder[J, U] = new AnyRefMapBuilder[J, U]
+ }
+
+ final class AnyRefMapBuilder[K <: AnyRef, V] extends Builder[(K, V), AnyRefMap[K, V]] {
+ private[collection] var elems: AnyRefMap[K, V] = new AnyRefMap[K, V]
+ def +=(entry: (K, V)): this.type = {
+ elems += entry
+ this
+ }
+ def clear() { elems = new AnyRefMap[K, V] }
+ def result(): AnyRefMap[K, V] = elems
+ }
+
+ /** Creates a new `AnyRefMap` with zero or more key/value pairs. */
+ def apply[K <: AnyRef, V](elems: (K, V)*): AnyRefMap[K, V] = {
+ val sz = if (elems.hasDefiniteSize) elems.size else 4
+ val arm = new AnyRefMap[K, V](sz * 2)
+ elems.foreach{ case (k,v) => arm(k) = v }
+ if (arm.size < (sz>>3)) arm.repack()
+ arm
+ }
+
+ /** Creates a new empty `AnyRefMap`. */
+ def empty[K <: AnyRef, V]: AnyRefMap[K, V] = new AnyRefMap[K, V]
+
+ /** Creates a new empty `AnyRefMap` with the supplied default */
+ def withDefault[K <: AnyRef, V](default: K => V): AnyRefMap[K, V] = new AnyRefMap[K, V](default)
+
+ /** Creates a new `AnyRefMap` from arrays of keys and values.
+ * Equivalent to but more efficient than `AnyRefMap((keys zip values): _*)`.
+ */
+ def fromZip[K <: AnyRef, V](keys: Array[K], values: Array[V]): AnyRefMap[K, V] = {
+ val sz = math.min(keys.length, values.length)
+ val arm = new AnyRefMap[K, V](sz * 2)
+ var i = 0
+ while (i < sz) { arm(keys(i)) = values(i); i += 1 }
+ if (arm.size < (sz>>3)) arm.repack()
+ arm
+ }
+
+ /** Creates a new `AnyRefMap` from keys and values.
+ * Equivalent to but more efficient than `AnyRefMap((keys zip values): _*)`.
+ */
+ def fromZip[K <: AnyRef, V](keys: Iterable[K], values: Iterable[V]): AnyRefMap[K, V] = {
+ val sz = math.min(keys.size, values.size)
+ val arm = new AnyRefMap[K, V](sz * 2)
+ val ki = keys.iterator
+ val vi = values.iterator
+ while (ki.hasNext && vi.hasNext) arm(ki.next) = vi.next
+ if (arm.size < (sz >> 3)) arm.repack()
+ arm
+ }
+}
diff --git a/src/library/scala/collection/mutable/LongMap.scala b/src/library/scala/collection/mutable/LongMap.scala
new file mode 100644
index 0000000000..81c381279f
--- /dev/null
+++ b/src/library/scala/collection/mutable/LongMap.scala
@@ -0,0 +1,558 @@
+package scala
+package collection
+package mutable
+
+import generic.CanBuildFrom
+
+/** This class implements mutable maps with `Long` keys based on a hash table with open addressing.
+ *
+ * Basic map operations on single entries, including `contains` and `get`,
+ * are typically substantially faster with `LongMap` than [[HashMap]]. Methods
+ * that act on the whole map, including `foreach` and `map` are not in
+ * general expected to be faster than with a generic map, save for those
+ * that take particular advantage of the internal structure of the map:
+ * `foreachKey`, `foreachValue`, `mapValuesNow`, and `transformValues`.
+ *
+ * Maps with open addressing may become less efficient at lookup after
+ * repeated addition/removal of elements. Although `LongMap` makes a
+ * decent attempt to remain efficient regardless, calling `repack`
+ * on a map that will no longer have elements removed but will be
+ * used heavily may save both time and storage space.
+ *
+ * This map is not indended to contain more than 2^29 entries (approximately
+ * 500 million). The maximum capacity is 2^30, but performance will degrade
+ * rapidly as 2^30 is approached.
+ *
+ */
+final class LongMap[V] private[collection] (defaultEntry: Long => V, initialBufferSize: Int, initBlank: Boolean)
+extends AbstractMap[Long, V]
+ with Map[Long, V]
+ with MapLike[Long, V, LongMap[V]]
+ with Serializable
+{
+ import LongMap._
+
+ def this() = this(LongMap.exceptionDefault, 16, true)
+
+ /** Creates a new `LongMap` that returns default values according to a supplied key-value mapping. */
+ def this(defaultEntry: Long => V) = this(defaultEntry, 16, true)
+
+ /** Creates a new `LongMap` with an initial buffer of specified size.
+ *
+ * A LongMap can typically contain half as many elements as its buffer size
+ * before it requires resizing.
+ */
+ def this(initialBufferSize: Int) = this(LongMap.exceptionDefault, initialBufferSize, true)
+
+ /** Creates a new `LongMap` with specified default values and initial buffer size. */
+ def this(defaultEntry: Long => V, initialBufferSize: Int) = this(defaultEntry, initialBufferSize, true)
+
+ private[this] var mask = 0
+ private[this] var extraKeys: Int = 0
+ private[this] var zeroValue: AnyRef = null
+ private[this] var minValue: AnyRef = null
+ private[this] var _size = 0
+ private[this] var _vacant = 0
+ private[this] var _keys: Array[Long] = null
+ private[this] var _values: Array[AnyRef] = null
+
+ if (initBlank) defaultInitialize(initialBufferSize)
+
+ private[this] def defaultInitialize(n: Int) = {
+ mask =
+ if (n<0) 0x7
+ else (((1 << (32 - java.lang.Integer.numberOfLeadingZeros(n-1))) - 1) & 0x3FFFFFFF) | 0x7
+ _keys = new Array[Long](mask+1)
+ _values = new Array[AnyRef](mask+1)
+ }
+
+ private[collection] def initializeTo(
+ m: Int, ek: Int, zv: AnyRef, mv: AnyRef, sz: Int, vc: Int, kz: Array[Long], vz: Array[AnyRef]
+ ) {
+ mask = m; extraKeys = ek; zeroValue = zv; minValue = mv; _size = sz; _vacant = vc; _keys = kz; _values = vz
+ }
+
+ override def size: Int = _size + (extraKeys+1)/2
+ override def empty: LongMap[V] = new LongMap()
+
+ private def imbalanced: Boolean =
+ (_size + _vacant) > 0.5*mask || _vacant > _size
+
+ private def toIndex(k: Long): Int = {
+ // Part of the MurmurHash3 32 bit finalizer
+ val h = ((k ^ (k >>> 32)) & 0xFFFFFFFFL).toInt
+ var x = (h ^ (h >>> 16)) * 0x85EBCA6B
+ (x ^ (x >>> 13)) & mask
+ }
+
+ private def seekEmpty(k: Long): Int = {
+ var e = toIndex(k)
+ var x = 0
+ while (_keys(e) != 0) { x += 1; e = (e + 2*(x+1)*x - 3) & mask }
+ e
+ }
+
+ private def seekEntry(k: Long): Int = {
+ var e = toIndex(k)
+ var x = 0
+ var q = 0L
+ while ({ q = _keys(e); if (q==k) return e; q != 0}) { x += 1; e = (e + 2*(x+1)*x - 3) & mask }
+ e | MissingBit
+ }
+
+ private def seekEntryOrOpen(k: Long): Int = {
+ var e = toIndex(k)
+ var x = 0
+ var q = 0L
+ while ({ q = _keys(e); if (q==k) return e; q+q != 0}) {
+ x += 1
+ e = (e + 2*(x+1)*x - 3) & mask
+ }
+ if (q == 0) return e | MissingBit
+ val o = e | MissVacant
+ while ({ q = _keys(e); if (q==k) return e; q != 0}) {
+ x += 1
+ e = (e + 2*(x+1)*x - 3) & mask
+ }
+ o
+ }
+
+ override def contains(key: Long): Boolean = {
+ if (key == -key) (((key>>>63).toInt+1) & extraKeys) != 0
+ else seekEntry(key) >= 0
+ }
+
+ override def get(key: Long): Option[V] = {
+ if (key == -key) {
+ if ((((key>>>63).toInt+1) & extraKeys) == 0) None
+ else if (key == 0) Some(zeroValue.asInstanceOf[V])
+ else Some(minValue.asInstanceOf[V])
+ }
+ else {
+ val i = seekEntry(key)
+ if (i < 0) None else Some(_values(i).asInstanceOf[V])
+ }
+ }
+
+ override def getOrElse[V1 >: V](key: Long, default: => V1): V1 = {
+ if (key == -key) {
+ if ((((key>>>63).toInt+1) & extraKeys) == 0) default
+ else if (key == 0) zeroValue.asInstanceOf[V1]
+ else minValue.asInstanceOf[V1]
+ }
+ else {
+ val i = seekEntry(key)
+ if (i < 0) default else _values(i).asInstanceOf[V1]
+ }
+ }
+
+ override def getOrElseUpdate(key: Long, defaultValue: => V): V = {
+ if (key == -key) {
+ val kbits = (key>>>63).toInt + 1
+ if ((kbits & extraKeys) == 0) {
+ val value = defaultValue
+ extraKeys |= kbits
+ if (key == 0) zeroValue = value.asInstanceOf[AnyRef]
+ else minValue = value.asInstanceOf[AnyRef]
+ value
+ }
+ else if (key == 0) zeroValue.asInstanceOf[V]
+ else minValue.asInstanceOf[V]
+ }
+ else {
+ val i = seekEntryOrOpen(key)
+ if (i < 0) {
+ val value = defaultValue
+ _size += 1
+ val j = i & IndexMask
+ _keys(j) = key
+ _values(j) = value.asInstanceOf[AnyRef]
+ if ((i & VacantBit) != 0) _vacant -= 1
+ else if (imbalanced) repack()
+ value
+ }
+ else _values(i).asInstanceOf[V]
+ }
+ }
+
+ /** Retrieves the value associated with a key, or the default for that type if none exists
+ * (null for AnyRef, 0 for floats and integers).
+ *
+ * Note: this is the fastest way to retrieve a value that may or
+ * may not exist, if the default null/zero is acceptable. For key/value
+ * pairs that do exist, `apply` (i.e. `map(key)`) is equally fast.
+ */
+ def getOrNull(key: Long): V = {
+ if (key == -key) {
+ if ((((key>>>63).toInt+1) & extraKeys) == 0) null.asInstanceOf[V]
+ else if (key == 0) zeroValue.asInstanceOf[V]
+ else minValue.asInstanceOf[V]
+ }
+ else {
+ val i = seekEntry(key)
+ if (i < 0) null.asInstanceOf[V] else _values(i).asInstanceOf[V]
+ }
+ }
+
+ /** Retrieves the value associated with a key.
+ * If the key does not exist in the map, the `defaultEntry` for that key
+ * will be returned instead.
+ */
+ override def apply(key: Long): V = {
+ if (key == -key) {
+ if ((((key>>>63).toInt+1) & extraKeys) == 0) defaultEntry(key)
+ else if (key == 0) zeroValue.asInstanceOf[V]
+ else minValue.asInstanceOf[V]
+ }
+ else {
+ val i = seekEntry(key)
+ if (i < 0) defaultEntry(key) else _values(i).asInstanceOf[V]
+ }
+ }
+
+ /** The user-supplied default value for the key. Throws an exception
+ * if no other default behavior was specified.
+ */
+ override def default(key: Long) = defaultEntry(key)
+
+ private def repack(newMask: Int) {
+ val ok = _keys
+ val ov = _values
+ mask = newMask
+ _keys = new Array[Long](mask+1)
+ _values = new Array[AnyRef](mask+1)
+ _vacant = 0
+ var i = 0
+ while (i < ok.length) {
+ val k = ok(i)
+ if (k != -k) {
+ val j = seekEmpty(k)
+ _keys(j) = k
+ _values(j) = ov(i)
+ }
+ i += 1
+ }
+ }
+
+ /** Repacks the contents of this `LongMap` for maximum efficiency of lookup.
+ *
+ * For maps that undergo a complex creation process with both addition and
+ * removal of keys, and then are used heavily with no further removal of
+ * elements, calling `repack` after the end of the creation can result in
+ * improved performance. Repacking takes time proportional to the number
+ * of entries in the map.
+ */
+ def repack() {
+ var m = mask
+ if (_size + _vacant >= 0.5*mask && !(_vacant > 0.2*mask)) m = ((m << 1) + 1) & IndexMask
+ while (m > 8 && 8*_size < m) m = m >>> 1
+ repack(m)
+ }
+
+ override def put(key: Long, value: V): Option[V] = {
+ if (key == -key) {
+ if (key == 0) {
+ val ans = if ((extraKeys&1) == 1) Some(zeroValue.asInstanceOf[V]) else None
+ zeroValue = value.asInstanceOf[AnyRef]
+ extraKeys |= 1
+ ans
+ }
+ else {
+ val ans = if ((extraKeys&2) == 1) Some(minValue.asInstanceOf[V]) else None
+ minValue = value.asInstanceOf[AnyRef]
+ extraKeys |= 2
+ ans
+ }
+ }
+ else {
+ val i = seekEntryOrOpen(key)
+ if (i < 0) {
+ val j = i & IndexMask
+ _keys(j) = key
+ _values(j) = value.asInstanceOf[AnyRef]
+ _size += 1
+ if ((i & VacantBit) != 0) _vacant -= 1
+ else if (imbalanced) repack()
+ None
+ }
+ else {
+ val ans = Some(_values(i).asInstanceOf[V])
+ _keys(i) = key
+ _values(i) = value.asInstanceOf[AnyRef]
+ ans
+ }
+ }
+ }
+
+ /** Updates the map to include a new key-value pair.
+ *
+ * This is the fastest way to add an entry to a `LongMap`.
+ */
+ override def update(key: Long, value: V): Unit = {
+ if (key == -key) {
+ if (key == 0) {
+ zeroValue = value.asInstanceOf[AnyRef]
+ extraKeys |= 1
+ }
+ else {
+ minValue = value.asInstanceOf[AnyRef]
+ extraKeys |= 2
+ }
+ }
+ else {
+ var i = seekEntryOrOpen(key)
+ if (i < 0) {
+ val j = i & IndexMask
+ _keys(j) = key
+ _values(j) = value.asInstanceOf[AnyRef]
+ _size += 1
+ if ((i & VacantBit) != 0) _vacant -= 1
+ else if (imbalanced) repack()
+ }
+ else {
+ _keys(i) = key
+ _values(i) = value.asInstanceOf[AnyRef]
+ }
+ }
+ }
+
+ /** Adds a new key/value pair to this map and returns the map. */
+ def +=(key: Long, value: V): this.type = { update(key, value); this }
+
+ def +=(kv: (Long, V)): this.type = { update(kv._1, kv._2); this }
+
+ def -=(key: Long): this.type = {
+ if (key == -key) {
+ if (key == 0L) {
+ extraKeys &= 0x2
+ zeroValue = null
+ }
+ else {
+ extraKeys &= 0x1
+ minValue = null
+ }
+ }
+ else {
+ val i = seekEntry(key)
+ if (i >= 0) {
+ _size -= 1
+ _vacant += 1
+ _keys(i) = Long.MinValue
+ _values(i) = null
+ }
+ }
+ this
+ }
+
+ def iterator: Iterator[(Long, V)] = new Iterator[(Long, V)] {
+ private[this] val kz = _keys
+ private[this] val vz = _values
+
+ private[this] var nextPair: (Long, V) =
+ if (extraKeys==0) null
+ else if ((extraKeys&1)==1) (0L, zeroValue.asInstanceOf[V])
+ else (Long.MinValue, minValue.asInstanceOf[V])
+
+ private[this] var anotherPair: (Long, V) =
+ if (extraKeys==3) (Long.MinValue, minValue.asInstanceOf[V])
+ else null
+
+ private[this] var index = 0
+
+ def hasNext: Boolean = nextPair != null || (index < kz.length && {
+ var q = kz(index)
+ while (q == -q) {
+ index += 1
+ if (index >= kz.length) return false
+ q = kz(index)
+ }
+ nextPair = (kz(index), vz(index).asInstanceOf[V])
+ index += 1
+ true
+ })
+ def next = {
+ if (nextPair == null && !hasNext) throw new NoSuchElementException("next")
+ val ans = nextPair
+ if (anotherPair != null) {
+ nextPair = anotherPair
+ anotherPair = null
+ }
+ nextPair = null
+ ans
+ }
+ }
+
+ override def foreach[A](f: ((Long,V)) => A) {
+ var i,j = 0
+ while (i < _keys.length & j < _size) {
+ val k = _keys(i)
+ if (k != -k) {
+ j += 1
+ f((k, _values(i).asInstanceOf[V]))
+ }
+ i += 1
+ }
+ if ((extraKeys & 1) == 1) f((0L, zeroValue.asInstanceOf[V]))
+ if ((extraKeys & 2) == 2) f((Long.MinValue, minValue.asInstanceOf[V]))
+ }
+
+ override def clone(): LongMap[V] = {
+ val kz = java.util.Arrays.copyOf(_keys, _keys.length)
+ val vz = java.util.Arrays.copyOf(_values, _values.length)
+ val lm = new LongMap[V](defaultEntry, 1, false)
+ lm.initializeTo(mask, extraKeys, zeroValue, minValue, _size, _vacant, kz, vz)
+ lm
+ }
+
+ /** Applies a function to all keys of this map. */
+ def foreachKey[A](f: Long => A) {
+ var i,j = 0
+ while (i < _keys.length & j < _size) {
+ val k = _keys(i)
+ if (k != -k) {
+ j += 1
+ f(k)
+ }
+ i += 1
+ }
+ if ((extraKeys & 1) == 1) f(0L)
+ if ((extraKeys & 2) == 2) f(Long.MinValue)
+ }
+
+ /** Applies a function to all values of this map. */
+ def foreachValue[A](f: V => A) {
+ var i,j = 0
+ while (i < _keys.length & j < _size) {
+ val k = _keys(i)
+ if (k != -k) {
+ j += 1
+ f(_values(i).asInstanceOf[V])
+ }
+ i += 1
+ }
+ if ((extraKeys & 1) == 1) f(zeroValue.asInstanceOf[V])
+ if ((extraKeys & 2) == 2) f(minValue.asInstanceOf[V])
+ }
+
+ /** Creates a new `LongMap` with different values.
+ * Unlike `mapValues`, this method generates a new
+ * collection immediately.
+ */
+ def mapValuesNow[V1](f: V => V1): LongMap[V1] = {
+ val lm = new LongMap[V1](LongMap.exceptionDefault, 1, false)
+ val kz = java.util.Arrays.copyOf(_keys, _keys.length)
+ val vz = new Array[AnyRef](_values.length)
+ var i,j = 0
+ while (i < _keys.length & j < _size) {
+ val k = _keys(i)
+ if (k != -k) {
+ j += 1
+ vz(i) = f(_values(i).asInstanceOf[V]).asInstanceOf[AnyRef]
+ }
+ i += 1
+ }
+ val zv = if ((extraKeys & 1) == 1) f(zeroValue.asInstanceOf[V]).asInstanceOf[AnyRef] else null
+ val mv = if ((extraKeys & 2) == 2) f(minValue.asInstanceOf[V]).asInstanceOf[AnyRef] else null
+ lm.initializeTo(mask, extraKeys, zv, mv, _size, _vacant, kz, vz)
+ lm
+ }
+
+ /** Applies a transformation function to all values stored in this map.
+ * Note: the default, if any, is not transformed.
+ */
+ def transformValues(f: V => V): this.type = {
+ var i,j = 0
+ while (i < _keys.length & j < _size) {
+ val k = _keys(i)
+ if (k != -k) {
+ j += 1
+ _values(i) = f(_values(i).asInstanceOf[V]).asInstanceOf[AnyRef]
+ }
+ i += 1
+ }
+ if ((extraKeys & 1) == 1) zeroValue = f(zeroValue.asInstanceOf[V]).asInstanceOf[AnyRef]
+ if ((extraKeys & 2) == 2) minValue = f(minValue.asInstanceOf[V]).asInstanceOf[AnyRef]
+ this
+ }
+
+ /*
+ override def toString = {
+ val sb = new StringBuilder("LongMap(")
+ var n = 0
+ foreach{ case (k,v) =>
+ if (n > 0) sb ++= ", "
+ sb ++= k.toString
+ sb ++= " -> "
+ sb ++= v.toString
+ n += 1
+ }
+ sb += ')'
+ sb.result
+ }
+ */
+}
+
+object LongMap {
+ private final val IndexMask = 0x3FFFFFFF
+ private final val MissingBit = 0x80000000
+ private final val VacantBit = 0x40000000
+ private final val MissVacant = 0xC0000000
+
+ private val exceptionDefault: Long => Nothing = (k: Long) => throw new NoSuchElementException(k.toString)
+
+ implicit def canBuildFrom[V, U]: CanBuildFrom[LongMap[V], (Long, U), LongMap[U]] =
+ new CanBuildFrom[LongMap[V], (Long, U), LongMap[U]] {
+ def apply(from: LongMap[V]): LongMapBuilder[U] = apply()
+ def apply(): LongMapBuilder[U] = new LongMapBuilder[U]
+ }
+
+ final class LongMapBuilder[V] extends Builder[(Long, V), LongMap[V]] {
+ private[collection] var elems: LongMap[V] = new LongMap[V]
+ def +=(entry: (Long, V)): this.type = {
+ elems += entry
+ this
+ }
+ def clear() { elems = new LongMap[V] }
+ def result(): LongMap[V] = elems
+ }
+
+ /** Creates a new `LongMap` with zero or more key/value pairs. */
+ def apply[V](elems: (Long, V)*): LongMap[V] = {
+ val sz = if (elems.hasDefiniteSize) elems.size else 4
+ val lm = new LongMap[V](sz * 2)
+ elems.foreach{ case (k,v) => lm(k) = v }
+ if (lm.size < (sz>>3)) lm.repack()
+ lm
+ }
+
+ /** Creates a new empty `LongMap`. */
+ def empty[V]: LongMap[V] = new LongMap[V]
+
+ /** Creates a new empty `LongMap` with the supplied default */
+ def withDefault[V](default: Long => V): LongMap[V] = new LongMap[V](default)
+
+ /** Creates a new `LongMap` from arrays of keys and values.
+ * Equivalent to but more efficient than `LongMap((keys zip values): _*)`.
+ */
+ def fromZip[V](keys: Array[Long], values: Array[V]): LongMap[V] = {
+ val sz = math.min(keys.length, values.length)
+ val lm = new LongMap[V](sz * 2)
+ var i = 0
+ while (i < sz) { lm(keys(i)) = values(i); i += 1 }
+ if (lm.size < (sz>>3)) lm.repack()
+ lm
+ }
+
+ /** Creates a new `LongMap` from keys and values.
+ * Equivalent to but more efficient than `LongMap((keys zip values): _*)`.
+ */
+ def fromZip[V](keys: Iterable[Long], values: Iterable[V]): LongMap[V] = {
+ val sz = math.min(keys.size, values.size)
+ val lm = new LongMap[V](sz * 2)
+ val ki = keys.iterator
+ val vi = values.iterator
+ while (ki.hasNext && vi.hasNext) lm(ki.next) = vi.next
+ if (lm.size < (sz >> 3)) lm.repack()
+ lm
+ }
+}
diff --git a/test/files/pos/t1014.scala b/test/files/pos/t1014.scala
new file mode 100644
index 0000000000..6fb7f7ba49
--- /dev/null
+++ b/test/files/pos/t1014.scala
@@ -0,0 +1,16 @@
+class NodeSeq
+class Elem extends NodeSeq
+
+class EO extends App with Moo {
+ // return type is Flog, inherited from overridden method.
+ // implicit conversions are applied because expected type `pt` is `Flog` when `computeType(rhs, pt)`.
+ def cat = (??? : Elem)
+
+ implicit def nodeSeqToFlog(in: Elem): Flog = new Flog(in)
+}
+
+trait Moo {
+ def cat: Flog
+}
+
+class Flog(val in: NodeSeq)
diff --git a/test/files/pos/t1203a.scala b/test/files/pos/t1203a.scala
new file mode 100644
index 0000000000..cf5ab9fba0
--- /dev/null
+++ b/test/files/pos/t1203a.scala
@@ -0,0 +1,13 @@
+class Node
+object NodeSeq {
+ implicit def seqToNodeSeq(s: Seq[Node]): NodeSeq = ???
+}
+abstract class NodeSeq extends collection.immutable.Seq[Node]
+
+case class ant(t: String) extends scala.annotation.Annotation
+object Test {
+ def main(args: Array[String]): Unit = {
+ val a: NodeSeq @ant("12") = Nil
+ println(a)
+ }
+}
diff --git a/test/files/pos/t2698.scala b/test/files/pos/t2698.scala
new file mode 100644
index 0000000000..bce02e48b3
--- /dev/null
+++ b/test/files/pos/t2698.scala
@@ -0,0 +1,14 @@
+class WordExp {
+ abstract class Label
+ type _labelT <: Label
+}
+
+import scala.collection._
+
+abstract class S2 {
+ val lang: WordExp
+ type __labelT = lang._labelT
+
+ var deltaq: Array[__labelT] = _
+ def delta1 = immutable.Map(deltaq.zipWithIndex: _*)
+}
diff --git a/test/files/pos/t3160.scala b/test/files/pos/t3160.scala
new file mode 100644
index 0000000000..cc007dc014
--- /dev/null
+++ b/test/files/pos/t3160.scala
@@ -0,0 +1,6 @@
+import scala.collection.mutable._
+class Node
+
+class A {
+ def f(x: Node): Node = ???
+}
diff --git a/test/files/pos/t6201.scala b/test/files/pos/t6201.scala
new file mode 100644
index 0000000000..d4e5bce03a
--- /dev/null
+++ b/test/files/pos/t6201.scala
@@ -0,0 +1,19 @@
+// probably needs xml's weirdness to reproduce
+// (specifically, _root_.scala.xml.Null being in the root package)
+class Elem
+
+class Test {
+ def elem: Elem = ???
+
+ class Foo1 {
+ def must(x: Elem) = ()
+ }
+
+ class Foo2 {
+ def must(x: Int) = ()
+ }
+ implicit def toFoo1(s: Elem) = new Foo1()
+ implicit def toFoo2(s: Elem) = new Foo2()
+
+ def is: Unit = { (elem) }
+} \ No newline at end of file
diff --git a/test/files/presentation/callcc-interpreter.check b/test/files/presentation/callcc-interpreter.check
index d41b982614..f031c52c86 100644
--- a/test/files/presentation/callcc-interpreter.check
+++ b/test/files/presentation/callcc-interpreter.check
@@ -2,7 +2,7 @@ reload: CallccInterpreter.scala
askTypeCompletion at CallccInterpreter.scala(51,38)
================================================================================
-[response] askCompletionAt (51,38)
+[response] askTypeCompletion at (51,38)
retrieved 59 members
abstract trait Term extends AnyRef
abstract trait Value extends AnyRef
diff --git a/test/files/presentation/completion-implicit-chained.check b/test/files/presentation/completion-implicit-chained.check
index b34e6bc7e1..f9d77f7a53 100644
--- a/test/files/presentation/completion-implicit-chained.check
+++ b/test/files/presentation/completion-implicit-chained.check
@@ -2,7 +2,7 @@ reload: Completions.scala
askTypeCompletion at Completions.scala(11,16)
================================================================================
-[response] askCompletionAt (11,16)
+[response] askTypeCompletion at (11,16)
retrieved 24 members
[inaccessible] protected[package lang] def clone(): Object
[inaccessible] protected[package lang] def finalize(): Unit
diff --git a/test/files/presentation/ide-bug-1000349.check b/test/files/presentation/ide-bug-1000349.check
index aa6660cec5..c59fa6843f 100644
--- a/test/files/presentation/ide-bug-1000349.check
+++ b/test/files/presentation/ide-bug-1000349.check
@@ -2,7 +2,7 @@ reload: CompletionOnEmptyArgMethod.scala
askTypeCompletion at CompletionOnEmptyArgMethod.scala(2,17)
================================================================================
-[response] askCompletionAt (2,17)
+[response] askTypeCompletion at (2,17)
retrieved 32 members
def +(other: String): String
def ->[B](y: B): (Foo, B)
diff --git a/test/files/presentation/ide-bug-1000475.check b/test/files/presentation/ide-bug-1000475.check
index cb7de6d34a..f5b4253e1a 100644
--- a/test/files/presentation/ide-bug-1000475.check
+++ b/test/files/presentation/ide-bug-1000475.check
@@ -2,7 +2,7 @@ reload: Foo.scala
askTypeCompletion at Foo.scala(3,7)
================================================================================
-[response] askCompletionAt (3,7)
+[response] askTypeCompletion at (3,7)
retrieved 31 members
[inaccessible] protected[package lang] def clone(): Object
[inaccessible] protected[package lang] def finalize(): Unit
@@ -36,7 +36,7 @@ final def wait(x$1: Long,x$2: Int): Unit
askTypeCompletion at Foo.scala(6,10)
================================================================================
-[response] askCompletionAt (6,10)
+[response] askTypeCompletion at (6,10)
retrieved 31 members
[inaccessible] protected[package lang] def clone(): Object
[inaccessible] protected[package lang] def finalize(): Unit
@@ -70,7 +70,7 @@ final def wait(x$1: Long,x$2: Int): Unit
askTypeCompletion at Foo.scala(7,7)
================================================================================
-[response] askCompletionAt (7,7)
+[response] askTypeCompletion at (7,7)
retrieved 31 members
[inaccessible] protected[package lang] def clone(): Object
[inaccessible] protected[package lang] def finalize(): Unit
diff --git a/test/files/presentation/ide-bug-1000531.check b/test/files/presentation/ide-bug-1000531.check
index 9a2cad5fd2..dff89b155b 100644
--- a/test/files/presentation/ide-bug-1000531.check
+++ b/test/files/presentation/ide-bug-1000531.check
@@ -2,7 +2,7 @@ reload: CrashOnLoad.scala
askTypeCompletion at CrashOnLoad.scala(6,12)
================================================================================
-[response] askCompletionAt (6,12)
+[response] askTypeCompletion at (6,12)
retrieved 120 members
[inaccessible] protected[package lang] def clone(): Object
[inaccessible] protected[package lang] def finalize(): Unit
diff --git a/test/files/presentation/implicit-member.check b/test/files/presentation/implicit-member.check
index ef361599c5..5ad52b4dd3 100644
--- a/test/files/presentation/implicit-member.check
+++ b/test/files/presentation/implicit-member.check
@@ -2,7 +2,7 @@ reload: ImplicitMember.scala
askTypeCompletion at ImplicitMember.scala(7,7)
================================================================================
-[response] askCompletionAt (7,7)
+[response] askTypeCompletion at (7,7)
retrieved 34 members
def +(other: String): String
def ->[B](y: B): (Implicit.type, B)
diff --git a/test/files/presentation/ping-pong.check b/test/files/presentation/ping-pong.check
index 10d29bfed6..20f17aa7d0 100644
--- a/test/files/presentation/ping-pong.check
+++ b/test/files/presentation/ping-pong.check
@@ -2,7 +2,7 @@ reload: PingPong.scala
askTypeCompletion at PingPong.scala(10,23)
================================================================================
-[response] askCompletionAt (10,23)
+[response] askTypeCompletion at (10,23)
retrieved 35 members
[inaccessible] private[this] val ping: Ping
[inaccessible] protected[package lang] def clone(): Object
@@ -39,7 +39,7 @@ private[this] val name: String
askTypeCompletion at PingPong.scala(19,20)
================================================================================
-[response] askCompletionAt (19,20)
+[response] askTypeCompletion at (19,20)
retrieved 35 members
[inaccessible] protected[package lang] def clone(): Object
[inaccessible] protected[package lang] def finalize(): Unit
diff --git a/test/files/presentation/scope-completion-1.check b/test/files/presentation/scope-completion-1.check
new file mode 100644
index 0000000000..63f956b239
--- /dev/null
+++ b/test/files/presentation/scope-completion-1.check
@@ -0,0 +1,19 @@
+reload: Completions.scala
+
+askScopeCompletion at Completions.scala(6,2)
+================================================================================
+[response] askScopeCompletion at (6,2)
+retrieved 3 members
+class Completion1 extends AnyRef
+def <init>(): test.Completion1
+object Completion2
+================================================================================
+
+askScopeCompletion at Completions.scala(10,2)
+================================================================================
+[response] askScopeCompletion at (10,2)
+retrieved 3 members
+class Completion1 extends AnyRef
+def <init>(): test.Completion2.type
+object Completion2
+================================================================================
diff --git a/test/files/presentation/scope-completion-1/Test.scala b/test/files/presentation/scope-completion-1/Test.scala
new file mode 100644
index 0000000000..bec1131c4c
--- /dev/null
+++ b/test/files/presentation/scope-completion-1/Test.scala
@@ -0,0 +1,3 @@
+import scala.tools.nsc.interactive.tests.InteractiveTest
+
+object Test extends InteractiveTest \ No newline at end of file
diff --git a/test/files/presentation/scope-completion-1/src/Completions.scala b/test/files/presentation/scope-completion-1/src/Completions.scala
new file mode 100644
index 0000000000..c4eea6b261
--- /dev/null
+++ b/test/files/presentation/scope-completion-1/src/Completions.scala
@@ -0,0 +1,12 @@
+package test
+
+/* completion on empty class and object */
+
+class Completion1 {
+ /*_*/
+}
+
+object Completion2 {
+ /*_*/
+}
+
diff --git a/test/files/presentation/scope-completion-2.check b/test/files/presentation/scope-completion-2.check
new file mode 100644
index 0000000000..3a1dbd7cff
--- /dev/null
+++ b/test/files/presentation/scope-completion-2.check
@@ -0,0 +1,35 @@
+reload: Completions.scala
+
+askScopeCompletion at Completions.scala(16,4)
+================================================================================
+[response] askScopeCompletion at (16,4)
+retrieved 11 members
+class Completion1 extends AnyRef
+def <init>(): test.Completion1
+def test: Unit
+object Completion1
+private class Cc1 extends AnyRef
+private class Co1 extends AnyRef
+private def fc1: Int
+private def fo1: Int
+private[this] val c: test.Completion1
+private[this] val vc1: Int
+private[this] val vo1: Int
+================================================================================
+
+askScopeCompletion at Completions.scala(32,4)
+================================================================================
+[response] askScopeCompletion at (32,4)
+retrieved 11 members
+[inaccessible] private[this] val vc1: Int
+class Completion1 extends AnyRef
+def <init>(): test.Completion1.type
+def test: Unit
+object Completion1
+private class Cc1 extends AnyRef
+private class Co1 extends AnyRef
+private def fc1: Int
+private def fo1: Int
+private[this] val c: test.Completion1
+private[this] val vo1: Int
+================================================================================
diff --git a/test/files/presentation/scope-completion-2/Test.scala b/test/files/presentation/scope-completion-2/Test.scala
new file mode 100644
index 0000000000..bec1131c4c
--- /dev/null
+++ b/test/files/presentation/scope-completion-2/Test.scala
@@ -0,0 +1,3 @@
+import scala.tools.nsc.interactive.tests.InteractiveTest
+
+object Test extends InteractiveTest \ No newline at end of file
diff --git a/test/files/presentation/scope-completion-2/src/Completions.scala b/test/files/presentation/scope-completion-2/src/Completions.scala
new file mode 100644
index 0000000000..96d38f1b85
--- /dev/null
+++ b/test/files/presentation/scope-completion-2/src/Completions.scala
@@ -0,0 +1,35 @@
+package test
+
+/* private elements are visible in the companion class/object */
+
+class Completion1 {
+
+ import Completion1._
+
+ private val vc1 = 0
+ private def fc1 = 0
+
+ private class Cc1
+
+ def test {
+ // needs to be done in a method, because of SI-7280
+ /*_*/
+ }
+}
+
+object Completion1 {
+
+ val c = new Completion1()
+ import c._
+
+ private val vo1 = 0
+ private def fo1 = 0
+
+ private class Co1
+
+ def test {
+ // needs to be done in a method, because of SI-7280
+ /*_*/
+ }
+}
+
diff --git a/test/files/presentation/scope-completion-3.check b/test/files/presentation/scope-completion-3.check
new file mode 100644
index 0000000000..cf73e89a3b
--- /dev/null
+++ b/test/files/presentation/scope-completion-3.check
@@ -0,0 +1,111 @@
+reload: Completions.scala
+
+askScopeCompletion at Completions.scala(75,2)
+================================================================================
+[response] askScopeCompletion at (75,2)
+retrieved 49 members
+[inaccessible] private class Cb2 extends AnyRef
+[inaccessible] private class Ct2 extends AnyRef
+[inaccessible] private def fb2: Int
+[inaccessible] private def ft2: Int
+[inaccessible] private object Ob2
+[inaccessible] private object Ot2
+[inaccessible] private type tb2 = Completion1.this.tb2
+[inaccessible] private type tt2 = Completion1.this.tt2
+[inaccessible] private[this] val vb1: Int
+[inaccessible] private[this] val vb2: Int
+[inaccessible] private[this] val vt1: Int
+[inaccessible] private[this] val vt2: Int
+[inaccessible] private[this] var rb1: Int
+[inaccessible] private[this] var rb2: Int
+[inaccessible] private[this] var rt1: Int
+[inaccessible] private[this] var rt2: Int
+abstract class Base1 extends AnyRef
+abstract trait Trait1 extends AnyRef
+class Cb1 extends AnyRef
+class Cc1 extends AnyRef
+class Completion1 extends Base1 with Trait1
+class Ct1 extends AnyRef
+def <init>(): test.Completion1
+def fb1: Int
+def fc1: Int
+def ft1: Int
+object Completion2
+object Ob1
+object Oc1
+object Ot1
+override def fb3: Int
+override def ft3: Int
+override type tb3 = Completion1.this.tb3
+override type tt3 = Completion1.this.tt3
+private class Cc2 extends AnyRef
+private def fc2: Int
+private object Oc2
+private type tc2 = Completion1.this.tc2
+private[this] val vb3: Int
+private[this] val vc1: Int
+private[this] val vc2: Int
+private[this] val vt3: Int
+private[this] var rb3: Int
+private[this] var rc1: Int
+private[this] var rc2: Int
+private[this] var rt3: Int
+type tb1 = Completion1.this.tb1
+type tc1 = Completion1.this.tc1
+type tt1 = Completion1.this.tt1
+================================================================================
+
+askScopeCompletion at Completions.scala(104,2)
+================================================================================
+[response] askScopeCompletion at (104,2)
+retrieved 49 members
+[inaccessible] private class Cb2 extends AnyRef
+[inaccessible] private class Ct2 extends AnyRef
+[inaccessible] private def fb2: Int
+[inaccessible] private def ft2: Int
+[inaccessible] private object Ob2
+[inaccessible] private object Ot2
+[inaccessible] private type tb2 = test.Completion2.tb2
+[inaccessible] private type tt2 = test.Completion2.tt2
+[inaccessible] private[this] val vb1: Int
+[inaccessible] private[this] val vb2: Int
+[inaccessible] private[this] val vt1: Int
+[inaccessible] private[this] val vt2: Int
+[inaccessible] private[this] var rb1: Int
+[inaccessible] private[this] var rb2: Int
+[inaccessible] private[this] var rt1: Int
+[inaccessible] private[this] var rt2: Int
+abstract class Base1 extends AnyRef
+abstract trait Trait1 extends AnyRef
+class Cb1 extends AnyRef
+class Co1 extends AnyRef
+class Completion1 extends Base1 with Trait1
+class Ct1 extends AnyRef
+def <init>(): test.Completion2.type
+def fb1: Int
+def fo1: Int
+def ft1: Int
+object Completion2
+object Ob1
+object Oo1
+object Ot1
+override def fb3: Int
+override def ft3: Int
+override type tb3 = test.Completion2.tb3
+override type tt3 = test.Completion2.tt3
+private class Co2 extends AnyRef
+private def fo2: Int
+private object Oo2
+private type to2 = test.Completion2.to2
+private[this] val vb3: Int
+private[this] val vo1: Int
+private[this] val vo2: Int
+private[this] val vt3: Int
+private[this] var rb3: Int
+private[this] var ro1: Int
+private[this] var ro2: Int
+private[this] var rt3: Int
+type tb1 = test.Completion2.tb1
+type to1 = test.Completion2.to1
+type tt1 = test.Completion2.tt1
+================================================================================
diff --git a/test/files/presentation/scope-completion-3/Test.scala b/test/files/presentation/scope-completion-3/Test.scala
new file mode 100644
index 0000000000..bec1131c4c
--- /dev/null
+++ b/test/files/presentation/scope-completion-3/Test.scala
@@ -0,0 +1,3 @@
+import scala.tools.nsc.interactive.tests.InteractiveTest
+
+object Test extends InteractiveTest \ No newline at end of file
diff --git a/test/files/presentation/scope-completion-3/src/Completions.scala b/test/files/presentation/scope-completion-3/src/Completions.scala
new file mode 100644
index 0000000000..18cef1cefa
--- /dev/null
+++ b/test/files/presentation/scope-completion-3/src/Completions.scala
@@ -0,0 +1,106 @@
+package test
+
+/* check availability of members defined locally and in hierachy */
+
+abstract class Base1 {
+
+ type tb1 = Int
+ val vb1 = 0
+ var rb1 = 0
+ def fb1 = 0
+ class Cb1
+ object Ob1
+
+ private type tb2 = Int
+ private val vb2 = 0
+ private var rb2 = 0
+ private def fb2 = 0
+ private class Cb2
+ private object Ob2
+
+ type tb3
+ val vb3: Int
+ var rb3: Int
+ def fb3: Int
+}
+
+trait Trait1 {
+
+ type tt1 = Int
+ val vt1 = 0
+ var rt1 = 0
+ def ft1 = 0
+ class Ct1
+ object Ot1
+
+ private type tt2 = Int
+ private val vt2 = 0
+ private var rt2 = 0
+ private def ft2 = 0
+ private class Ct2
+ private object Ot2
+
+ type tt3
+ val vt3: Int
+ var rt3: Int
+ def ft3: Int
+}
+
+class Completion1 extends Base1 with Trait1 {
+
+ type tc1 = Int
+ val vc1 = 0
+ var rc1 = 0
+ def fc1 = 0
+ class Cc1
+ object Oc1
+
+ private type tc2 = Int
+ private val vc2 = 0
+ private var rc2 = 0
+ private def fc2 = 0
+ private class Cc2
+ private object Oc2
+
+ override type tb3 = Int
+ override val vb3 = 12
+ override var rb3 = 12
+ override def fb3 = 12
+
+ override type tt3 = Int
+ override val vt3 = 12
+ override var rt3 = 12
+ override def ft3 = 12
+
+ /*_*/
+}
+
+object Completion2 extends Base1 with Trait1 {
+
+ type to1 = Int
+ val vo1 = 0
+ var ro1 = 0
+ def fo1 = 0
+ class Co1
+ object Oo1
+
+ private type to2 = Int
+ private val vo2 = 0
+ private var ro2 = 0
+ private def fo2 = 0
+ private class Co2
+ private object Oo2
+
+ override type tb3 = Int
+ override val vb3 = 12
+ override var rb3 = 12
+ override def fb3 = 12
+
+ override type tt3 = Int
+ override val vt3 = 12
+ override var rt3 = 12
+ override def ft3 = 12
+
+ /*_*/
+}
+
diff --git a/test/files/presentation/scope-completion-4.check b/test/files/presentation/scope-completion-4.check
new file mode 100644
index 0000000000..59c47464c4
--- /dev/null
+++ b/test/files/presentation/scope-completion-4.check
@@ -0,0 +1,293 @@
+reload: Completions.scala
+
+askScopeCompletion at Completions.scala(12,8)
+================================================================================
+[response] askScopeCompletion at (12,8)
+retrieved 8 members
+class Completion1 extends AnyRef
+class c extends AnyRef
+class fc extends AnyRef
+class ffc extends AnyRef
+def <init>(): test.Completion1
+def f: Unit
+def ff: Unit
+def fff: Unit
+================================================================================
+
+askScopeCompletion at Completions.scala(15,6)
+================================================================================
+[response] askScopeCompletion at (15,6)
+retrieved 8 members
+class Completion1 extends AnyRef
+class c extends AnyRef
+class fc extends AnyRef
+class ffc extends AnyRef
+def <init>(): test.Completion1
+def f: Unit
+def ff: Unit
+def fff: Unit
+================================================================================
+
+askScopeCompletion at Completions.scala(18,8)
+================================================================================
+[response] askScopeCompletion at (18,8)
+retrieved 8 members
+class Completion1 extends AnyRef
+class c extends AnyRef
+class fc extends AnyRef
+class ffc extends AnyRef
+def <init>(): ffc
+def f: Unit
+def ff: Unit
+def fff: Unit
+================================================================================
+
+askScopeCompletion at Completions.scala(21,6)
+================================================================================
+[response] askScopeCompletion at (21,6)
+retrieved 8 members
+class Completion1 extends AnyRef
+class c extends AnyRef
+class fc extends AnyRef
+class ffc extends AnyRef
+def <init>(): test.Completion1
+def f: Unit
+def ff: Unit
+def fff: Unit
+================================================================================
+
+askScopeCompletion at Completions.scala(24,4)
+================================================================================
+[response] askScopeCompletion at (24,4)
+retrieved 6 members
+class Completion1 extends AnyRef
+class c extends AnyRef
+class fc extends AnyRef
+def <init>(): test.Completion1
+def f: Unit
+def ff: Unit
+================================================================================
+
+askScopeCompletion at Completions.scala(29,8)
+================================================================================
+[response] askScopeCompletion at (29,8)
+retrieved 8 members
+class Completion1 extends AnyRef
+class c extends AnyRef
+class fc extends AnyRef
+class fcc extends AnyRef
+def <init>(): fc
+def f: Unit
+def fcf: Unit
+def ff: Unit
+================================================================================
+
+askScopeCompletion at Completions.scala(32,6)
+================================================================================
+[response] askScopeCompletion at (32,6)
+retrieved 8 members
+class Completion1 extends AnyRef
+class c extends AnyRef
+class fc extends AnyRef
+class fcc extends AnyRef
+def <init>(): fc
+def f: Unit
+def fcf: Unit
+def ff: Unit
+================================================================================
+
+askScopeCompletion at Completions.scala(35,8)
+================================================================================
+[response] askScopeCompletion at (35,8)
+retrieved 8 members
+class Completion1 extends AnyRef
+class c extends AnyRef
+class fc extends AnyRef
+class fcc extends AnyRef
+def <init>(): fc.this.fcc
+def f: Unit
+def fcf: Unit
+def ff: Unit
+================================================================================
+
+askScopeCompletion at Completions.scala(38,6)
+================================================================================
+[response] askScopeCompletion at (38,6)
+retrieved 8 members
+class Completion1 extends AnyRef
+class c extends AnyRef
+class fc extends AnyRef
+class fcc extends AnyRef
+def <init>(): fc
+def f: Unit
+def fcf: Unit
+def ff: Unit
+================================================================================
+
+askScopeCompletion at Completions.scala(41,4)
+================================================================================
+[response] askScopeCompletion at (41,4)
+retrieved 6 members
+class Completion1 extends AnyRef
+class c extends AnyRef
+class fc extends AnyRef
+def <init>(): test.Completion1
+def f: Unit
+def ff: Unit
+================================================================================
+
+askScopeCompletion at Completions.scala(44,2)
+================================================================================
+[response] askScopeCompletion at (44,2)
+retrieved 4 members
+class Completion1 extends AnyRef
+class c extends AnyRef
+def <init>(): test.Completion1
+def f: Unit
+================================================================================
+
+askScopeCompletion at Completions.scala(51,8)
+================================================================================
+[response] askScopeCompletion at (51,8)
+retrieved 8 members
+class Completion1 extends AnyRef
+class c extends AnyRef
+class cc extends AnyRef
+class ccc extends AnyRef
+def <init>(): cc.this.ccc
+def ccf: Unit
+def cf: Unit
+def f: Unit
+================================================================================
+
+askScopeCompletion at Completions.scala(54,6)
+================================================================================
+[response] askScopeCompletion at (54,6)
+retrieved 8 members
+class Completion1 extends AnyRef
+class c extends AnyRef
+class cc extends AnyRef
+class ccc extends AnyRef
+def <init>(): c.this.cc
+def ccf: Unit
+def cf: Unit
+def f: Unit
+================================================================================
+
+askScopeCompletion at Completions.scala(57,8)
+================================================================================
+[response] askScopeCompletion at (57,8)
+retrieved 8 members
+class Completion1 extends AnyRef
+class c extends AnyRef
+class cc extends AnyRef
+class ccc extends AnyRef
+def <init>(): c.this.cc
+def ccf: Unit
+def cf: Unit
+def f: Unit
+================================================================================
+
+askScopeCompletion at Completions.scala(60,6)
+================================================================================
+[response] askScopeCompletion at (60,6)
+retrieved 8 members
+class Completion1 extends AnyRef
+class c extends AnyRef
+class cc extends AnyRef
+class ccc extends AnyRef
+def <init>(): c.this.cc
+def ccf: Unit
+def cf: Unit
+def f: Unit
+================================================================================
+
+askScopeCompletion at Completions.scala(63,4)
+================================================================================
+[response] askScopeCompletion at (63,4)
+retrieved 6 members
+class Completion1 extends AnyRef
+class c extends AnyRef
+class cc extends AnyRef
+def <init>(): Completion1.this.c
+def cf: Unit
+def f: Unit
+================================================================================
+
+askScopeCompletion at Completions.scala(68,8)
+================================================================================
+[response] askScopeCompletion at (68,8)
+retrieved 8 members
+class Completion1 extends AnyRef
+class c extends AnyRef
+class cc extends AnyRef
+class cfc extends AnyRef
+def <init>(): cfc
+def cf: Unit
+def cff: Unit
+def f: Unit
+================================================================================
+
+askScopeCompletion at Completions.scala(71,6)
+================================================================================
+[response] askScopeCompletion at (71,6)
+retrieved 8 members
+class Completion1 extends AnyRef
+class c extends AnyRef
+class cc extends AnyRef
+class cfc extends AnyRef
+def <init>(): Completion1.this.c
+def cf: Unit
+def cff: Unit
+def f: Unit
+================================================================================
+
+askScopeCompletion at Completions.scala(74,8)
+================================================================================
+[response] askScopeCompletion at (74,8)
+retrieved 8 members
+class Completion1 extends AnyRef
+class c extends AnyRef
+class cc extends AnyRef
+class cfc extends AnyRef
+def <init>(): Completion1.this.c
+def cf: Unit
+def cff: Unit
+def f: Unit
+================================================================================
+
+askScopeCompletion at Completions.scala(77,6)
+================================================================================
+[response] askScopeCompletion at (77,6)
+retrieved 8 members
+class Completion1 extends AnyRef
+class c extends AnyRef
+class cc extends AnyRef
+class cfc extends AnyRef
+def <init>(): Completion1.this.c
+def cf: Unit
+def cff: Unit
+def f: Unit
+================================================================================
+
+askScopeCompletion at Completions.scala(80,4)
+================================================================================
+[response] askScopeCompletion at (80,4)
+retrieved 6 members
+class Completion1 extends AnyRef
+class c extends AnyRef
+class cc extends AnyRef
+def <init>(): Completion1.this.c
+def cf: Unit
+def f: Unit
+================================================================================
+
+askScopeCompletion at Completions.scala(83,2)
+================================================================================
+[response] askScopeCompletion at (83,2)
+retrieved 4 members
+class Completion1 extends AnyRef
+class c extends AnyRef
+def <init>(): test.Completion1
+def f: Unit
+================================================================================
diff --git a/test/files/presentation/scope-completion-4/Test.scala b/test/files/presentation/scope-completion-4/Test.scala
new file mode 100644
index 0000000000..bec1131c4c
--- /dev/null
+++ b/test/files/presentation/scope-completion-4/Test.scala
@@ -0,0 +1,3 @@
+import scala.tools.nsc.interactive.tests.InteractiveTest
+
+object Test extends InteractiveTest \ No newline at end of file
diff --git a/test/files/presentation/scope-completion-4/src/Completions.scala b/test/files/presentation/scope-completion-4/src/Completions.scala
new file mode 100644
index 0000000000..d11315720a
--- /dev/null
+++ b/test/files/presentation/scope-completion-4/src/Completions.scala
@@ -0,0 +1,84 @@
+package test
+
+/* check that members defined in sub-block are not visible*/
+
+class Completion1 {
+
+ def f {
+
+ def ff {
+
+ def fff {
+ /*_*/
+ }
+
+ /*_*/
+
+ class ffc {
+ /*_*/
+ }
+
+ /*_*/
+ }
+
+ /*_*/
+
+ class fc {
+
+ def fcf {
+ /*_*/
+ }
+
+ /*_*/
+
+ class fcc {
+ /*_*/
+ }
+
+ /*_*/
+ }
+
+ /*_*/
+ }
+
+ /*_*/
+
+ class c {
+
+ class cc {
+
+ class ccc {
+ /*_*/
+ }
+
+ /*_*/
+
+ def ccf {
+ /*_*/
+ }
+
+ /*_*/
+ }
+
+ /*_*/
+
+ def cf {
+
+ class cfc {
+ /*_*/
+ }
+
+ /*_*/
+
+ def cff {
+ /*_*/
+ }
+
+ /*_*/
+ }
+
+ /*_*/
+ }
+
+ /*_*/
+}
diff --git a/test/files/presentation/scope-completion-import.check b/test/files/presentation/scope-completion-import.check
new file mode 100644
index 0000000000..d518b0c37a
--- /dev/null
+++ b/test/files/presentation/scope-completion-import.check
@@ -0,0 +1,141 @@
+reload: Completions.scala
+
+askScopeCompletion at Completions.scala(15,4)
+================================================================================
+[response] askScopeCompletion at (15,4)
+retrieved 10 members
+class C extends AnyRef
+class Foo extends AnyRef
+class Foo_1 extends AnyRef
+class Foo_2 extends AnyRef
+class Foo_3 extends AnyRef
+def <init>(): test.Foo
+def fCCC: Int
+def fOOO: Int
+object O
+val o: test.O.type
+================================================================================
+
+askScopeCompletion at Completions.scala(19,4)
+================================================================================
+[response] askScopeCompletion at (19,4)
+retrieved 9 members
+class C extends AnyRef
+class Foo extends AnyRef
+class Foo_1 extends AnyRef
+class Foo_2 extends AnyRef
+class Foo_3 extends AnyRef
+def <init>(): test.Foo
+def fCCC: Int
+def fOOO: Int
+object O
+================================================================================
+
+askScopeCompletion at Completions.scala(24,4)
+================================================================================
+[response] askScopeCompletion at (24,4)
+retrieved 9 members
+class C extends AnyRef
+class Foo extends AnyRef
+class Foo_1 extends AnyRef
+class Foo_2 extends AnyRef
+class Foo_3 extends AnyRef
+def <init>(): test.Foo
+def fCCC: Int
+object O
+val c: test.C
+================================================================================
+
+askScopeCompletion at Completions.scala(27,5)
+================================================================================
+[response] askScopeCompletion at (27,5)
+retrieved 8 members
+class C extends AnyRef
+class Foo extends AnyRef
+class Foo_1 extends AnyRef
+class Foo_2 extends AnyRef
+class Foo_3 extends AnyRef
+def <init>(): test.Foo
+object O
+val c: test.C
+================================================================================
+
+askScopeCompletion at Completions.scala(30,5)
+================================================================================
+[response] askScopeCompletion at (30,5)
+retrieved 9 members
+class C extends AnyRef
+class Foo extends AnyRef
+class Foo_1 extends AnyRef
+class Foo_2 extends AnyRef
+class Foo_3 extends AnyRef
+def <init>(): test.Foo
+def fCCC: Int
+object O
+val c: test.C
+================================================================================
+
+askScopeCompletion at Completions.scala(32,5)
+================================================================================
+[response] askScopeCompletion at (32,5)
+retrieved 10 members
+class C extends AnyRef
+class Foo extends AnyRef
+class Foo_1 extends AnyRef
+class Foo_2 extends AnyRef
+class Foo_3 extends AnyRef
+def <init>(): test.Foo
+def fCCC: Int
+def fOOO: Int
+object O
+val c: test.C
+================================================================================
+
+askScopeCompletion at Completions.scala(41,4)
+================================================================================
+[response] askScopeCompletion at (41,4)
+retrieved 10 members
+class C extends AnyRef
+class Foo extends AnyRef
+class Foo_1 extends AnyRef
+class Foo_2 extends AnyRef
+class Foo_3 extends AnyRef
+def <init>(): test.Foo_1
+def bar: Unit
+def fCCC: Int
+def fOOO: Int
+object O
+================================================================================
+
+askScopeCompletion at Completions.scala(51,4)
+================================================================================
+[response] askScopeCompletion at (51,4)
+retrieved 11 members
+class C extends AnyRef
+class Foo extends AnyRef
+class Foo_1 extends AnyRef
+class Foo_2 extends AnyRef
+class Foo_3 extends AnyRef
+def <init>(): test.Foo_2
+def bar: Unit
+def fCCC: Int
+def fOOO: Int
+object O
+private[this] val o: test.O.type
+================================================================================
+
+askScopeCompletion at Completions.scala(61,4)
+================================================================================
+[response] askScopeCompletion at (61,4)
+retrieved 10 members
+class C extends AnyRef
+class Foo extends AnyRef
+class Foo_1 extends AnyRef
+class Foo_2 extends AnyRef
+class Foo_3 extends AnyRef
+def <init>(): test.Foo_3
+def bar: Unit
+def fCCC: Int
+object O
+private[this] val c: test.C
+================================================================================
diff --git a/test/files/presentation/scope-completion-import/Test.scala b/test/files/presentation/scope-completion-import/Test.scala
new file mode 100644
index 0000000000..bec1131c4c
--- /dev/null
+++ b/test/files/presentation/scope-completion-import/Test.scala
@@ -0,0 +1,3 @@
+import scala.tools.nsc.interactive.tests.InteractiveTest
+
+object Test extends InteractiveTest \ No newline at end of file
diff --git a/test/files/presentation/scope-completion-import/src/Completions.scala b/test/files/presentation/scope-completion-import/src/Completions.scala
new file mode 100644
index 0000000000..6e08321283
--- /dev/null
+++ b/test/files/presentation/scope-completion-import/src/Completions.scala
@@ -0,0 +1,64 @@
+package test
+
+class C {
+ def fCCC : Int = 0
+}
+
+object O extends C {
+ def fOOO : Int = 0
+}
+
+class Foo {
+ {
+ val o = O
+ import o._
+ /*_*/
+ }
+ {
+ import O._
+ /*_*/
+ }
+ {
+ val c = new C
+ import c._
+ /*_*/
+ }
+ {
+ f/*_*/
+ val c = new C
+ import c._
+ f/*_*/
+ import O._
+ f/*_*/
+ }
+}
+
+class Foo_1 {
+
+ import O._
+
+ def bar {
+ /*_*/
+ }
+}
+
+class Foo_2 {
+
+ val o = O
+ import o._
+
+ def bar {
+ /*_*/
+ }
+}
+
+class Foo_3 {
+
+ val c = new C
+ import c._
+
+ def bar {
+ /*_*/
+ }
+}
+
diff --git a/test/files/presentation/t1207.check b/test/files/presentation/t1207.check
index 84bfd79d75..0eed4ece04 100644
--- a/test/files/presentation/t1207.check
+++ b/test/files/presentation/t1207.check
@@ -2,7 +2,7 @@ reload: Completions.scala
askTypeCompletion at Completions.scala(10,15)
================================================================================
-[response] askCompletionAt (10,15)
+[response] askTypeCompletion at (10,15)
retrieved 3 members
final package bongo
final package lang
@@ -11,7 +11,7 @@ final package util
askTypeCompletion at Completions.scala(11,16)
================================================================================
-[response] askCompletionAt (11,16)
+[response] askTypeCompletion at (11,16)
retrieved 3 members
final package bongo
final package lang
@@ -20,7 +20,7 @@ final package util
askTypeCompletion at Completions.scala(12,19)
================================================================================
-[response] askCompletionAt (12,19)
+[response] askTypeCompletion at (12,19)
retrieved 3 members
final package bongo
final package lang
@@ -29,7 +29,7 @@ final package util
askTypeCompletion at Completions.scala(13,19)
================================================================================
-[response] askCompletionAt (13,19)
+[response] askTypeCompletion at (13,19)
retrieved 3 members
final package bongo
final package lang
@@ -38,7 +38,7 @@ final package util
askTypeCompletion at Completions.scala(14,23)
================================================================================
-[response] askCompletionAt (14,23)
+[response] askTypeCompletion at (14,23)
retrieved 3 members
final package bongo
final package lang
@@ -47,7 +47,7 @@ final package util
askTypeCompletion at Completions.scala(15,10)
================================================================================
-[response] askCompletionAt (15,10)
+[response] askTypeCompletion at (15,10)
retrieved 0 members
================================================================================
diff --git a/test/files/presentation/t5708.check b/test/files/presentation/t5708.check
index 5f17c0b762..04806b5867 100644
--- a/test/files/presentation/t5708.check
+++ b/test/files/presentation/t5708.check
@@ -2,7 +2,7 @@ reload: Completions.scala
askTypeCompletion at Completions.scala(17,9)
================================================================================
-[response] askCompletionAt (17,9)
+[response] askTypeCompletion at (17,9)
retrieved 39 members
[inaccessible] private def privateM: String
[inaccessible] private[this] val privateV: String
diff --git a/test/files/presentation/t7915.check b/test/files/presentation/t7915.check
new file mode 100644
index 0000000000..b18b4ddb55
--- /dev/null
+++ b/test/files/presentation/t7915.check
@@ -0,0 +1,11 @@
+reload: Foo.scala
+
+askHyperlinkPos for `Bar` at (7,11) Foo.scala
+================================================================================
+[response] found askHyperlinkPos for `Bar` at (1,7) Foo.scala
+================================================================================
+
+askHyperlinkPos for `bar` at (7,22) Foo.scala
+================================================================================
+[response] found askHyperlinkPos for `bar` at (2,7) Foo.scala
+================================================================================
diff --git a/test/files/presentation/t7915/Test.scala b/test/files/presentation/t7915/Test.scala
new file mode 100644
index 0000000000..c2f89bdb17
--- /dev/null
+++ b/test/files/presentation/t7915/Test.scala
@@ -0,0 +1,8 @@
+import scala.tools.nsc.interactive.tests.InteractiveTest
+
+object Test extends InteractiveTest {
+ override def runDefaultTests() {
+ sourceFiles foreach (src => askLoadedTyped(src).get)
+ super.runDefaultTests()
+ }
+}
diff --git a/test/files/presentation/t7915/src/Foo.scala b/test/files/presentation/t7915/src/Foo.scala
new file mode 100644
index 0000000000..a4166ae5b4
--- /dev/null
+++ b/test/files/presentation/t7915/src/Foo.scala
@@ -0,0 +1,9 @@
+class Bar {
+ def bar(b: Int = 2) {}
+}
+
+class Foo {
+ def foo() {
+ new Bar/*#*/().bar/*#*/()
+ }
+}
diff --git a/test/files/presentation/visibility.check b/test/files/presentation/visibility.check
index 078e0a2342..217da34b9c 100644
--- a/test/files/presentation/visibility.check
+++ b/test/files/presentation/visibility.check
@@ -2,7 +2,7 @@ reload: Completions.scala
askTypeCompletion at Completions.scala(14,12)
================================================================================
-[response] askCompletionAt (14,12)
+[response] askTypeCompletion at (14,12)
retrieved 37 members
[inaccessible] private[this] def secretPrivateThis(): Unit
def +(other: String): String
@@ -42,7 +42,7 @@ protected[package lang] def finalize(): Unit
askTypeCompletion at Completions.scala(16,11)
================================================================================
-[response] askCompletionAt (16,11)
+[response] askTypeCompletion at (16,11)
retrieved 37 members
def +(other: String): String
def ->[B](y: B): (accessibility.Foo, B)
@@ -82,7 +82,7 @@ protected[package lang] def finalize(): Unit
askTypeCompletion at Completions.scala(22,11)
================================================================================
-[response] askCompletionAt (22,11)
+[response] askTypeCompletion at (22,11)
retrieved 37 members
[inaccessible] private def secretPrivate(): Unit
def +(other: String): String
@@ -122,7 +122,7 @@ protected[package lang] def finalize(): Unit
askTypeCompletion at Completions.scala(28,10)
================================================================================
-[response] askCompletionAt (28,10)
+[response] askTypeCompletion at (28,10)
retrieved 37 members
[inaccessible] private def secretPrivate(): Unit
[inaccessible] private[this] def secretPrivateThis(): Unit
@@ -162,7 +162,7 @@ protected[package accessibility] def secretProtectedInPackage(): Unit
askTypeCompletion at Completions.scala(37,8)
================================================================================
-[response] askCompletionAt (37,8)
+[response] askTypeCompletion at (37,8)
retrieved 37 members
[inaccessible] private def secretPrivate(): Unit
[inaccessible] private[this] def secretPrivateThis(): Unit
diff --git a/test/files/run/fors.check b/test/files/run/fors.check
new file mode 100644
index 0000000000..b459f00b49
--- /dev/null
+++ b/test/files/run/fors.check
@@ -0,0 +1,28 @@
+
+testOld
+1 2 3
+2
+2
+3
+1 2 3
+1 2 3
+0 1 2 3 4 5 6 7 8 9
+0 2 4 6 8
+0 2 4 6 8
+a b c
+b c
+b c
+
+testNew
+3
+1 2 3
+1 2 3
+0 1 2 3 4 5 6 7 8 9
+0 2 4 6 8
+0 2 4 6 8
+0 2 4 6 8
+0 2 4 6 8
+0 2 4 6 8
+0 2 4 6 8
+0 2 4 6 8
+a b c
diff --git a/test/files/run/fors.scala b/test/files/run/fors.scala
new file mode 100644
index 0000000000..c778df3e24
--- /dev/null
+++ b/test/files/run/fors.scala
@@ -0,0 +1,84 @@
+//############################################################################
+// for-comprehensions (old and new syntax)
+//############################################################################
+
+//############################################################################
+
+object Test extends App {
+ val xs = List(1, 2, 3)
+ val ys = List('a, 'b, 'c)
+
+ def it = 0 until 10
+
+ val ar = "abc".toCharArray
+
+ /////////////////// old syntax ///////////////////
+
+ def testOld {
+ println("\ntestOld")
+
+ // lists
+ for (x <- xs) print(x + " "); println
+ for (x <- xs;
+ if x % 2 == 0) print(x + " "); println
+ for {x <- xs
+ if x % 2 == 0} print(x + " "); println
+ var n = 0
+ for (_ <- xs) n += 1; println(n)
+ for ((x, y) <- xs zip ys) print(x + " "); println
+ for (p @ (x, y) <- xs zip ys) print(p._1 + " "); println
+
+ // iterators
+ for (x <- it) print(x + " "); println
+ for (x <- it;
+ if x % 2 == 0) print(x + " "); println
+ for {x <- it
+ if x % 2 == 0} print(x + " "); println
+
+ // arrays
+ for (x <- ar) print(x + " "); println
+ for (x <- ar;
+ if x.toInt > 97) print(x + " "); println
+ for {x <- ar
+ if x.toInt > 97} print(x + " "); println
+
+ }
+
+ /////////////////// new syntax ///////////////////
+
+ def testNew {
+ println("\ntestNew")
+
+ // lists
+ var n = 0
+ for (_ <- xs) n += 1; println(n)
+ for ((x, y) <- xs zip ys) print(x + " "); println
+ for (p @ (x, y) <- xs zip ys) print(p._1 + " "); println
+
+ // iterators
+ for (x <- it) print(x + " "); println
+ for (x <- it if x % 2 == 0) print(x + " "); println
+ for (x <- it; if x % 2 == 0) print(x + " "); println
+ for (x <- it;
+ if x % 2 == 0) print(x + " "); println
+ for (x <- it
+ if x % 2 == 0) print(x + " "); println
+ for {x <- it
+ if x % 2 == 0} print(x + " "); println
+ for (x <- it;
+ y = 2
+ if x % y == 0) print(x + " "); println
+ for {x <- it
+ y = 2
+ if x % y == 0} print(x + " "); println
+
+ // arrays
+ for (x <- ar) print(x + " "); println
+
+ }
+
+ ////////////////////////////////////////////////////
+
+ testOld
+ testNew
+}
diff --git a/test/files/run/mutable-anyrefmap.scala b/test/files/run/mutable-anyrefmap.scala
new file mode 100644
index 0000000000..ff615d0daf
--- /dev/null
+++ b/test/files/run/mutable-anyrefmap.scala
@@ -0,0 +1,91 @@
+object Test extends App {
+
+ import scala.collection.mutable.HashMap;
+ import scala.collection.mutable.AnyRefMap;
+
+ val keys = Array(
+ null, "perch", "herring", "salmon", "pike", "cod", ""
+ )
+
+ val rn = new scala.util.Random(42L)
+ var arm = AnyRefMap.empty[String, Int]
+ val hm = HashMap.empty[String, Int]
+
+ def checkConsistent = hm.forall{ case (k,v) => arm.get(k).exists(_ == v) }
+
+ assert {
+ (0 to 10000).forall{ i =>
+ val k = keys(rn.nextInt(keys.length))
+ if (rn.nextInt(100) < 2) arm = arm.clone()
+ if (rn.nextInt(100) < 5) arm.repack()
+ if (rn.nextBoolean) {
+ hm += ((k, i))
+ rn.nextInt(6) match {
+ case 0 => arm += ((k, i))
+ case 1 => arm += (k, i)
+ case 2 => arm(k) = i
+ case 3 => arm.put(k,i)
+ case 4 => arm ++= List((k,i))
+ case _ => if (!arm.contains(k)) arm.getOrElseUpdate(k,i)
+ else arm += (k,i)
+ }
+ }
+ else {
+ hm -= k
+ rn.nextInt(2) match {
+ case 0 => arm -= k
+ case _ => arm --= List(k)
+ }
+ }
+ checkConsistent
+ }
+ }
+
+ assert {
+ val mapped =
+ arm.map{ case (k,v) => (if (k==null) "" else k+k) -> v.toString }
+ mapped.getClass == arm.getClass
+ }
+
+ assert {
+ val arm2 = new AnyRefMap[java.lang.Integer,Unit](2000000)
+ for (i <- 0 until 1000000) arm2(java.lang.Integer.valueOf(i)) = ()
+
+ arm2.size == 1000000 &&
+ (0 to 1100000 by 100000).map(java.lang.Integer.valueOf).forall(i => (arm2 contains i) == i < 1000000)
+ }
+
+ arm = AnyRefMap("heron" -> 22, "dove" -> 5, "budgie" -> 0)
+
+ assert{
+ var s = ""
+ arm.foreachKey(s += _)
+
+ s.length == "herondovebudgie".length &&
+ s.contains("heron") &&
+ s.contains("dove") &&
+ s.contains("budgie")
+ }
+
+ assert{ var s = 0L; arm.foreachValue(s += _); s == 27L }
+
+ assert {
+ val m2 = arm.mapValuesNow(_+2)
+ arm.transformValues(_+2)
+ m2 == arm && !(m2 eq arm) && (for ((_,v) <- arm) yield v).sum == 33L
+ }
+
+ assert {
+ val arm2 = new AnyRefMap[String, String](x => if (x==null) "null" else x)
+ arm2 += ("cod" -> "fish", "Rarity" -> "unicorn")
+ val hm2 = (new HashMap[String,String]) ++= arm2
+
+ List(null, "cod", "sparrow", "Rarity").forall(i =>
+ arm2.get(i) == hm2.get(i) &&
+ arm2.getOrElse(i, "") == hm2.getOrElse(i, "") &&
+ arm2(i) == hm2.get(i).getOrElse(if (i==null) "null" else i.toString) &&
+ arm2.getOrNull(i) == hm2.get(i).orNull
+ )
+ }
+}
+
diff --git a/test/files/run/mutable-longmap.scala b/test/files/run/mutable-longmap.scala
new file mode 100644
index 0000000000..07fd80f6f0
--- /dev/null
+++ b/test/files/run/mutable-longmap.scala
@@ -0,0 +1,79 @@
+object Test extends App {
+
+ import scala.collection.mutable.HashMap;
+ import scala.collection.mutable.LongMap;
+
+ val keys = Array(
+ Long.MinValue, Int.MinValue - 1L, Int.MinValue, -9127, -1,
+ 0, 1, 9127, Int.MaxValue, Long.MaxValue
+ )
+
+ val rn = new scala.util.Random(42L)
+ var lm = LongMap.empty[Long]
+ val hm = HashMap.empty[Long,Long]
+
+ def checkConsistent = hm.forall{ case (k,v) => lm.get(k).exists(_ == v) }
+
+ assert {
+ (0 to 10000).forall{ i =>
+ val k = keys(rn.nextInt(keys.length))
+ if (rn.nextInt(100) < 2) lm = lm.clone()
+ if (rn.nextInt(100) < 5) lm.repack()
+ if (rn.nextBoolean) {
+ hm += ((k, i))
+ rn.nextInt(6) match {
+ case 0 => lm += ((k, i))
+ case 1 => lm += (k, i)
+ case 2 => lm(k) = i
+ case 3 => lm.put(k,i)
+ case 4 => lm ++= List((k,i))
+ case _ => if (!lm.contains(k)) lm.getOrElseUpdate(k,i)
+ else lm += (k,i)
+ }
+ }
+ else {
+ hm -= k
+ rn.nextInt(2) match {
+ case 0 => lm -= k
+ case _ => lm --= List(k)
+ }
+ }
+ checkConsistent
+ }
+ }
+
+ assert {
+ lm.map{ case (k,v) => -k*k -> v.toString }.getClass == lm.getClass
+ }
+
+ assert {
+ val lm2 = new LongMap[Unit](2000000)
+ for (i <- 0 until 1000000) lm2(i) = ()
+
+ lm2.size == 1000000 &&
+ (0 to 1100000 by 100000).forall(i => (lm2 contains i) == i < 1000000)
+ }
+
+ lm = LongMap(8L -> 22L, -5L -> 5L, Long.MinValue -> 0L)
+
+ assert{ var s = 0L; lm.foreachKey(s += _); s == Long.MinValue + 3 }
+ assert{ var s = 0L; lm.foreachValue(s += _); s == 27L }
+ assert {
+ val m2 = lm.mapValuesNow(_+2)
+ lm.transformValues(_+2)
+ m2 == lm && !(m2 eq lm) && (for ((_,v) <- lm) yield v).sum == 33L
+ }
+
+ assert {
+ val lm2 = new LongMap[String](_.toString)
+ lm2 += (5L -> "fish", 0L -> "unicorn")
+ val hm2 = (new HashMap[Long,String]) ++= lm2
+
+ List(Long.MinValue, 0L, 1L, 5L).forall(i =>
+ lm2.get(i) == hm2.get(i) &&
+ lm2.getOrElse(i, "") == hm2.getOrElse(i, "") &&
+ lm2(i) == hm2.get(i).getOrElse(i.toString) &&
+ lm2.getOrNull(i) == hm2.get(i).orNull
+ )
+ }
+}
diff --git a/test/files/run/repl-backticks.check b/test/files/run/repl-backticks.check
new file mode 100644
index 0000000000..c0561abd7c
--- /dev/null
+++ b/test/files/run/repl-backticks.check
@@ -0,0 +1,2 @@
+import java.lang.Thread.`yield`
+import scala.`package`.Throwable
diff --git a/test/files/run/repl-backticks.scala b/test/files/run/repl-backticks.scala
new file mode 100644
index 0000000000..e40a8bc662
--- /dev/null
+++ b/test/files/run/repl-backticks.scala
@@ -0,0 +1,18 @@
+import scala.tools.nsc._
+
+object Test {
+ val testCode = """
+ import java.lang.Thread.`yield`
+ import scala.`package`.Throwable
+
+ `yield`
+ """
+
+ def main(args: Array[String]) {
+ val settings = new Settings()
+ settings.classpath.value = System.getProperty("java.class.path")
+ val repl = new interpreter.IMain(settings)
+ repl.interpret(testCode)
+ }
+}
+
diff --git a/test/files/run/t1500.check b/test/files/run/t1500.check
new file mode 100644
index 0000000000..94a169333b
--- /dev/null
+++ b/test/files/run/t1500.check
@@ -0,0 +1,3 @@
+defined class posingAs
+resolve: [A, B](x: A @posingAs[B])B
+x: Any = 7
diff --git a/test/files/run/t1500.scala b/test/files/run/t1500.scala
new file mode 100644
index 0000000000..30c026f70f
--- /dev/null
+++ b/test/files/run/t1500.scala
@@ -0,0 +1,46 @@
+import scala.tools.nsc._
+
+object Test {
+
+ /**
+ * Type inference overlooks constraints posed by type parameters in annotations on types.
+ */
+
+ val testCode = """
+
+ class posingAs[A] extends annotation.TypeConstraint
+
+ def resolve[A,B](x: A @posingAs[B]): B = x.asInstanceOf[B]
+
+ val x = resolve(7: @posingAs[Any])
+
+ """
+
+ def main(args: Array[String]) {
+
+ val settings = new Settings()
+ settings.classpath.value = System.getProperty("java.class.path")
+ val tool = new interpreter.IMain(settings)
+ val global = tool.global
+
+ import global._
+ import definitions._
+
+ object checker extends AnnotationChecker {
+
+ /** Check annotations to decide whether tpe1 <:< tpe2 */
+ def annotationsConform(tpe1: Type, tpe2: Type): Boolean = {
+
+ tpe1.annotations.forall(a1 => tpe2.annotations.forall(a2 => a1.atp <:< a2.atp))
+
+ }
+ }
+
+ global.addAnnotationChecker(checker)
+
+ tool.interpret(testCode)
+
+ }
+
+}
+
diff --git a/test/files/run/t1501.check b/test/files/run/t1501.check
new file mode 100644
index 0000000000..f0fa9112a5
--- /dev/null
+++ b/test/files/run/t1501.check
@@ -0,0 +1,3 @@
+defined class xyz
+loopWhile: [T](cond: => Boolean)(body: => Unit @xyz[T])Unit @xyz[T]
+test: ()Unit @xyz[Int]
diff --git a/test/files/run/t1501.scala b/test/files/run/t1501.scala
new file mode 100644
index 0000000000..ca6bf357fb
--- /dev/null
+++ b/test/files/run/t1501.scala
@@ -0,0 +1,56 @@
+import scala.tools.nsc._
+
+object Test {
+
+ /**
+ * ...
+ */
+
+ val testCode = """
+
+ class xyz[A] extends annotation.TypeConstraint
+
+ def loopWhile[T](cond: =>Boolean)(body: =>(Unit @xyz[T])): Unit @ xyz[T] = {{
+ if (cond) {{
+ body
+ loopWhile[T](cond)(body)
+ }}
+ }}
+
+ def test() = {{
+ var x = 7
+ loopWhile(x != 0) {{
+ x = x - 1
+ (): @xyz[Int]
+ }}
+ }}
+
+ """
+
+ def main(args: Array[String]) {
+ val settings = new Settings()
+ settings.classpath.value = System.getProperty("java.class.path")
+ val tool = new interpreter.IMain(settings)
+ val global = tool.global
+
+ import global._
+ import definitions._
+
+ object checker extends AnnotationChecker {
+
+ /** Check annotations to decide whether tpe1 <:< tpe2 */
+ def annotationsConform(tpe1: Type, tpe2: Type): Boolean = {
+
+ tpe1.annotations.forall(a1 => tpe2.annotations.forall(a2 => a1.atp <:< a2.atp))
+
+ }
+ }
+
+ global.addAnnotationChecker(checker)
+
+ tool.interpret(testCode)
+
+ }
+
+}
+
diff --git a/test/files/run/t4124.check b/test/files/run/t4124.check
new file mode 100644
index 0000000000..66a0092d93
--- /dev/null
+++ b/test/files/run/t4124.check
@@ -0,0 +1,4 @@
+hi
+hi
+bye
+bye
diff --git a/test/files/run/t4124.scala b/test/files/run/t4124.scala
new file mode 100644
index 0000000000..9f35b57ce3
--- /dev/null
+++ b/test/files/run/t4124.scala
@@ -0,0 +1,24 @@
+import xml.Node
+
+object Test extends App {
+ val body: Node = <elem>hi</elem>
+ println ((body: AnyRef, "foo") match {
+ case (node: Node, "bar") => "bye"
+ case (ser: Serializable, "foo") => "hi"
+ })
+
+ println ((body, "foo") match {
+ case (node: Node, "bar") => "bye"
+ case (ser: Serializable, "foo") => "hi"
+ })
+
+ println ((body: AnyRef, "foo") match {
+ case (node: Node, "foo") => "bye"
+ case (ser: Serializable, "foo") => "hi"
+ })
+
+ println ((body: AnyRef, "foo") match {
+ case (node: Node, "foo") => "bye"
+ case (ser: Serializable, "foo") => "hi"
+ })
+}