diff options
Diffstat (limited to 'src')
14 files changed, 193 insertions, 49 deletions
diff --git a/src/compiler/scala/tools/nsc/settings/Warnings.scala b/src/compiler/scala/tools/nsc/settings/Warnings.scala index d174dc86c7..41ce0837cb 100644 --- a/src/compiler/scala/tools/nsc/settings/Warnings.scala +++ b/src/compiler/scala/tools/nsc/settings/Warnings.scala @@ -28,10 +28,11 @@ trait Warnings { val warnUnusedImport = BooleanSetting("-Ywarn-unused-import", "Warn when imports are unused.") // Experimental lint warnings that are turned off, but which could be turned on programmatically. - // These warnings are said to blind those who dare enable them. - // They are not activated by -Xlint and can't be enabled on the command line. - val warnValueOverrides = { // Currently turned off as experimental. Created using constructor (new BS), so not available on the command line. - val flag = new BooleanSetting("value-overrides", "Generated value class method overrides an implementation") + // They are not activated by -Xlint and can't be enabled on the command line because they are not + // created using the standard factory methods. + + val warnValueOverrides = { + val flag = new BooleanSetting("value-overrides", "Generated value class method overrides an implementation.") flag.value = false flag } @@ -53,10 +54,11 @@ trait Warnings { val TypeParameterShadow = LintWarning("type-parameter-shadow", "A local type parameter shadows a type already in scope.") val PolyImplicitOverload = LintWarning("poly-implicit-overload", "Parameterized overloaded implicit methods are not visible as view bounds.") val OptionImplicit = LintWarning("option-implicit", "Option.apply used implicit view.") - val DelayedInitSelect = LintWarning("delayedinit-select", "Selecting member of DelayedInit") + val DelayedInitSelect = LintWarning("delayedinit-select", "Selecting member of DelayedInit.") val ByNameRightAssociative = LintWarning("by-name-right-associative", "By-name parameter of right associative operator.") val PackageObjectClasses = LintWarning("package-object-classes", "Class or object defined in package object.") val UnsoundMatch = LintWarning("unsound-match", "Pattern match may not be typesafe.") + val StarsAlign = LintWarning("stars-align", "Pattern sequence wildcard must align with sequence component.") def allLintWarnings = values.toSeq.asInstanceOf[Seq[LintWarning]] } @@ -77,6 +79,7 @@ trait Warnings { def warnByNameRightAssociative = lint contains ByNameRightAssociative def warnPackageObjectClasses = lint contains PackageObjectClasses def warnUnsoundMatch = lint contains UnsoundMatch + def warnStarsAlign = lint contains StarsAlign // Lint warnings that are currently -Y, but deprecated in that usage @deprecated("Use warnAdaptedArgs", since="2.11.2") diff --git a/src/compiler/scala/tools/nsc/transform/patmat/PatternMatching.scala b/src/compiler/scala/tools/nsc/transform/patmat/PatternMatching.scala index d35aad964d..b2f2516b5b 100644 --- a/src/compiler/scala/tools/nsc/transform/patmat/PatternMatching.scala +++ b/src/compiler/scala/tools/nsc/transform/patmat/PatternMatching.scala @@ -239,6 +239,11 @@ trait Interface extends ast.TreeDSL { case Ident(_) => subst(from, to) case _ => super.transform(tree) } + tree1 match { + case _: DefTree => + tree1.symbol.modifyInfo(_.substituteTypes(from, toTypes)) + case _ => + } tree1.modifyType(_.substituteTypes(from, toTypes)) } } diff --git a/src/compiler/scala/tools/nsc/transform/patmat/ScalacPatternExpanders.scala b/src/compiler/scala/tools/nsc/transform/patmat/ScalacPatternExpanders.scala index 8924394b72..2753baa51d 100644 --- a/src/compiler/scala/tools/nsc/transform/patmat/ScalacPatternExpanders.scala +++ b/src/compiler/scala/tools/nsc/transform/patmat/ScalacPatternExpanders.scala @@ -110,8 +110,10 @@ trait ScalacPatternExpanders { err("Star pattern must correspond with varargs or unapplySeq") else if (elementArity < 0) arityError("not enough") - else if (elementArity > 0 && !extractor.hasSeq) + else if (elementArity > 0 && !isSeq) arityError("too many") + else if (settings.warnStarsAlign && isSeq && productArity > 0 && (elementArity > 0 || !isStar)) + warn("A repeated case parameter or extracted sequence should be matched only by a sequence wildcard (_*).") aligned } diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index e6fa9a0142..e4255e5333 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -825,6 +825,16 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper } orElse { _ => val resetTree = resetAttrs(original) + resetTree match { + case treeInfo.Applied(fun, targs, args) => + if (fun.symbol != null && fun.symbol.isError) + // SI-9041 Without this, we leak error symbols past the typer! + // because the fallback typechecking notices the error-symbol, + // refuses to re-attempt typechecking, and presumes that someone + // else was responsible for issuing the related type error! + fun.setSymbol(NoSymbol) + case _ => + } debuglog(s"fallback on implicits: ${tree}/$resetTree") val tree1 = typed(resetTree, mode) // Q: `typed` already calls `pluginsTyped` and `adapt`. the only difference here is that @@ -1177,7 +1187,7 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper } def instantiatePossiblyExpectingUnit(tree: Tree, mode: Mode, pt: Type): Tree = { - if (mode.typingExprNotFun && pt.typeSymbol == UnitClass) + if (mode.typingExprNotFun && pt.typeSymbol == UnitClass && !tree.tpe.isInstanceOf[MethodType]) instantiateExpectingUnit(tree, mode) else instantiate(tree, mode, pt) @@ -1536,7 +1546,11 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper val cbody1 = treeCopy.Block(cbody, preSuperStats, superCall1) val clazz = context.owner assert(clazz != NoSymbol, templ) - val dummy = context.outer.owner.newLocalDummy(templ.pos) + // SI-9086 The position of this symbol is material: implicit search will avoid triggering + // cyclic errors in an implicit search in argument to the super constructor call on + // account of the "ignore symbols without complete info that succeed the implicit search" + // in this source file. See `ImplicitSearch#isValid` and `ImplicitInfo#isCyclicOrErroneous`. + val dummy = context.outer.owner.newLocalDummy(context.owner.pos) val cscope = context.outer.makeNewScope(ctor, dummy) if (dummy.isTopLevel) currentRun.symSource(dummy) = currentUnit.source.file val cbody2 = { // called both during completion AND typing. diff --git a/src/eclipse/README.md b/src/eclipse/README.md index 5311651db5..03c7403b04 100644 --- a/src/eclipse/README.md +++ b/src/eclipse/README.md @@ -1,28 +1,9 @@ Eclipse project files ===================== -The following points describe how to get Scala to run in Eclipse: +The following points describe how to get Scala to run in Eclipse. Please also take a look at the [excellent tutorial on scala-ide.org](http://scala-ide.org/docs/tutorials/scalac-trunk/index.html). -0. To get Scala to work inside of Eclipse Kepler it is necessary to build the Scala IDE by your own -because for the moment there is no update site provided for the newest development version -of Scala. To do so enter the following commands one after the other: - - git clone https://github.com/scala-ide/scala-ide.git - cd scala-ide - ./build-all.sh clean install -Pscala-2.11.x -Peclipse-kepler -DskipTests - - After that you have an update site in `scala-ide/org.scala-ide.sdt.update-site/target/site`, which needs to be -installed in Eclipse. - -0. The second thing that needs to be done is building Scala in order to get all necessary -dependencies. To do that simply enter - - ant - - and wait until it is completed. To verify that everything has been built successfully, execute the REPL that can be found -at `scala/build/pack/bin/scala`. - -0. Import all projects inside of Eclipse by choosing `File/Import Existing Projects` +0. Import all projects into a [very recent version of Scala IDE for Eclipse](http://scala-ide.org/download/nightly.html) by choosing `File/Import Existing Projects` and navigate to `scala/src/eclipse`. Check all projects and click ok. 0. You need to define a `path variable` inside Eclipse. Define `SCALA_BASEDIR` in diff --git a/src/library/scala/collection/IterableLike.scala b/src/library/scala/collection/IterableLike.scala index 91ab1f6ac2..7643b84a8b 100644 --- a/src/library/scala/collection/IterableLike.scala +++ b/src/library/scala/collection/IterableLike.scala @@ -179,6 +179,7 @@ self => /** Groups elements in fixed size blocks by passing a "sliding window" * over them (as opposed to partitioning them, as is done in grouped.) + * "Sliding window" step is 1 by default. * @see [[scala.collection.Iterator]], method `sliding` * * @param size the number of elements per group @@ -194,7 +195,7 @@ self => * * @param size the number of elements per group * @param step the distance between the first elements of successive - * groups (defaults to 1) + * groups * @return An iterator producing ${coll}s of size `size`, except the * last and the only element will be truncated if there are * fewer elements than size. diff --git a/src/library/scala/collection/immutable/StringLike.scala b/src/library/scala/collection/immutable/StringLike.scala index f0daaf25a5..1ead894faf 100644 --- a/src/library/scala/collection/immutable/StringLike.scala +++ b/src/library/scala/collection/immutable/StringLike.scala @@ -10,7 +10,7 @@ package scala package collection package immutable -import mutable.Builder +import mutable.{ ArrayBuilder, Builder } import scala.util.matching.Regex import scala.math.ScalaNumber import scala.reflect.ClassTag @@ -203,8 +203,33 @@ self => private def escape(ch: Char): String = "\\Q" + ch + "\\E" - @throws(classOf[java.util.regex.PatternSyntaxException]) - def split(separator: Char): Array[String] = toString.split(escape(separator)) + def split(separator: Char): Array[String] = { + val thisString = toString + var pos = thisString.indexOf(separator) + + if (pos != -1) { + val res = new ArrayBuilder.ofRef[String] + + var prev = 0 + do { + res += thisString.substring(prev, pos) + prev = pos + 1 + pos = thisString.indexOf(separator, prev) + } while (pos != -1) + + if (prev != thisString.size) + res += thisString.substring(prev, thisString.size) + + val initialResult = res.result() + pos = initialResult.length + while (pos > 0 && initialResult(pos - 1).isEmpty) pos = pos - 1 + if (pos != initialResult.length) { + val trimmed = new Array[String](pos) + Array.copy(initialResult, 0, trimmed, 0, pos) + trimmed + } else initialResult + } else Array[String](thisString) + } @throws(classOf[java.util.regex.PatternSyntaxException]) def split(separators: Array[Char]): Array[String] = { diff --git a/src/library/scala/collection/mutable/BitSet.scala b/src/library/scala/collection/mutable/BitSet.scala index faa4155317..78150b5e88 100644 --- a/src/library/scala/collection/mutable/BitSet.scala +++ b/src/library/scala/collection/mutable/BitSet.scala @@ -160,6 +160,9 @@ class BitSet(protected final var elems: Array[Long]) extends AbstractSet[Int] * * @return an immutable set containing all the elements of this set. */ + @deprecated("If this BitSet contains a value that is 128 or greater, the result of this method is an 'immutable' " + + "BitSet that shares state with this mutable BitSet. Thus, if the mutable BitSet is modified, it will violate the " + + "immutability of the result.", "2.11.6") def toImmutable = immutable.BitSet.fromBitMaskNoCopy(elems) override def clone(): BitSet = { diff --git a/src/library/scala/collection/mutable/MutableList.scala b/src/library/scala/collection/mutable/MutableList.scala index b852a4747b..646023f469 100644 --- a/src/library/scala/collection/mutable/MutableList.scala +++ b/src/library/scala/collection/mutable/MutableList.scala @@ -13,7 +13,6 @@ package mutable import generic._ import immutable.{List, Nil} -// !!! todo: convert to LinkedListBuffer? /** * This class is used internally to represent mutable lists. It is the * basis for the implementation of the class `Queue`. @@ -113,9 +112,21 @@ extends AbstractSeq[A] } } - /** Returns an iterator over all elements of this list. + /** Returns an iterator over up to `length` elements of this list. */ - override def iterator: Iterator[A] = first0.iterator + override def iterator: Iterator[A] = if (isEmpty) Iterator.empty else + new AbstractIterator[A] { + var elems = first0 + var count = len + def hasNext = count > 0 && elems.nonEmpty + def next() = { + if (!hasNext) throw new NoSuchElementException + count = count - 1 + val e = elems.elem + elems = if (count == 0) null else elems.next + e + } + } override def last = { if (isEmpty) throw new NoSuchElementException("MutableList.empty.last") diff --git a/src/library/scala/concurrent/package.scala b/src/library/scala/concurrent/package.scala index 4843d28679..d159dda414 100644 --- a/src/library/scala/concurrent/package.scala +++ b/src/library/scala/concurrent/package.scala @@ -12,6 +12,75 @@ import scala.concurrent.duration.Duration import scala.annotation.implicitNotFound /** This package object contains primitives for concurrent and parallel programming. + * + * == Guide == + * + * A more detailed guide to Futures and Promises, including discussion and examples + * can be found at + * [[http://docs.scala-lang.org/overviews/core/futures.html]]. + * + * == Common Imports == + * + * When working with Futures, you will often find that importing the whole concurrent + * package is convenient, furthermore you are likely to need an implicit ExecutionContext + * in scope for many operations involving Futures and Promises: + * + * {{{ + * import scala.concurrent._ + * import ExecutionContext.Implicits.global + * }}} + * + * == Specifying Durations == + * + * Operations often require a duration to be specified. A duration DSL is available + * to make defining these easier: + * + * {{{ + * import scala.concurrent.duration._ + * val d: Duration = 10.seconds + * }}} + * + * == Using Futures For Non-blocking Computation == + * + * Basic use of futures is easy with the factory method on Future, which executes a + * provided function asynchronously, handing you back a future result of that function + * without blocking the current thread. In order to create the Future you will need + * either an implicit or explicit ExecutionContext to be provided: + * + * {{{ + * import scala.concurrent._ + * import ExecutionContext.Implicits.global // implicit execution context + * + * val firstZebra: Future[Int] = Future { + * val source = scala.io.Source.fromFile("/etc/dictionaries-common/words") + * source.toSeq.indexOfSlice("zebra") + * } + * }}} + * + * == Avoid Blocking == + * + * Although blocking is possible in order to await results (with a mandatory timeout duration): + * + * {{{ + * import scala.concurrent.duration._ + * Await.result(firstZebra, 10.seconds) + * }}} + * + * and although this is sometimes necessary to do, in particular for testing purposes, blocking + * in general is discouraged when working with Futures and concurrency in order to avoid + * potential deadlocks and improve performance. Instead, use callbacks or combinators to + * remain in the future domain: + * + * {{{ + * val animalRange: Future[Int] = for { + * aardvark <- firstAardvark + * zebra <- firstZebra + * } yield zebra - aardvark + * + * animalRange.onSuccess { + * case x if x > 500000 => println("It's a long way from Aardvark to Zebra") + * } + * }}} */ package object concurrent { type ExecutionException = java.util.concurrent.ExecutionException @@ -70,6 +139,11 @@ package concurrent { /** * `Await` is what is used to ensure proper handling of blocking for `Awaitable` instances. + * + * While occasionally useful, e.g. for testing, it is recommended that you avoid Await + * when possible in favor of callbacks and combinators like onComplete and use in + * for comprehensions. Await will block the thread on which it runs, and could cause + * performance and deadlock issues. */ object Await { /** diff --git a/src/reflect/scala/reflect/internal/Symbols.scala b/src/reflect/scala/reflect/internal/Symbols.scala index e91bfadc85..d5fc52abbf 100644 --- a/src/reflect/scala/reflect/internal/Symbols.scala +++ b/src/reflect/scala/reflect/internal/Symbols.scala @@ -2054,7 +2054,11 @@ trait Symbols extends api.Symbols { self: SymbolTable => * where it is the outer class of the enclosing class. */ final def outerClass: Symbol = - if (owner.isClass) owner + if (this == NoSymbol) { + // ideally we shouldn't get here, but its better to harden against this than suffer the infinite loop in SI-9133 + devWarningDumpStack("NoSymbol.outerClass", 15) + NoSymbol + } else if (owner.isClass) owner else if (isClassLocalToConstructor) owner.enclClass.outerClass else owner.outerClass diff --git a/src/reflect/scala/reflect/internal/Trees.scala b/src/reflect/scala/reflect/internal/Trees.scala index 35de3adff6..fd918b8595 100644 --- a/src/reflect/scala/reflect/internal/Trees.scala +++ b/src/reflect/scala/reflect/internal/Trees.scala @@ -1576,6 +1576,7 @@ trait Trees extends api.Trees { */ class TreeSymSubstituter(from: List[Symbol], to: List[Symbol]) extends Transformer { val symSubst = new SubstSymMap(from, to) + private var mutatedSymbols: List[Symbol] = Nil override def transform(tree: Tree): Tree = { def subst(from: List[Symbol], to: List[Symbol]) { if (!from.isEmpty) @@ -1594,6 +1595,7 @@ trait Trees extends api.Trees { |TreeSymSubstituter: updated info of symbol ${tree.symbol} | Old: ${showRaw(tree.symbol.info, printTypes = true, printIds = true)} | New: ${showRaw(newInfo, printTypes = true, printIds = true)}""") + mutatedSymbols ::= tree.symbol tree.symbol updateInfo newInfo } case _ => @@ -1613,7 +1615,23 @@ trait Trees extends api.Trees { } else super.transform(tree) } - def apply[T <: Tree](tree: T): T = transform(tree).asInstanceOf[T] + def apply[T <: Tree](tree: T): T = { + val tree1 = transform(tree) + invalidateSingleTypeCaches(tree1) + tree1.asInstanceOf[T] + } + private def invalidateSingleTypeCaches(tree: Tree): Unit = { + if (mutatedSymbols.nonEmpty) + for (t <- tree if t.tpe != null) + for (tp <- t.tpe) { + tp match { + case s: SingleType if mutatedSymbols contains s.sym => + s.underlyingPeriod = NoPeriod + s.underlyingCache = NoType + case _ => + } + } + } override def toString() = "TreeSymSubstituter/" + substituterString("Symbol", "Symbol", from, to) } diff --git a/src/repl/scala/tools/nsc/interpreter/ILoop.scala b/src/repl/scala/tools/nsc/interpreter/ILoop.scala index 4fd5768b79..4d71e0e09e 100644 --- a/src/repl/scala/tools/nsc/interpreter/ILoop.scala +++ b/src/repl/scala/tools/nsc/interpreter/ILoop.scala @@ -12,6 +12,7 @@ import scala.annotation.tailrec import Predef.{ println => _, _ } import interpreter.session._ import StdReplTags._ +import scala.tools.asm.ClassReader import scala.util.Properties.{ jdkHome, javaVersion, versionString, javaVmName } import scala.tools.nsc.util.{ ClassPath, Exceptional, stringFromWriter, stringFromStream } import scala.reflect.classTag @@ -633,28 +634,29 @@ class ILoop(in0: Option[BufferedReader], protected val out: JPrintWriter) * the interpreter and replays all interpreter expressions. */ def require(arg: String): Unit = { - class InfoClassLoader extends java.lang.ClassLoader { - def classOf(arr: Array[Byte]): Class[_] = - super.defineClass(null, arr, 0, arr.length) - } - val f = File(arg).normalize - if (f.isDirectory) { - echo("Adding directories to the classpath is not supported. Add a jar instead.") + val jarFile = AbstractFile.getDirectory(new java.io.File(arg)) + if (jarFile == null) { + echo(s"Cannot load '$arg'") return } - val jarFile = AbstractFile.getDirectory(new java.io.File(arg)) - def flatten(f: AbstractFile): Iterator[AbstractFile] = if (f.isClassContainer) f.iterator.flatMap(flatten) else Iterator(f) val entries = flatten(jarFile) - val cloader = new InfoClassLoader - def classNameOf(classFile: AbstractFile): String = cloader.classOf(classFile.toByteArray).getName + def classNameOf(classFile: AbstractFile): String = { + val input = classFile.input + try { + val reader = new ClassReader(input) + reader.getClassName.replace('/', '.') + } finally { + input.close() + } + } def alreadyDefined(clsName: String) = intp.classLoader.tryToLoadClass(clsName).isDefined val exists = entries.filter(_.hasExtension("class")).map(classNameOf).exists(alreadyDefined) diff --git a/src/repl/scala/tools/nsc/interpreter/InteractiveReader.scala b/src/repl/scala/tools/nsc/interpreter/InteractiveReader.scala index 28ddf2939c..ed69d449cb 100644 --- a/src/repl/scala/tools/nsc/interpreter/InteractiveReader.scala +++ b/src/repl/scala/tools/nsc/interpreter/InteractiveReader.scala @@ -23,6 +23,7 @@ trait InteractiveReader { def readYesOrNo(prompt: String, alt: => Boolean): Boolean = readOneKey(prompt) match { case 'y' => true case 'n' => false + case -1 => false // EOF case _ => alt } |