diff options
Diffstat (limited to 'src')
19 files changed, 60 insertions, 77 deletions
diff --git a/src/compiler/scala/tools/nsc/ScriptRunner.scala b/src/compiler/scala/tools/nsc/ScriptRunner.scala index 6d24b31531..bf93ad30bc 100644 --- a/src/compiler/scala/tools/nsc/ScriptRunner.scala +++ b/src/compiler/scala/tools/nsc/ScriptRunner.scala @@ -16,16 +16,16 @@ import util.Exceptional.unwrap /** An object that runs Scala code in script files. * - * <p>For example, here is a complete Scala script on Unix:</pre> - * <pre> + * For example, here is a complete Scala script on Unix: + * {{{ * #!/bin/sh * exec scala "$0" "$@" * !# * Console.println("Hello, world!") * args.toList foreach Console.println - * </pre> - * <p>And here is a batch file example on Windows XP:</p> - * <pre> + * }}} + * And here is a batch file example on Windows XP: + * {{{ * ::#! * @echo off * call scala %0 %* @@ -33,7 +33,7 @@ import util.Exceptional.unwrap * ::!# * Console.println("Hello, world!") * args.toList foreach Console.println - * </pre> + * }}} * * @author Lex Spoon * @version 1.0, 15/05/2006 diff --git a/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala b/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala index 92833d647b..cd41c75298 100644 --- a/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala +++ b/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala @@ -226,7 +226,7 @@ trait Scanners extends ScannersCommon { * RPAREN if region starts with '(' * RBRACKET if region starts with '[' * RBRACE if region starts with '{' - * ARROW if region starts with `case' + * ARROW if region starts with 'case' * STRINGLIT if region is a string interpolation expression starting with '${' * (the STRINGLIT appears twice in succession on the stack iff the * expression is a multiline string literal). diff --git a/src/compiler/scala/tools/nsc/backend/jvm/GenASM.scala b/src/compiler/scala/tools/nsc/backend/jvm/GenASM.scala index a34ab914ef..5b59150f5d 100644 --- a/src/compiler/scala/tools/nsc/backend/jvm/GenASM.scala +++ b/src/compiler/scala/tools/nsc/backend/jvm/GenASM.scala @@ -495,8 +495,8 @@ abstract class GenASM extends SubComponent with BytecodeWriters { self => * generic classes or interfaces. * * @param superName the internal of name of the super class. For interfaces, - * the super class is {@link Object}. May be <tt>null</tt>, but - * only for the {@link Object} class. + * the super class is [[Object]]. May be <tt>null</tt>, but + * only for the [[Object]] class. * * @param interfaces the internal names of the class's interfaces (see * {@link Type#getInternalName() getInternalName}). May be diff --git a/src/compiler/scala/tools/nsc/typechecker/Checkable.scala b/src/compiler/scala/tools/nsc/typechecker/Checkable.scala index fc632e0d0d..309b80f9ba 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Checkable.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Checkable.scala @@ -44,7 +44,7 @@ import scala.language.postfixOps * which is essentially the intersection of X and |P|, where |P| is * the erasure of P. If XR <: P, then no warning is emitted. * - * We evaluate "X with conform to P" by checking `X <: P_wild, where + * We evaluate "X with conform to P" by checking `X <: P_wild`, where * P_wild is the result of substituting wildcard types in place of * pattern type variables. This is intentionally stricter than * (X matchesPattern P), see SI-8597 for motivating test cases. diff --git a/src/compiler/scala/tools/nsc/typechecker/Implicits.scala b/src/compiler/scala/tools/nsc/typechecker/Implicits.scala index 7ec9cd74a4..6c37cb96c0 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Implicits.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Implicits.scala @@ -110,10 +110,10 @@ trait Implicits { * Ignore their constr field! The list of type constraints returned along with each tree specifies the constraints that * must be met by the corresponding type parameter in `tpars` (for the returned implicit view to be valid). * - * @arg tp from-type for the implicit conversion - * @arg context search implicits here - * @arg tpars symbols that should be considered free type variables - * (implicit search should not try to solve them, just track their constraints) + * @param tp from-type for the implicit conversion + * @param context search implicits here + * @param tpars symbols that should be considered free type variables + * (implicit search should not try to solve them, just track their constraints) */ def allViewsFrom(tp: Type, context: Context, tpars: List[Symbol]): List[(SearchResult, List[TypeConstraint])] = { // my untouchable typevars are better than yours (they can't be constrained by them) diff --git a/src/compiler/scala/tools/nsc/typechecker/Infer.scala b/src/compiler/scala/tools/nsc/typechecker/Infer.scala index ab9fa26bac..9f7bdf7aff 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Infer.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Infer.scala @@ -1375,7 +1375,7 @@ trait Infer extends Checkable { * Otherwise, if there is no best alternative, error. * * @param argtpes0 contains the argument types. If an argument is named, as - * "a = 3", the corresponding type is `NamedType("a", Int)'. If the name + * "a = 3", the corresponding type is `NamedType("a", Int)`. If the name * of some NamedType does not exist in an alternative's parameter names, * the type is replaces by `Unit`, i.e. the argument is treated as an * assignment expression. diff --git a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala index 0198529ef7..90ac1f466d 100644 --- a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala +++ b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala @@ -1511,7 +1511,8 @@ abstract class RefChecks extends InfoTransform with scala.reflect.internal.trans sym.isSourceMethod && sym.isCase && sym.name == nme.apply && - isClassTypeAccessible(tree) + isClassTypeAccessible(tree) && + !tree.tpe.resultType.typeSymbol.primaryConstructor.isLessAccessibleThan(tree.symbol) if (doTransform) { tree foreach { diff --git a/src/compiler/scala/tools/nsc/typechecker/StdAttachments.scala b/src/compiler/scala/tools/nsc/typechecker/StdAttachments.scala index ea44b9dc39..92b0719ba3 100644 --- a/src/compiler/scala/tools/nsc/typechecker/StdAttachments.scala +++ b/src/compiler/scala/tools/nsc/typechecker/StdAttachments.scala @@ -132,7 +132,7 @@ trait StdAttachments { /** Marks the tree as a macro impl reference, which is a naked reference to a method. * * This is necessary for typechecking macro impl references (see `DefaultMacroCompiler.defaultResolveMacroImpl`), - * because otherwise typing a naked reference will result in the "follow this method with `_' if you want to + * because otherwise typing a naked reference will result in the "follow this method with `_` if you want to * treat it as a partially applied function" errors. * * This mark suppresses adapt except for when the annottee is a macro application. diff --git a/src/compiler/scala/tools/nsc/typechecker/Tags.scala b/src/compiler/scala/tools/nsc/typechecker/Tags.scala index 57dc74d2a0..56127f4026 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Tags.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Tags.scala @@ -36,7 +36,7 @@ trait Tags { * @param allowMaterialization If true (default) then the resolver is allowed to launch materialization macros when there's no class tag in scope. * If false then materialization macros are prohibited from running. * - * @returns Tree that represents an `scala.reflect.ClassTag` for `tp` if everything is okay. + * @return Tree that represents an `scala.reflect.ClassTag` for `tp` if everything is okay. * EmptyTree if the result contains unresolved (i.e. not spliced) type parameters and abstract type members. * EmptyTree if `allowMaterialization` is false, and there is no class tag in scope. */ @@ -57,7 +57,7 @@ trait Tags { * @param allowMaterialization If true (default) then the resolver is allowed to launch materialization macros when there's no type tag in scope. * If false then materialization macros are prohibited from running. * - * @returns Tree that represents a `scala.reflect.TypeTag` for `tp` if everything is okay. + * @return Tree that represents a `scala.reflect.TypeTag` for `tp` if everything is okay. * EmptyTree if `concrete` is true and the result contains unresolved (i.e. not spliced) type parameters and abstract type members. * EmptyTree if `allowMaterialization` is false, and there is no array tag in scope. */ diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index fd1a6f293f..a7046e45e0 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -2725,7 +2725,7 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper * * If 'T' is not fully defined, it is inferred by type checking * `apply$body` without a result type before type checking the block. - * The method's inferred result type is used instead of T`. [See test/files/pos/sammy_poly.scala] + * The method's inferred result type is used instead of `T`. [See test/files/pos/sammy_poly.scala] * * The `apply` method is identified by the argument `sam`; `S` corresponds to the argument `samClassTp`, * and `resPt` is derived from `samClassTp` -- it may be fully defined, or not... diff --git a/src/compiler/scala/tools/nsc/util/DocStrings.scala b/src/compiler/scala/tools/nsc/util/DocStrings.scala index 4ff7067a21..501546b8f6 100755 --- a/src/compiler/scala/tools/nsc/util/DocStrings.scala +++ b/src/compiler/scala/tools/nsc/util/DocStrings.scala @@ -37,7 +37,7 @@ object DocStrings { /** Returns index of string `str` after `start` skipping longest * sequence of space and tab characters, possibly also containing * a single `*` character or the `/``**` sequence. - * @pre start == str.length || str(start) == `\n' + * @pre start == str.length || str(start) == `\n` */ def skipLineLead(str: String, start: Int): Int = if (start == str.length) start @@ -49,7 +49,7 @@ object DocStrings { else idx } - /** Skips to next occurrence of `\n' or to the position after the `/``**` sequence following index `start`. + /** Skips to next occurrence of `\n` or to the position after the `/``**` sequence following index `start`. */ def skipToEol(str: String, start: Int): Int = if (start + 2 < str.length && (str charAt start) == '/' && (str charAt (start + 1)) == '*' && (str charAt (start + 2)) == '*') start + 3 diff --git a/src/library/scala/collection/convert/Wrappers.scala b/src/library/scala/collection/convert/Wrappers.scala index 9f9732c62f..e829a0215b 100644 --- a/src/library/scala/collection/convert/Wrappers.scala +++ b/src/library/scala/collection/convert/Wrappers.scala @@ -265,17 +265,11 @@ private[collection] trait Wrappers { def +=(kv: (A, B)): this.type = { underlying.put(kv._1, kv._2); this } def -=(key: A): this.type = { underlying remove key; this } - override def put(k: A, v: B): Option[B] = { - val r = underlying.put(k, v) - if (r != null) Some(r) else None - } + override def put(k: A, v: B): Option[B] = Option(underlying.put(k, v)) override def update(k: A, v: B) { underlying.put(k, v) } - override def remove(k: A): Option[B] = { - val r = underlying remove k - if (r != null) Some(r) else None - } + override def remove(k: A): Option[B] = Option(underlying remove k) def iterator: Iterator[(A, B)] = new AbstractIterator[(A, B)] { val ui = underlying.entrySet.iterator @@ -326,25 +320,15 @@ private[collection] trait Wrappers { * are not guaranteed to be atomic. */ case class JConcurrentMapWrapper[A, B](underlying: juc.ConcurrentMap[A, B]) extends mutable.AbstractMap[A, B] with JMapWrapperLike[A, B, JConcurrentMapWrapper[A, B]] with concurrent.Map[A, B] { - override def get(k: A) = { - val v = underlying get k - if (v != null) Some(v) - else None - } + override def get(k: A) = Option(underlying get k) override def empty = new JConcurrentMapWrapper(new juc.ConcurrentHashMap[A, B]) - def putIfAbsent(k: A, v: B): Option[B] = { - val r = underlying.putIfAbsent(k, v) - if (r != null) Some(r) else None - } + def putIfAbsent(k: A, v: B): Option[B] = Option(underlying.putIfAbsent(k, v)) def remove(k: A, v: B): Boolean = underlying.remove(k, v) - def replace(k: A, v: B): Option[B] = { - val prev = underlying.replace(k, v) - if (prev != null) Some(prev) else None - } + def replace(k: A, v: B): Option[B] = Option(underlying.replace(k, v)) def replace(k: A, oldvalue: B, newvalue: B): Boolean = underlying.replace(k, oldvalue, newvalue) @@ -380,25 +364,16 @@ private[collection] trait Wrappers { case class JDictionaryWrapper[A, B](underlying: ju.Dictionary[A, B]) extends mutable.AbstractMap[A, B] with mutable.Map[A, B] { override def size: Int = underlying.size - def get(k: A) = { - val v = underlying get k - if (v != null) Some(v) else None - } + def get(k: A) = Option(underlying get k) def +=(kv: (A, B)): this.type = { underlying.put(kv._1, kv._2); this } def -=(key: A): this.type = { underlying remove key; this } - override def put(k: A, v: B): Option[B] = { - val r = underlying.put(k, v) - if (r != null) Some(r) else None - } + override def put(k: A, v: B): Option[B] = Option(underlying.put(k, v)) override def update(k: A, v: B) { underlying.put(k, v) } - override def remove(k: A): Option[B] = { - val r = underlying remove k - if (r != null) Some(r) else None - } + override def remove(k: A): Option[B] = Option(underlying remove k) def iterator = enumerationAsScalaIterator(underlying.keys) map (k => (k, underlying get k)) diff --git a/src/library/scala/collection/immutable/StringLike.scala b/src/library/scala/collection/immutable/StringLike.scala index 1ead894faf..1b52e40b72 100644 --- a/src/library/scala/collection/immutable/StringLike.scala +++ b/src/library/scala/collection/immutable/StringLike.scala @@ -217,8 +217,8 @@ self => pos = thisString.indexOf(separator, prev) } while (pos != -1) - if (prev != thisString.size) - res += thisString.substring(prev, thisString.size) + if (prev != thisString.length) + res += thisString.substring(prev, thisString.length) val initialResult = res.result() pos = initialResult.length diff --git a/src/library/scala/ref/WeakReference.scala b/src/library/scala/ref/WeakReference.scala index 6ee40aed5c..9dcc0bbe5f 100644 --- a/src/library/scala/ref/WeakReference.scala +++ b/src/library/scala/ref/WeakReference.scala @@ -28,10 +28,7 @@ object WeakReference { def apply[T <: AnyRef](value: T) = new WeakReference(value) /** Optionally returns the referenced value, or `None` if that value no longer exists */ - def unapply[T <: AnyRef](wr: WeakReference[T]): Option[T] = { - val x = wr.underlying.get - if (x != null) Some(x) else None - } + def unapply[T <: AnyRef](wr: WeakReference[T]): Option[T] = Option(wr.underlying.get) } /** diff --git a/src/library/scala/util/control/Exception.scala b/src/library/scala/util/control/Exception.scala index aa30887ba0..24c297a2fc 100644 --- a/src/library/scala/util/control/Exception.scala +++ b/src/library/scala/util/control/Exception.scala @@ -105,7 +105,7 @@ object Exception { case x if rethrow(x) => throw x case x if pf isDefinedAt x => pf(x) } - finally fin map (_.invoke()) + finally fin foreach (_.invoke()) /* Create an empty Try container with this Catch and the supplied `Finally`. */ def andFinally(body: => Unit): Catch[T] = fin match { diff --git a/src/reflect/scala/reflect/runtime/TwoWayCache.scala b/src/reflect/scala/reflect/runtime/TwoWayCache.scala index d0fc3dac74..6c1ca5b571 100644 --- a/src/reflect/scala/reflect/runtime/TwoWayCache.scala +++ b/src/reflect/scala/reflect/runtime/TwoWayCache.scala @@ -26,8 +26,7 @@ private[runtime] class TwoWayCache[J, S] { private object SomeRef { def unapply[T](optRef: Option[WeakReference[T]]): Option[T] = if (optRef.nonEmpty) { - val result = optRef.get.get - if (result != null) Some(result) else None + Option(optRef.get.get) } else None } diff --git a/src/reflect/scala/reflect/runtime/TwoWayCaches.scala b/src/reflect/scala/reflect/runtime/TwoWayCaches.scala index 6e2890e536..6ce0c0a728 100644 --- a/src/reflect/scala/reflect/runtime/TwoWayCaches.scala +++ b/src/reflect/scala/reflect/runtime/TwoWayCaches.scala @@ -26,8 +26,7 @@ private[runtime] trait TwoWayCaches { self: SymbolTable => private object SomeRef { def unapply[T](optRef: Option[WeakReference[T]]): Option[T] = if (optRef.nonEmpty) { - val result = optRef.get.get - if (result != null) Some(result) else None + Option(optRef.get.get) } else None } diff --git a/src/repl/scala/tools/nsc/interpreter/IMain.scala b/src/repl/scala/tools/nsc/interpreter/IMain.scala index 841b4abfa5..06ae179da9 100644 --- a/src/repl/scala/tools/nsc/interpreter/IMain.scala +++ b/src/repl/scala/tools/nsc/interpreter/IMain.scala @@ -888,7 +888,7 @@ class IMain(@BeanProperty val factory: ScriptEngineFactory, initialSettings: Set /** Code to import bound names from previous lines - accessPath is code to * append to objectName to access anything bound by request. */ - lazy val ComputedImports(importsPreamble, importsTrailer, accessPath) = + lazy val ComputedImports(headerPreamble, importsPreamble, importsTrailer, accessPath) = exitingTyper(importsCode(referencedNames.toSet, ObjectSourceCode, definesClass)) /** the line of code to compute */ @@ -908,6 +908,7 @@ class IMain(@BeanProperty val factory: ScriptEngineFactory, initialSettings: Set else List("def %s = %s".format("$line", tquoted(originalLine)), "def %s = Nil".format("$trees")) } def preamble = s""" + |$headerPreamble |${preambleHeader format lineRep.readName} |${envLines mkString (" ", ";\n ", ";\n")} |$importsPreamble diff --git a/src/repl/scala/tools/nsc/interpreter/Imports.scala b/src/repl/scala/tools/nsc/interpreter/Imports.scala index 3ec77e46f1..5b231d94b6 100644 --- a/src/repl/scala/tools/nsc/interpreter/Imports.scala +++ b/src/repl/scala/tools/nsc/interpreter/Imports.scala @@ -70,7 +70,10 @@ trait Imports { /** Compute imports that allow definitions from previous * requests to be visible in a new request. Returns - * three pieces of related code: + * three or four pieces of related code: + * + * 0. Header code fragment that should go at the beginning + * of the compilation unit, specifically, import Predef. * * 1. An initial code fragment that should go before * the code of the new request. @@ -91,30 +94,34 @@ trait Imports { * (3) It imports multiple same-named implicits, but only the * last one imported is actually usable. */ - case class ComputedImports(prepend: String, append: String, access: String) + case class ComputedImports(header: String, prepend: String, append: String, access: String) protected def importsCode(wanted: Set[Name], wrapper: Request#Wrapper, definesClass: Boolean): ComputedImports = { + val header, code, trailingBraces, accessPath = new StringBuilder + val currentImps = mutable.HashSet[Name]() + var predefEscapes = false // only emit predef import header if name not resolved in history, loosely + /** Narrow down the list of requests from which imports * should be taken. Removes requests which cannot contribute * useful imports for the specified set of wanted names. */ - case class ReqAndHandler(req: Request, handler: MemberHandler) { } + case class ReqAndHandler(req: Request, handler: MemberHandler) def reqsToUse: List[ReqAndHandler] = { /** Loop through a list of MemberHandlers and select which ones to keep. - * 'wanted' is the set of names that need to be imported. + * 'wanted' is the set of names that need to be imported. */ def select(reqs: List[ReqAndHandler], wanted: Set[Name]): List[ReqAndHandler] = { // Single symbol imports might be implicits! See bug #1752. Rather than // try to finesse this, we will mimic all imports for now. def keepHandler(handler: MemberHandler) = handler match { - /* While defining classes in class based mode - implicits are not needed. */ + // While defining classes in class based mode - implicits are not needed. case h: ImportHandler if isClassBased && definesClass => h.importedNames.exists(x => wanted.contains(x)) case _: ImportHandler => true case x => x.definesImplicit || (x.definedNames exists wanted) } reqs match { - case Nil => Nil + case Nil => predefEscapes = wanted contains PredefModule.name ; Nil case rh :: rest if !keepHandler(rh.handler) => select(rest, wanted) case rh :: rest => import rh.handler._ @@ -127,9 +134,6 @@ trait Imports { select(allReqAndHandlers reverseMap { case (r, h) => ReqAndHandler(r, h) }, wanted).reverse } - val code, trailingBraces, accessPath = new StringBuilder - val currentImps = mutable.HashSet[Name]() - // add code for a new object to hold some imports def addWrapper() { import nme.{ INTERPRETER_IMPORT_WRAPPER => iw } @@ -146,6 +150,9 @@ trait Imports { try op finally addWrapper() } + // imports from Predef are relocated to the template header to allow hiding. + def checkHeader(h: ImportHandler) = h.referencedNames contains PredefModule.name + // loop through previous requests, adding imports for each one wrapBeforeAndAfter { // Reusing a single temporary value when import from a line with multiple definitions. @@ -153,6 +160,9 @@ trait Imports { for (ReqAndHandler(req, handler) <- reqsToUse) { val objName = req.lineRep.readPathInstance handler match { + case h: ImportHandler if checkHeader(h) => + header.clear() + header append f"${h.member}%n" // If the user entered an import, then just use it; add an import wrapping // level if the import might conflict with some other import case x: ImportHandler if x.importsWildcard => @@ -194,7 +204,8 @@ trait Imports { } } - ComputedImports(code.toString, trailingBraces.toString, accessPath.toString) + val computedHeader = if (predefEscapes) header.toString else "" + ComputedImports(computedHeader, code.toString, trailingBraces.toString, accessPath.toString) } private def allReqAndHandlers = |