diff options
author | Adriaan Moors <adriaan.moors@typesafe.com> | 2014-06-10 17:48:27 +0200 |
---|---|---|
committer | Adriaan Moors <adriaan.moors@typesafe.com> | 2014-06-10 17:48:27 +0200 |
commit | 6887029f100e2c3a90534768da074472f39cf14f (patch) | |
tree | 4b880aac09cf5cfc5a682ff3cf97ef805db6a9cd | |
parent | ed3df58ab167f660825e675b6b45eb454fc9869b (diff) | |
parent | cf8902907756cca2c5b8367c898ca0e9698c6521 (diff) | |
download | scala-6887029f100e2c3a90534768da074472f39cf14f.tar.gz scala-6887029f100e2c3a90534768da074472f39cf14f.tar.bz2 scala-6887029f100e2c3a90534768da074472f39cf14f.zip |
Merge pull request #3821 from retronym/merge/2.11.x-to-2.12.x
Merge 2.11.x to 2.12.x
45 files changed, 464 insertions, 300 deletions
@@ -1357,20 +1357,24 @@ TODO: </target> <target name="test.osgi" depends="test.osgi.comp"> - <stopwatch name="test.osgi.timer"/> - <mkdir dir="${test.osgi.classes}"/> - - <echo message="Running OSGi JUnit tests. Output in ${build-osgi.dir}"/> - <junit fork="yes" haltonfailure="yes"> - <classpath refid="test.osgi.compiler.build.path"/> - <batchtest fork="yes" todir="${build-osgi.dir}"> - <fileset dir="${test.osgi.classes}"> - <include name="**/*Test.class"/> - </fileset> - </batchtest> - <formatter type="xml" /> <!-- silenced by having it use a file; I tried for an hour to use other formatters but classpath issues drove me to this usefile="false" --> - </junit> - <stopwatch name="test.osgi.timer" action="total"/> + <if><isset property="has.java8"/><then> + <echo message="Skipping OSGi JUnit tests on Java 8. See SI-8642"/> + </then><else> + <echo message="Running OSGi JUnit tests. Output in ${build-osgi.dir}"/> + <stopwatch name="test.osgi.timer"/> + <mkdir dir="${test.osgi.classes}"/> + + <junit fork="yes" haltonfailure="yes"> + <classpath refid="test.osgi.compiler.build.path"/> + <batchtest fork="yes" todir="${build-osgi.dir}"> + <fileset dir="${test.osgi.classes}"> + <include name="**/*Test.class"/> + </fileset> + </batchtest> + <formatter type="xml" /> <!-- silenced by having it use a file; I tried for an hour to use other formatters but classpath issues drove me to this usefile="false" --> + </junit> + <stopwatch name="test.osgi.timer" action="total"/> + </else></if> </target> diff --git a/src/build/maven/scala-dist-pom.xml b/src/build/maven/scala-dist-pom.xml index 22a24dea21..9477e14285 100644 --- a/src/build/maven/scala-dist-pom.xml +++ b/src/build/maven/scala-dist-pom.xml @@ -40,6 +40,11 @@ <version>@VERSION@</version> </dependency> <dependency> + <groupId>org.scala-lang</groupId> + <artifactId>scalap</artifactId> + <version>@VERSION@</version> + </dependency> + <dependency> <groupId>org.scala-lang.plugins</groupId> <!-- plugins are fully cross-versioned. But, we don't publish with 2.11.0-SNAPSHOT, instead use full version of the last non-snapshot version --> <artifactId>scala-continuations-plugin_@SCALA_FULL_VERSION@</artifactId> diff --git a/src/compiler/scala/tools/nsc/CompilerCommand.scala b/src/compiler/scala/tools/nsc/CompilerCommand.scala index bab0768ca9..a1d0d52dcf 100644 --- a/src/compiler/scala/tools/nsc/CompilerCommand.scala +++ b/src/compiler/scala/tools/nsc/CompilerCommand.scala @@ -20,9 +20,12 @@ class CompilerCommand(arguments: List[String], val settings: Settings) { def ok = processArgumentsResult._1 def files = processArgumentsResult._2 - /** The name of the command */ + /** The name of the command. */ def cmdName = "scalac" + /** A descriptive alias for version and help messages. */ + def cmdDesc = "compiler" + private def explainAdvanced = "\n" + """ |-- Notes on option parsing -- |Boolean settings are always false unless set. @@ -85,7 +88,11 @@ class CompilerCommand(arguments: List[String], val settings: Settings) { def getInfoMessage(global: Global): String = { import settings._ - if (help) usageMsg + global.pluginOptionsHelp + import Properties.{ versionString, copyrightString } //versionFor + def versionFor(command: String) = f"Scala $command $versionString -- $copyrightString" + + if (version) versionFor(cmdDesc) + else if (help) usageMsg + global.pluginOptionsHelp else if (Xhelp) xusageMsg else if (Yhelp) yusageMsg else if (showPlugins) global.pluginDescriptions diff --git a/src/compiler/scala/tools/nsc/Driver.scala b/src/compiler/scala/tools/nsc/Driver.scala index 3ac27a42e8..6befa76b3f 100644 --- a/src/compiler/scala/tools/nsc/Driver.scala +++ b/src/compiler/scala/tools/nsc/Driver.scala @@ -2,26 +2,24 @@ package scala package tools.nsc import scala.tools.nsc.reporters.ConsoleReporter -import Properties.{ versionString, copyrightString, residentPromptString } +import Properties.{ versionMsg, residentPromptString } import scala.reflect.internal.util.FakePos abstract class Driver { val prompt = residentPromptString - val versionMsg = "Scala compiler " + - versionString + " -- " + - copyrightString - var reporter: ConsoleReporter = _ protected var command: CompilerCommand = _ protected var settings: Settings = _ - protected def scalacError(msg: String) { + protected def scalacError(msg: String): Unit = { reporter.error(FakePos("scalac"), msg + "\n scalac -help gives more information") } - protected def processSettingsHook(): Boolean = true + protected def processSettingsHook(): Boolean = { + if (settings.version) { reporter echo versionMsg ; false } else true + } protected def newCompiler(): Global @@ -37,14 +35,12 @@ abstract class Driver { } def process(args: Array[String]) { - val ss = new Settings(scalacError) - reporter = new ConsoleReporter(ss) + val ss = new Settings(scalacError) + reporter = new ConsoleReporter(ss) command = new CompilerCommand(args.toList, ss) settings = command.settings - if (settings.version) { - reporter.echo(versionMsg) - } else if (processSettingsHook()) { + if (processSettingsHook()) { val compiler = newCompiler() try { if (reporter.hasErrors) @@ -68,5 +64,4 @@ abstract class Driver { process(args) sys.exit(if (reporter.hasErrors) 1 else 0) } - } diff --git a/src/compiler/scala/tools/nsc/GenericRunnerCommand.scala b/src/compiler/scala/tools/nsc/GenericRunnerCommand.scala index e710222285..dbdeec809f 100644 --- a/src/compiler/scala/tools/nsc/GenericRunnerCommand.scala +++ b/src/compiler/scala/tools/nsc/GenericRunnerCommand.scala @@ -19,9 +19,10 @@ extends CompilerCommand(args, settings) { def this(args: List[String]) = this(args, str => Console.println("Error: " + str)) - /** name of the associated compiler command */ override def cmdName = "scala" - def compCmdName = "scalac" + override def cmdDesc = "code runner" + + def compCmdName = "scalac" // super.cmdName // change CompilerCommand behavior override def shouldProcessArguments: Boolean = false @@ -50,17 +51,16 @@ extends CompilerCommand(args, settings) { case Nil => AsRepl case hd :: _ => waysToRun find (_.name == settings.howtorun.value) getOrElse guessHowToRun(hd) } - private def interpolate(s: String) = s.trim.replaceAll("@cmd@", cmdName).replaceAll("@compileCmd@", compCmdName) + "\n" - - def shortUsageMsg = interpolate(""" -Usage: @cmd@ <options> [<script|class|object|jar> <arguments>] - or @cmd@ -help -All options to @compileCmd@ (see @compileCmd@ -help) are also allowed. -""") + def shortUsageMsg = +s"""|Usage: $cmdName <options> [<script|class|object|jar> <arguments>] + | or $cmdName -help + | + |All options to $compCmdName (see $compCmdName -help) are also allowed. +""".stripMargin - override def usageMsg = shortUsageMsg + interpolate(""" -The first given argument other than options to @cmd@ designates + override def usageMsg = f"""$shortUsageMsg +The first given argument other than options to $cmdName designates what to run. Runnable targets are: - a file containing scala source @@ -68,7 +68,7 @@ what to run. Runnable targets are: - a runnable jar file with a valid Main-Class attribute - or if no argument is given, the repl (interactive shell) is started -Options to @cmd@ which reach the java runtime: +Options to $cmdName which reach the java runtime: -Dname=prop passed directly to java to set system properties -J<arg> -J is stripped and <arg> passed to java as-is @@ -86,8 +86,7 @@ A file argument will be run as a scala script unless it contains only self-contained compilation units (classes and objects) and exactly one runnable main method. In that case the file will be compiled and the main method invoked. This provides a bridge between scripts and standard -scala source. - """) + "\n" +scala source.%n""" } object GenericRunnerCommand { diff --git a/src/compiler/scala/tools/nsc/backend/jvm/BCodeBodyBuilder.scala b/src/compiler/scala/tools/nsc/backend/jvm/BCodeBodyBuilder.scala index 1285ca6862..bffa4bc51d 100644 --- a/src/compiler/scala/tools/nsc/backend/jvm/BCodeBodyBuilder.scala +++ b/src/compiler/scala/tools/nsc/backend/jvm/BCodeBodyBuilder.scala @@ -686,7 +686,12 @@ abstract class BCodeBodyBuilder extends BCodeSkelBuilder { case _ => } if ((targetTypeKind != null) && (sym == definitions.Array_clone) && invokeStyle.isDynamic) { - val target: String = targetTypeKind.asClassBType.internalName + // An invokevirtual points to a CONSTANT_Methodref_info which in turn points to a + // CONSTANT_Class_info of the receiver type. + // The JVMS is not explicit about this, but that receiver type may be an array type + // descriptor (instead of a class internal name): + // invokevirtual #2; //Method "[I".clone:()Ljava/lang/Object + val target: String = targetTypeKind.asRefBType.classOrArrayType bc.invokevirtual(target, "clone", "()Ljava/lang/Object;") } else { diff --git a/src/compiler/scala/tools/nsc/backend/jvm/BTypes.scala b/src/compiler/scala/tools/nsc/backend/jvm/BTypes.scala index 9aedc7f8b4..5b0fa6f7a8 100644 --- a/src/compiler/scala/tools/nsc/backend/jvm/BTypes.scala +++ b/src/compiler/scala/tools/nsc/backend/jvm/BTypes.scala @@ -217,7 +217,8 @@ abstract class BTypes[G <: Global](val __global_dont_use: G) { sealed trait RefBType extends BType { /** * The class or array type of this reference type. Used for ANEWARRAY, MULTIANEWARRAY, - * INSTANCEOF and CHECKCAST instructions. + * INSTANCEOF and CHECKCAST instructions. Also used for emitting invokevirtual calls to + * (a: Array[T]).clone() for any T, see genApply. * * In contrast to the descriptor, this string does not contain the surrounding 'L' and ';' for * class types, for example "java/lang/String". diff --git a/src/compiler/scala/tools/nsc/settings/ScalaSettings.scala b/src/compiler/scala/tools/nsc/settings/ScalaSettings.scala index 20ccc30ff6..d22dcacad6 100644 --- a/src/compiler/scala/tools/nsc/settings/ScalaSettings.scala +++ b/src/compiler/scala/tools/nsc/settings/ScalaSettings.scala @@ -42,7 +42,7 @@ trait ScalaSettings extends AbsScalaSettings def optimiseSettings = List[BooleanSetting](inline, inlineHandlers, Xcloselim, Xdce, YconstOptimization) /** If any of these settings is enabled, the compiler should print a message and exit. */ - def infoSettings = List[Setting](help, Xhelp, Yhelp, showPlugins, showPhases, genPhaseGraph) + def infoSettings = List[Setting](version, help, Xhelp, Yhelp, showPlugins, showPhases, genPhaseGraph) /** Is an info setting set? */ def isInfo = infoSettings exists (_.isSetByUser) diff --git a/src/compiler/scala/tools/nsc/symtab/classfile/ICodeReader.scala b/src/compiler/scala/tools/nsc/symtab/classfile/ICodeReader.scala index 6ca2205881..149b4fe446 100644 --- a/src/compiler/scala/tools/nsc/symtab/classfile/ICodeReader.scala +++ b/src/compiler/scala/tools/nsc/symtab/classfile/ICodeReader.scala @@ -780,32 +780,40 @@ abstract class ICodeReader extends ClassfileParser { bb = otherBlock // Console.println("\t> entering bb: " + bb) } - instr match { - case LJUMP(target) => - otherBlock = blocks(target) - bb.emitOnly(JUMP(otherBlock)) - case LCJUMP(success, failure, cond, kind) => - otherBlock = blocks(success) - val failBlock = blocks(failure) - bb.emitOnly(CJUMP(otherBlock, failBlock, cond, kind)) + if (bb.closed) { + // the basic block is closed, i.e. the previous instruction was a jump, return or throw, + // but the next instruction is not a jump target. this means that the next instruction is + // dead code. we can therefore advance until the next jump target. + debuglog(s"ICode reader skipping dead instruction $instr in classfile $instanceCode") + } else { + instr match { + case LJUMP(target) => + otherBlock = blocks(target) + bb.emitOnly(JUMP(otherBlock)) + + case LCJUMP(success, failure, cond, kind) => + otherBlock = blocks(success) + val failBlock = blocks(failure) + bb.emitOnly(CJUMP(otherBlock, failBlock, cond, kind)) - case LCZJUMP(success, failure, cond, kind) => - otherBlock = blocks(success) - val failBlock = blocks(failure) - bb.emitOnly(CZJUMP(otherBlock, failBlock, cond, kind)) + case LCZJUMP(success, failure, cond, kind) => + otherBlock = blocks(success) + val failBlock = blocks(failure) + bb.emitOnly(CZJUMP(otherBlock, failBlock, cond, kind)) - case LSWITCH(tags, targets) => - bb.emitOnly(SWITCH(tags, targets map blocks)) + case LSWITCH(tags, targets) => + bb.emitOnly(SWITCH(tags, targets map blocks)) - case RETURN(_) => - bb emitOnly instr + case RETURN(_) => + bb emitOnly instr - case THROW(clasz) => - bb emitOnly instr + case THROW(clasz) => + bb emitOnly instr - case _ => - bb emit instr + case _ => + bb emit instr + } } } diff --git a/src/compiler/scala/tools/nsc/typechecker/NamesDefaults.scala b/src/compiler/scala/tools/nsc/typechecker/NamesDefaults.scala index dceb0a47d8..284ab2f6f9 100644 --- a/src/compiler/scala/tools/nsc/typechecker/NamesDefaults.scala +++ b/src/compiler/scala/tools/nsc/typechecker/NamesDefaults.scala @@ -174,8 +174,8 @@ trait NamesDefaults { self: Analyzer => // 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 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 + if(qual.pos.isRange && baseFun1.pos.isRange) qual.pos.union(baseFun1.pos).withStart(Math.min(qual.pos.end, baseFun1.pos.end)) + else baseFun1.pos val f = blockTyper.typedOperator(Select(newQual, selected).setSymbol(baseFun1.symbol).setPos(selectPos)) if (funTargs.isEmpty) f else TypeApply(f, funTargs).setType(baseFun.tpe) diff --git a/src/compiler/scala/tools/reflect/ToolBoxFactory.scala b/src/compiler/scala/tools/reflect/ToolBoxFactory.scala index 3b12086cc7..923297bafb 100644 --- a/src/compiler/scala/tools/reflect/ToolBoxFactory.scala +++ b/src/compiler/scala/tools/reflect/ToolBoxFactory.scala @@ -141,6 +141,7 @@ abstract class ToolBoxFactory[U <: JavaUniverse](val u: U) { factorySelf => val run = new Run run.symSource(ownerClass) = NoAbstractFile // need to set file to something different from null, so that currentRun.defines works phase = run.typerPhase // need to set a phase to something <= typerPhase, otherwise implicits in typedSelect will be disabled + globalPhase = run.typerPhase // amazing... looks like phase and globalPhase are different things, so we need to set them separately currentTyper.context.setReportErrors() // need to manually set context mode, otherwise typer.silent will throw exceptions reporter.reset() diff --git a/src/interactive/scala/tools/nsc/interactive/Main.scala b/src/interactive/scala/tools/nsc/interactive/Main.scala index c838606f02..7796c65670 100644 --- a/src/interactive/scala/tools/nsc/interactive/Main.scala +++ b/src/interactive/scala/tools/nsc/interactive/Main.scala @@ -12,7 +12,7 @@ package interactive */ object Main extends nsc.MainClass { override def processSettingsHook(): Boolean = { - if (this.settings.Yidedebug) { + def run(): Unit = { this.settings.Xprintpos.value = true this.settings.Yrangepos.value = true val compiler = new interactive.Global(this.settings, this.reporter) @@ -27,8 +27,9 @@ object Main extends nsc.MainClass { case None => reporter.reset() // Causes other compiler errors to be ignored } askShutdown - false } - else true + super.processSettingsHook() && ( + if (this.settings.Yidedebug) { run() ; false } else true + ) } } diff --git a/src/library/scala/collection/IndexedSeqOptimized.scala b/src/library/scala/collection/IndexedSeqOptimized.scala index ade04e4de8..42cb37aa24 100755 --- a/src/library/scala/collection/IndexedSeqOptimized.scala +++ b/src/library/scala/collection/IndexedSeqOptimized.scala @@ -206,7 +206,7 @@ trait IndexedSeqOptimized[+A, +Repr] extends Any with IndexedSeqLike[A, Repr] { override /*SeqLike*/ def lastIndexWhere(p: A => Boolean, end: Int): Int = { - var i = end + var i = math.min(end, length - 1) while (i >= 0 && !p(this(i))) i -= 1 i } diff --git a/src/library/scala/collection/Iterator.scala b/src/library/scala/collection/Iterator.scala index e321a6adba..f6f46e158f 100644 --- a/src/library/scala/collection/Iterator.scala +++ b/src/library/scala/collection/Iterator.scala @@ -922,6 +922,9 @@ trait Iterator[+A] extends TraversableOnce[A] { /** For reasons which remain to be determined, calling * self.take(n).toSeq cause an infinite loop, so we have * a slight variation on take for local usage. + * NB: self.take.toSeq is slice.toStream, lazily built on self, + * so a subsequent self.hasNext would not test self after the + * group was consumed. */ private def takeDestructively(size: Int): Seq[A] = { val buf = new ArrayBuffer[A] @@ -945,12 +948,10 @@ trait Iterator[+A] extends TraversableOnce[A] { // so the rest of the code can be oblivious val xs: Seq[B] = { val res = takeDestructively(count) - // extra checks so we don't calculate length unless there's reason - if (pad.isDefined && !self.hasNext) { - val shortBy = count - res.length - if (shortBy > 0) res ++ padding(shortBy) else res - } - else res + // was: extra checks so we don't calculate length unless there's reason + // but since we took the group eagerly, just use the fast length + val shortBy = count - res.length + if (shortBy > 0 && pad.isDefined) res ++ padding(shortBy) else res } lazy val len = xs.length lazy val incomplete = len < count diff --git a/src/library/scala/collection/mutable/AVLTree.scala b/src/library/scala/collection/mutable/AVLTree.scala index de09bb2040..cc2acb74d4 100644 --- a/src/library/scala/collection/mutable/AVLTree.scala +++ b/src/library/scala/collection/mutable/AVLTree.scala @@ -14,8 +14,8 @@ package mutable * An immutable AVL Tree implementation formerly used by mutable.TreeSet * * @author Lucien Pereira - * @deprecated("AVLTree and its related classes are being removed from the standard library since they're not different enough from RedBlackTree to justify keeping them.", "2.11.0") */ +@deprecated("AVLTree and its related classes are being removed from the standard library since they're not different enough from RedBlackTree to justify keeping them.", "2.11.2") private[mutable] sealed trait AVLTree[+A] extends Serializable { def balance: Int diff --git a/src/library/scala/concurrent/Channel.scala b/src/library/scala/concurrent/Channel.scala index 067244bd1c..89ad7d8c0e 100644 --- a/src/library/scala/concurrent/Channel.scala +++ b/src/library/scala/concurrent/Channel.scala @@ -10,8 +10,10 @@ package scala.concurrent -/** This class ... +/** This class provides a simple FIFO queue of data objects, + * which are read by one or more reader threads. * + * @tparam A type of data exchanged * @author Martin Odersky * @version 1.0, 10/03/2003 */ @@ -20,11 +22,14 @@ class Channel[A] { var elem: A = _ var next: LinkedList[A] = null } - private var written = new LinkedList[A] // FIFO buffer, realized through + private var written = new LinkedList[A] // FIFO queue, realized through private var lastWritten = written // aliasing of a linked list private var nreaders = 0 - /** + /** Append a value to the FIFO queue to be read by `read`. + * This operation is nonblocking and can be executed by any thread. + * + * @param x object to enqueue to this channel */ def write(x: A) = synchronized { lastWritten.elem = x @@ -33,6 +38,11 @@ class Channel[A] { if (nreaders > 0) notify() } + /** Retrieve the next waiting object from the FIFO queue, + * blocking if necessary until an object is available. + * + * @return next object dequeued from this channel + */ def read: A = synchronized { while (written.next == null) { try { @@ -45,5 +55,4 @@ class Channel[A] { written = written.next x } - } diff --git a/src/library/scala/concurrent/ExecutionContext.scala b/src/library/scala/concurrent/ExecutionContext.scala index a1e94c8876..4674c9174b 100644 --- a/src/library/scala/concurrent/ExecutionContext.scala +++ b/src/library/scala/concurrent/ExecutionContext.scala @@ -77,12 +77,12 @@ trait ExecutionContext { } /** - * Union interface since Java does not support union types + * An [[ExecutionContext]] that is also a Java [[Executor]]. */ trait ExecutionContextExecutor extends ExecutionContext with Executor /** - * Union interface since Java does not support union types + * An [[ExecutionContext]] that is also a Java [[ExecutorService]]. */ trait ExecutionContextExecutorService extends ExecutionContextExecutor with ExecutorService diff --git a/src/library/scala/concurrent/Lock.scala b/src/library/scala/concurrent/Lock.scala index 1c00c0e91f..8d18da2d38 100644 --- a/src/library/scala/concurrent/Lock.scala +++ b/src/library/scala/concurrent/Lock.scala @@ -14,8 +14,8 @@ package scala.concurrent * * @author Martin Odersky * @version 1.0, 10/03/2003 - * @deprecated("Use java.util.concurrent.locks.Lock", "2.11.0") */ +@deprecated("Use java.util.concurrent.locks.Lock", "2.11.2") class Lock { var available = true diff --git a/src/library/scala/concurrent/SyncVar.scala b/src/library/scala/concurrent/SyncVar.scala index d5dc3d7e3f..494c955833 100644 --- a/src/library/scala/concurrent/SyncVar.scala +++ b/src/library/scala/concurrent/SyncVar.scala @@ -13,6 +13,7 @@ import java.util.concurrent.TimeUnit /** A class to provide safe concurrent access to a mutable cell. * All methods are synchronized. * + * @tparam A type of the contained value * @author Martin Odersky * @version 1.0, 10/03/2003 */ @@ -20,6 +21,12 @@ class SyncVar[A] { private var isDefined: Boolean = false private var value: Option[A] = None + /** + * Waits for this SyncVar to become defined and returns + * the result, without modifying the stored value. + * + * @return value that is held in this container + */ def get: A = synchronized { while (!isDefined) wait() value.get @@ -57,8 +64,12 @@ class SyncVar[A] { value } - /** Waits for this SyncVar to become defined and returns - * the result */ + /** + * Waits for this SyncVar to become defined and returns + * the result, unsetting the stored value before returning. + * + * @return value that was held in this container + */ def take(): A = synchronized { try get finally unsetVal() @@ -129,4 +140,3 @@ class SyncVar[A] { } } - diff --git a/src/library/scala/concurrent/package.scala b/src/library/scala/concurrent/package.scala index cc1350f5a9..4d88253de4 100644 --- a/src/library/scala/concurrent/package.scala +++ b/src/library/scala/concurrent/package.scala @@ -55,6 +55,11 @@ package object concurrent { } package concurrent { + /** + * This marker trait is used by [[Await]] to ensure that [[Awaitable.ready]] and [[Awaitable.result]] + * are not directly called by user code. An implicit instance of this trait is only available when + * user code is currently calling the methods on [[Await]]. + */ @implicitNotFound("Don't call `Awaitable` methods directly, use the `Await` object.") sealed trait CanAwait diff --git a/src/library/scala/util/Properties.scala b/src/library/scala/util/Properties.scala index d597feb898..2daa4de9a6 100644 --- a/src/library/scala/util/Properties.scala +++ b/src/library/scala/util/Properties.scala @@ -155,9 +155,12 @@ private[scala] trait PropertiesTrait { // This is looking for javac, tools.jar, etc. // Tries JDK_HOME first, then the more common but likely jre JAVA_HOME, // and finally the system property based javaHome. - def jdkHome = envOrElse("JDK_HOME", envOrElse("JAVA_HOME", javaHome)) + def jdkHome = envOrElse("JDK_HOME", envOrElse("JAVA_HOME", javaHome)) - def versionMsg = "Scala %s %s -- %s".format(propCategory, versionString, copyrightString) + // private[scala] for 2.12 + private[this] def versionFor(command: String) = f"Scala $command $versionString -- $copyrightString" + + def versionMsg = versionFor(propCategory) def scalaCmd = if (isWin) "scala.bat" else "scala" def scalacCmd = if (isWin) "scalac.bat" else "scalac" diff --git a/src/reflect/scala/reflect/internal/util/SourceFile.scala b/src/reflect/scala/reflect/internal/util/SourceFile.scala index 4fccad74ac..a2642628a4 100644 --- a/src/reflect/scala/reflect/internal/util/SourceFile.scala +++ b/src/reflect/scala/reflect/internal/util/SourceFile.scala @@ -40,7 +40,7 @@ abstract class SourceFile { def lineToString(index: Int): String = { val start = lineToOffset(index) var end = start - while (!isEndOfLine(end) && end <= length) end += 1 + while (end < length && !isEndOfLine(end)) end += 1 new String(content, start, end - start) } diff --git a/src/reflect/scala/reflect/runtime/package.scala b/src/reflect/scala/reflect/runtime/package.scala index 3c9bbccba3..e240bed0a7 100644 --- a/src/reflect/scala/reflect/runtime/package.scala +++ b/src/reflect/scala/reflect/runtime/package.scala @@ -30,7 +30,8 @@ package runtime { import c.universe._ val runtimeClass = c.reifyEnclosingRuntimeClass if (runtimeClass.isEmpty) c.abort(c.enclosingPosition, "call site does not have an enclosing class") - val runtimeUniverse = Select(Select(Select(Ident(newTermName("scala")), newTermName("reflect")), newTermName("runtime")), newTermName("universe")) + val scalaPackage = Select(Ident(newTermName("_root_")), newTermName("scala")) + val runtimeUniverse = Select(Select(Select(scalaPackage, newTermName("reflect")), newTermName("runtime")), newTermName("universe")) val currentMirror = Apply(Select(runtimeUniverse, newTermName("runtimeMirror")), List(Select(runtimeClass, newTermName("getClassLoader")))) c.Expr[Nothing](currentMirror)(c.WeakTypeTag.Nothing) } diff --git a/src/repl/scala/tools/nsc/MainGenericRunner.scala b/src/repl/scala/tools/nsc/MainGenericRunner.scala index 43f0ea1256..34057ed341 100644 --- a/src/repl/scala/tools/nsc/MainGenericRunner.scala +++ b/src/repl/scala/tools/nsc/MainGenericRunner.scala @@ -8,7 +8,6 @@ package tools.nsc import io.{ File } import util.{ ClassPath, ScalaClassLoader } -import Properties.{ versionString, copyrightString } import GenericRunnerCommand._ object JarRunner extends CommonRunner { @@ -28,79 +27,78 @@ object JarRunner extends CommonRunner { } /** An object that runs Scala code. It has three possible - * sources for the code to run: pre-compiled code, a script file, - * or interactive entry. - */ + * sources for the code to run: pre-compiled code, a script file, + * or interactive entry. + */ class MainGenericRunner { - def errorFn(ex: Throwable): Boolean = { - ex.printStackTrace() - false - } - def errorFn(str: String): Boolean = { - Console.err println str - false + def errorFn(str: String, e: Option[Throwable] = None, isFailure: Boolean = true): Boolean = { + if (str.nonEmpty) Console.err println str + e foreach (_.printStackTrace()) + !isFailure } def process(args: Array[String]): Boolean = { val command = new GenericRunnerCommand(args.toList, (x: String) => errorFn(x)) - import command.{ settings, howToRun, thingToRun } - def sampleCompiler = new Global(settings) // def so its not created unless needed - - if (!command.ok) return errorFn("\n" + command.shortUsageMsg) - else if (settings.version) return errorFn("Scala code runner %s -- %s".format(versionString, copyrightString)) - else if (command.shouldStopWithInfo) return errorFn(command getInfoMessage sampleCompiler) - - def isE = !settings.execute.isDefault - def dashe = settings.execute.value - - def isI = !settings.loadfiles.isDefault - def dashi = settings.loadfiles.value - - // Deadlocks on startup under -i unless we disable async. - if (isI) - settings.Yreplsync.value = true - - def combinedCode = { - val files = if (isI) dashi map (file => File(file).slurp()) else Nil - val str = if (isE) List(dashe) else Nil - - files ++ str mkString "\n\n" - } - - def runTarget(): Either[Throwable, Boolean] = howToRun match { - case AsObject => - ObjectRunner.runAndCatch(settings.classpathURLs, thingToRun, command.arguments) - case AsScript => - ScriptRunner.runScriptAndCatch(settings, thingToRun, command.arguments) - case AsJar => - JarRunner.runJar(settings, thingToRun, command.arguments) - case Error => - Right(false) - case _ => - // We start the repl when no arguments are given. - Right(new interpreter.ILoop process settings) + import command.{ settings, howToRun, thingToRun, shortUsageMsg, shouldStopWithInfo } + def sampleCompiler = new Global(settings) // def so it's not created unless needed + + def run(): Boolean = { + def isE = !settings.execute.isDefault + def dashe = settings.execute.value + + def isI = !settings.loadfiles.isDefault + def dashi = settings.loadfiles.value + + // Deadlocks on startup under -i unless we disable async. + if (isI) + settings.Yreplsync.value = true + + def combinedCode = { + val files = if (isI) dashi map (file => File(file).slurp()) else Nil + val str = if (isE) List(dashe) else Nil + + files ++ str mkString "\n\n" + } + + def runTarget(): Either[Throwable, Boolean] = howToRun match { + case AsObject => + ObjectRunner.runAndCatch(settings.classpathURLs, thingToRun, command.arguments) + case AsScript => + ScriptRunner.runScriptAndCatch(settings, thingToRun, command.arguments) + case AsJar => + JarRunner.runJar(settings, thingToRun, command.arguments) + case Error => + Right(false) + case _ => + // We start the repl when no arguments are given. + Right(new interpreter.ILoop process settings) + } + + /** If -e and -i were both given, we want to execute the -e code after the + * -i files have been included, so they are read into strings and prepended to + * the code given in -e. The -i option is documented to only make sense + * interactively so this is a pretty reasonable assumption. + * + * This all needs a rewrite though. + */ + if (isE) { + ScriptRunner.runCommand(settings, combinedCode, thingToRun +: command.arguments) + } + else runTarget() match { + case Left(ex) => errorFn("", Some(ex)) // there must be a useful message of hope to offer here + case Right(b) => b + } } - /** If -e and -i were both given, we want to execute the -e code after the - * -i files have been included, so they are read into strings and prepended to - * the code given in -e. The -i option is documented to only make sense - * interactively so this is a pretty reasonable assumption. - * - * This all needs a rewrite though. - */ - if (isE) { - ScriptRunner.runCommand(settings, combinedCode, thingToRun +: command.arguments) - } - else runTarget() match { - case Left(ex) => errorFn(ex) - case Right(b) => b - } + if (!command.ok) + errorFn(f"%n$shortUsageMsg") + else if (shouldStopWithInfo) + errorFn(command getInfoMessage sampleCompiler, isFailure = false) + else + run() } } object MainGenericRunner extends MainGenericRunner { - def main(args: Array[String]) { - if (!process(args)) - sys.exit(1) - } + def main(args: Array[String]): Unit = if (!process(args)) sys.exit(1) } diff --git a/test/files/neg/t6289.check b/test/files/neg/t6289.check index f6f43cabd3..989932750f 100644 --- a/test/files/neg/t6289.check +++ b/test/files/neg/t6289.check @@ -3,7 +3,7 @@ t6289/J.java:2: method does not override or implement a method from a supertype @Override public void foo() { } ^ 1 error -#partest java7 +#partest !java6 t6289/J.java:2: error: method does not override or implement a method from a supertype @Override public void foo() { } ^ diff --git a/test/files/neg/t8630.check b/test/files/neg/t8630.check new file mode 100644 index 0000000000..98b084b153 --- /dev/null +++ b/test/files/neg/t8630.check @@ -0,0 +1,7 @@ +t8630.scala:1: error: '{' expected but 'abstract' found. +package bobsdelights abstract class Fruit( val name: String, val color: String ) object Fruits { object Apple extends Fruit("apple", "red") object Orange extends Fruit("orange", "orange") object Pear extends Fruit("pear", "yellowish") val menu = List(Apple, Orange, Pear) } + ^ +t8630.scala:1: error: '}' expected but eof found. +package bobsdelights abstract class Fruit( val name: String, val color: String ) object Fruits { object Apple extends Fruit("apple", "red") object Orange extends Fruit("orange", "orange") object Pear extends Fruit("pear", "yellowish") val menu = List(Apple, Orange, Pear) } + ^ +two errors found diff --git a/test/files/neg/t8630.scala b/test/files/neg/t8630.scala new file mode 100644 index 0000000000..ea25227452 --- /dev/null +++ b/test/files/neg/t8630.scala @@ -0,0 +1 @@ +package bobsdelights abstract class Fruit( val name: String, val color: String ) object Fruits { object Apple extends Fruit("apple", "red") object Orange extends Fruit("orange", "orange") object Pear extends Fruit("pear", "yellowish") val menu = List(Apple, Orange, Pear) }
\ No newline at end of file diff --git a/test/files/pos/t8596.flags b/test/files/pos/t8596.flags new file mode 100644 index 0000000000..281f0a10cd --- /dev/null +++ b/test/files/pos/t8596.flags @@ -0,0 +1 @@ +-Yrangepos diff --git a/test/files/pos/t8596.scala b/test/files/pos/t8596.scala new file mode 100644 index 0000000000..bfed58eadf --- /dev/null +++ b/test/files/pos/t8596.scala @@ -0,0 +1,7 @@ +class TypeTreeObjects { + class Container { + def typeParamAndDefaultArg[C](name: String = ""): String = "" + } + // crashed under -Yrangepos + new Container().typeParamAndDefaultArg[Any]() +} diff --git a/test/files/presentation/ide-bug-1000531.check b/test/files/presentation/ide-bug-1000531.check index d8c7a369f7..12eafcd6de 100644 --- a/test/files/presentation/ide-bug-1000531.check +++ b/test/files/presentation/ide-bug-1000531.check @@ -1,111 +1,24 @@ -reload: CrashOnLoad.scala +reload: CrashOnLoad.scala, TestIterable.java -askTypeCompletion at CrashOnLoad.scala(6,12) +askTypeCompletion at CrashOnLoad.scala(6,11) ================================================================================ -[response] askTypeCompletion at (6,12) -retrieved 117 members +[response] askTypeCompletion at (6,11) +retrieved 30 members [inaccessible] protected[package lang] def clone(): Object [inaccessible] protected[package lang] def finalize(): Unit -[inaccessible] protected[this] def reversed: List[B] -class GroupedIterator[B >: A] extends AbstractIterator[Seq[B]] with Iterator[Seq[B]] def +(other: String): String -def ++[B >: B](that: => scala.collection.GenTraversableOnce[B]): Iterator[B] -def ->[B](y: B): (java.util.Iterator[B], B) -def /:[B](z: B)(op: (B, B) => B): B -def :\[B](z: B)(op: (B, B) => B): B -def addString(b: StringBuilder): StringBuilder -def addString(b: StringBuilder,sep: String): StringBuilder -def addString(b: StringBuilder,start: String,sep: String,end: String): StringBuilder -def aggregate[B](z: => B)(seqop: (B, B) => B,combop: (B, B) => B): B -def buffered: scala.collection.BufferedIterator[B] -def collectFirst[B](pf: PartialFunction[B,B]): Option[B] -def collect[B](pf: PartialFunction[B,B]): Iterator[B] -def contains(elem: Any): Boolean -def copyToArray[B >: B](xs: Array[B]): Unit -def copyToArray[B >: B](xs: Array[B],start: Int): Unit -def copyToArray[B >: B](xs: Array[B],start: Int,len: Int): Unit -def copyToBuffer[B >: B](dest: scala.collection.mutable.Buffer[B]): Unit -def corresponds[B](that: scala.collection.GenTraversableOnce[B])(p: (B, B) => Boolean): Boolean -def count(p: B => Boolean): Int -def drop(n: Int): Iterator[B] -def dropWhile(p: B => Boolean): Iterator[B] -def duplicate: (Iterator[B], Iterator[B]) -def ensuring(cond: Boolean): java.util.Iterator[B] -def ensuring(cond: Boolean,msg: => Any): java.util.Iterator[B] -def ensuring(cond: java.util.Iterator[B] => Boolean): java.util.Iterator[B] -def ensuring(cond: java.util.Iterator[B] => Boolean,msg: => Any): java.util.Iterator[B] +def ->[B](y: B): (other.TestIterator[Nothing], B) +def ensuring(cond: Boolean): other.TestIterator[Nothing] +def ensuring(cond: Boolean,msg: => Any): other.TestIterator[Nothing] +def ensuring(cond: other.TestIterator[Nothing] => Boolean): other.TestIterator[Nothing] +def ensuring(cond: other.TestIterator[Nothing] => Boolean,msg: => Any): other.TestIterator[Nothing] def equals(x$1: Any): Boolean -def exists(p: B => Boolean): Boolean -def filter(p: B => Boolean): Iterator[B] -def filterNot(p: B => Boolean): Iterator[B] -def find(p: B => Boolean): Option[B] -def flatMap[B](f: B => scala.collection.GenTraversableOnce[B]): Iterator[B] -def foldLeft[B](z: B)(op: (B, B) => B): B -def foldRight[B](z: B)(op: (B, B) => B): B -def fold[A1 >: B](z: A1)(op: (A1, A1) => A1): A1 -def forall(p: B => Boolean): Boolean -def foreach[U](f: B => U): Unit def formatted(fmtstr: String): String -def grouped[B >: B](size: Int): Iterator[B]#GroupedIterator[B] -def hasDefiniteSize: Boolean -def hasNext(): Boolean +def hasNext: Boolean def hashCode(): Int -def indexOf[B >: B](elem: B): Int -def indexWhere(p: B => Boolean): Int -def isEmpty: Boolean -def isTraversableAgain: Boolean -def length: Int -def map[B](f: B => B): Iterator[B] -def maxBy[B](f: B => B)(implicit cmp: Ordering[B]): B -def max[B >: B](implicit cmp: Ordering[B]): B -def minBy[B](f: B => B)(implicit cmp: Ordering[B]): B -def min[B >: B](implicit cmp: Ordering[B]): B -def mkString(sep: String): String -def mkString(start: String,sep: String,end: String): String -def mkString: String -def next(): B -def nonEmpty: Boolean -def padTo[A1 >: B](len: Int,elem: A1): Iterator[A1] -def partition(p: B => Boolean): (Iterator[B], Iterator[B]) -def patch[B >: B](from: Int,patchElems: Iterator[B],replaced: Int): Iterator[B] -def product[B >: B](implicit num: Numeric[B]): B -def reduceLeftOption[B >: B](op: (B, B) => B): Option[B] -def reduceLeft[B >: B](op: (B, B) => B): B -def reduceOption[A1 >: B](op: (A1, A1) => A1): Option[A1] -def reduceRightOption[B >: B](op: (B, B) => B): Option[B] -def reduceRight[B >: B](op: (B, B) => B): B -def reduce[A1 >: B](op: (A1, A1) => A1): A1 -def remove(): Unit -def sameElements(that: Iterator[_]): Boolean -def scanLeft[B](z: B)(op: (B, B) => B): Iterator[B] -def scanRight[B](z: B)(op: (B, B) => B): Iterator[B] -def seq: Iterator[B] -def size: Int -def slice(from: Int,until: Int): Iterator[B] -def sliding[B >: B](size: Int,step: Int): Iterator[B]#GroupedIterator[B] -def span(p: B => Boolean): (Iterator[B], Iterator[B]) -def sum[B >: B](implicit num: Numeric[B]): B -def take(n: Int): Iterator[B] -def takeWhile(p: B => Boolean): Iterator[B] -def toArray[B >: B](implicit evidence$1: scala.reflect.ClassTag[B]): Array[B] -def toBuffer[B >: B]: scala.collection.mutable.Buffer[B] -def toIndexedSeq: scala.collection.immutable.IndexedSeq[B] -def toIterable: Iterable[B] -def toIterator: Iterator[B] -def toList: List[B] -def toMap[T, U](implicit ev: <:<[B,(T, U)]): scala.collection.immutable.Map[T,U] -def toSeq: Seq[B] -def toSet[B >: B]: scala.collection.immutable.Set[B] -def toStream: scala.collection.immutable.Stream[B] +def next: T def toString(): String -def toTraversable: Traversable[B] -def toVector: Vector[B] -def to[Col[_]](implicit cbf: scala.collection.generic.CanBuildFrom[Nothing,B,Col[B]]): Col[B] -def withFilter(p: B => Boolean): Iterator[B] -def zipAll[B, A1 >: B, B1 >: B](that: Iterator[B],thisElem: A1,thatElem: B1): Iterator[(A1, B1)] -def zipWithIndex: Iterator[(B, Int)] -def zip[B](that: Iterator[B]): Iterator[(B, B)] -def →[B](y: B): (java.util.Iterator[B], B) +def →[B](y: B): (other.TestIterator[Nothing], B) final def !=(x$1: Any): Boolean final def ##(): Int final def ==(x$1: Any): Boolean diff --git a/test/files/presentation/ide-bug-1000531/src/CrashOnLoad.scala b/test/files/presentation/ide-bug-1000531/src/CrashOnLoad.scala index 878bbfa19e..3f59282083 100644 --- a/test/files/presentation/ide-bug-1000531/src/CrashOnLoad.scala +++ b/test/files/presentation/ide-bug-1000531/src/CrashOnLoad.scala @@ -1,7 +1,14 @@ /** When this files is opened within the IDE, a typing error is reported. */ -class A[B] extends java.lang.Iterable[B] { +class A[B] extends TestIterable[B] { import scala.collection.JavaConversions._ - def iterator = Iterator.empty + def iterator: other.TestIterator[Nothing] = ??? - iterator. /*!*/ -}
\ No newline at end of file + iterator./*!*/ +} + +object other { + trait TestIterator[T] { + def hasNext: Boolean + def next: T + } +} diff --git a/test/files/presentation/ide-bug-1000531/src/TestIterable.java b/test/files/presentation/ide-bug-1000531/src/TestIterable.java new file mode 100644 index 0000000000..84a6fe77f1 --- /dev/null +++ b/test/files/presentation/ide-bug-1000531/src/TestIterable.java @@ -0,0 +1,7 @@ +public abstract class TestIterable<T> { + public abstract TestIterator<T> iterator(); + public static abstract class TestIterator<T> { + public abstract T next(); + public abstract boolean hasNext(); + } +} diff --git a/test/files/presentation/t7915.check b/test/files/presentation/t7915.check index b18b4ddb55..0849aaa82b 100644 --- a/test/files/presentation/t7915.check +++ b/test/files/presentation/t7915.check @@ -9,3 +9,23 @@ askHyperlinkPos for `bar` at (7,22) Foo.scala ================================================================================ [response] found askHyperlinkPos for `bar` at (2,7) Foo.scala ================================================================================ + +askHyperlinkPos for `Bar` at (8,11) Foo.scala +================================================================================ +[response] found askHyperlinkPos for `Bar` at (1,7) Foo.scala +================================================================================ + +askHyperlinkPos for `baz` at (8,22) Foo.scala +================================================================================ +[response] found askHyperlinkPos for `baz` at (2,31) Foo.scala +================================================================================ + +askHyperlinkPos for `Bar` at (9,11) Foo.scala +================================================================================ +[response] found askHyperlinkPos for `Bar` at (1,7) Foo.scala +================================================================================ + +askHyperlinkPos for `baz` at (9,22) Foo.scala +================================================================================ +[response] found askHyperlinkPos for `baz` at (2,31) Foo.scala +================================================================================ diff --git a/test/files/presentation/t7915/src/Foo.scala b/test/files/presentation/t7915/src/Foo.scala index a4166ae5b4..5c9ca36a6e 100644 --- a/test/files/presentation/t7915/src/Foo.scala +++ b/test/files/presentation/t7915/src/Foo.scala @@ -1,9 +1,11 @@ class Bar { - def bar(b: Int = 2) {} + def bar(b: Int = 2) {}; def baz[X](b: Int = 2) {} } class Foo { def foo() { new Bar/*#*/().bar/*#*/() + new Bar/*#*/().baz/*#*/[Any]() + new Bar/*#*/().baz/*#*/() } } diff --git a/test/files/run/icode-reader-dead-code.check b/test/files/run/icode-reader-dead-code.check new file mode 100644 index 0000000000..d1739fed3b --- /dev/null +++ b/test/files/run/icode-reader-dead-code.check @@ -0,0 +1,19 @@ +Bytecode for method f + L0 + LINENUMBER 4 L0 + ICONST_1 + IRETURN + L1 + LOCALVARIABLE this Lp/A; L0 L1 0 + MAXSTACK = 1 + MAXLOCALS = 1 +Bytecode for method f + L0 + LINENUMBER 4 L0 + ICONST_1 + ATHROW + IRETURN + L1 + LOCALVARIABLE this Lp/A; L0 L1 0 + MAXSTACK = 1 + MAXLOCALS = 1 diff --git a/test/files/run/icode-reader-dead-code.scala b/test/files/run/icode-reader-dead-code.scala new file mode 100644 index 0000000000..00ba58829f --- /dev/null +++ b/test/files/run/icode-reader-dead-code.scala @@ -0,0 +1,82 @@ +import java.io.{FileOutputStream, FileInputStream} + +import scala.tools.asm.{ClassWriter, Opcodes, ClassReader} +import scala.tools.asm.tree.{InsnNode, ClassNode} +import scala.tools.nsc.backend.jvm.AsmUtils +import scala.tools.partest.DirectTest +import scala.collection.JavaConverters._ + +/** + * Test that the ICodeReader does not crash if the bytecode of a method has unreachable code. + */ +object Test extends DirectTest { + def code: String = ??? + + def show(): Unit = { + // The bytecode of f will be modified using ASM by `addDeadCode` + val aCode = + """ + |package p + |class A { + | @inline final def f = 1 + |} + """.stripMargin + + val bCode = + """ + |package p + |class B { + | def g = (new A()).f + |} + """.stripMargin + + compileString(newCompiler("-usejavacp"))(aCode) + + addDeadCode() + + // If inlining fails, the compiler will issue an inliner warning that is not present in the + // check file + compileString(newCompiler("-usejavacp", "-optimise"))(bCode) + } + + def readClass(file: String) = { + val cnode = new ClassNode() + val is = new FileInputStream(file) + val reader = new ClassReader(is) + reader.accept(cnode, 0) + is.close() + cnode + } + + def writeClass(file: String, cnode: ClassNode): Unit = { + val writer = new ClassWriter(0) + cnode.accept(writer) + + val os = new FileOutputStream(file) + os.write(writer.toByteArray) + os.close() + } + + def addDeadCode() { + val file = (testOutput / "p" / "A.class").path + val cnode = readClass(file) + val method = cnode.methods.asScala.find(_.name == "f").head + + AsmUtils.traceMethod(method) + + val insns = method.instructions + val it = insns.iterator() + while (it.hasNext) { + val in = it.next() + if (in.getOpcode == Opcodes.IRETURN) { + // Insert an ATHROW before the IRETURN. The IRETURN will then be dead code. + // The ICodeReader should not crash if there's dead code. + insns.insert(in.getPrevious, new InsnNode(Opcodes.ATHROW)) + } + } + + AsmUtils.traceMethod(method) + + writeClass(file, cnode) + } +} diff --git a/test/files/run/repl-javap-app.check b/test/files/run/repl-javap-app.check index 490860585c..1136b415d7 100644 --- a/test/files/run/repl-javap-app.check +++ b/test/files/run/repl-javap-app.check @@ -1,4 +1,5 @@ #partest java6 +Welcome to Scala Type in expressions to have them evaluated. Type :help for more information. @@ -6,16 +7,17 @@ scala> :javap -app MyApp$ public final void delayedEndpoint$MyApp$1(); Code: Stack=2, Locals=1, Args_size=1 - 0: getstatic #61; //Field scala/Console$.MODULE$:Lscala/Console$; - 3: ldc #63; //String Hello, delayed world. - 5: invokevirtual #67; //Method scala/Console$.println:(Ljava/lang/Object;)V + 0: getstatic #XX; //Field scala/Console$.MODULE$:Lscala/Console$; + 3: ldc #XX; //String Hello, delayed world. + 5: invokevirtual #XX; //Method scala/Console$.println:(Ljava/lang/Object;)V 8: return LocalVariableTable: Start Length Slot Name Signature 0 9 0 this LMyApp$; scala> -#partest !java6 +#partest java7 +Welcome to Scala Type in expressions to have them evaluated. Type :help for more information. @@ -24,9 +26,9 @@ scala> :javap -app MyApp$ flags: ACC_PUBLIC, ACC_FINAL Code: stack=2, locals=1, args_size=1 - 0: getstatic #61 // Field scala/Console$.MODULE$:Lscala/Console$; - 3: ldc #63 // String Hello, delayed world. - 5: invokevirtual #67 // Method scala/Console$.println:(Ljava/lang/Object;)V + 0: getstatic #XX // Field scala/Console$.MODULE$:Lscala/Console$; + 3: ldc #XX // String Hello, delayed world. + 5: invokevirtual #XX // Method scala/Console$.println:(Ljava/lang/Object;)V 8: return LocalVariableTable: Start Length Slot Name Signature @@ -36,3 +38,26 @@ scala> :javap -app MyApp$ } scala> +#partest java8 +Welcome to Scala +Type in expressions to have them evaluated. +Type :help for more information. + +scala> :javap -app MyApp$ + public final void delayedEndpoint$MyApp$1(); + descriptor: ()V + flags: ACC_PUBLIC, ACC_FINAL + Code: + stack=2, locals=1, args_size=1 + 0: getstatic #XX // Field scala/Console$.MODULE$:Lscala/Console$; + 3: ldc #XX // String Hello, delayed world. + 5: invokevirtual #XX // Method scala/Console$.println:(Ljava/lang/Object;)V + 8: return + LocalVariableTable: + Start Length Slot Name Signature + 0 9 0 this LMyApp$; + LineNumberTable: + line 5: 0 +} + +scala> diff --git a/test/files/run/repl-javap-app.scala b/test/files/run/repl-javap-app.scala index be04920be1..ad6076c2d5 100644 --- a/test/files/run/repl-javap-app.scala +++ b/test/files/run/repl-javap-app.scala @@ -7,4 +7,15 @@ object MyApp extends App { object Test extends ReplTest { def code = ":javap -app MyApp$" + + override def welcoming = true + + // The constant pool indices are not the same for GenASM / GenBCode, so + // replacing the exact numbers by XX. + lazy val hasConstantPoolRef = """(.*)(#\d\d)(.*)""".r + + override def normalize(s: String) = s match { + case hasConstantPoolRef(start, ref, end) => start + "#XX" + end + case _ => super.normalize(s) + } } diff --git a/test/files/run/t7974.check b/test/files/run/t7974.check index 0be496d8d0..d8152d3286 100644 --- a/test/files/run/t7974.check +++ b/test/files/run/t7974.check @@ -1,6 +1,5 @@ public class Symbols { - // compiled from: Symbols.scala @@ -18,20 +17,14 @@ public class Symbols { // access flags 0x9 public static <clinit>()V - L0 - LINENUMBER 2 L0 GETSTATIC scala/Symbol$.MODULE$ : Lscala/Symbol$; LDC "Symbolic1" INVOKEVIRTUAL scala/Symbol$.apply (Ljava/lang/String;)Lscala/Symbol; PUTSTATIC Symbols.symbol$1 : Lscala/Symbol; - L1 - LINENUMBER 3 L1 GETSTATIC scala/Symbol$.MODULE$ : Lscala/Symbol$; LDC "Symbolic2" INVOKEVIRTUAL scala/Symbol$.apply (Ljava/lang/String;)Lscala/Symbol; PUTSTATIC Symbols.symbol$2 : Lscala/Symbol; - L2 - LINENUMBER 5 L2 GETSTATIC scala/Symbol$.MODULE$ : Lscala/Symbol$; LDC "Symbolic3" INVOKEVIRTUAL scala/Symbol$.apply (Ljava/lang/String;)Lscala/Symbol; @@ -42,63 +35,41 @@ public class Symbols { // access flags 0x1 public someSymbol1()Lscala/Symbol; - L0 - LINENUMBER 2 L0 GETSTATIC Symbols.symbol$1 : Lscala/Symbol; ARETURN - L1 - LOCALVARIABLE this LSymbols; L0 L1 0 MAXSTACK = 1 MAXLOCALS = 1 // access flags 0x1 public someSymbol2()Lscala/Symbol; - L0 - LINENUMBER 3 L0 GETSTATIC Symbols.symbol$2 : Lscala/Symbol; ARETURN - L1 - LOCALVARIABLE this LSymbols; L0 L1 0 MAXSTACK = 1 MAXLOCALS = 1 // access flags 0x1 public sameSymbol1()Lscala/Symbol; - L0 - LINENUMBER 4 L0 GETSTATIC Symbols.symbol$1 : Lscala/Symbol; ARETURN - L1 - LOCALVARIABLE this LSymbols; L0 L1 0 MAXSTACK = 1 MAXLOCALS = 1 // access flags 0x1 public someSymbol3()Lscala/Symbol; - L0 - LINENUMBER 5 L0 ALOAD 0 GETFIELD Symbols.someSymbol3 : Lscala/Symbol; ARETURN - L1 - LOCALVARIABLE this LSymbols; L0 L1 0 MAXSTACK = 1 MAXLOCALS = 1 // access flags 0x1 public <init>()V - L0 - LINENUMBER 6 L0 ALOAD 0 INVOKESPECIAL java/lang/Object.<init> ()V - L1 - LINENUMBER 5 L1 ALOAD 0 GETSTATIC Symbols.symbol$3 : Lscala/Symbol; PUTFIELD Symbols.someSymbol3 : Lscala/Symbol; RETURN - L2 - LOCALVARIABLE this LSymbols; L0 L2 0 MAXSTACK = 2 MAXLOCALS = 1 } diff --git a/test/files/run/t7974/Test.scala b/test/files/run/t7974/Test.scala index 433d9061a7..29d2b9cb64 100644 --- a/test/files/run/t7974/Test.scala +++ b/test/files/run/t7974/Test.scala @@ -6,7 +6,7 @@ import scala.tools.nsc.util.stringFromWriter object Test extends BytecodeTest { def show { - val classNode = loadClassNode("Symbols", skipDebugInfo = false) + val classNode = loadClassNode("Symbols", skipDebugInfo = true) val textifier = new Textifier classNode.accept(new TraceClassVisitor(null, textifier, null)) diff --git a/test/files/run/t8637.check b/test/files/run/t8637.check new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/test/files/run/t8637.check diff --git a/test/files/run/t8637.scala b/test/files/run/t8637.scala new file mode 100644 index 0000000000..99c8d4c413 --- /dev/null +++ b/test/files/run/t8637.scala @@ -0,0 +1,9 @@ +import scala.reflect.runtime.universe._ +import scala.reflect.runtime.currentMirror +import scala.tools.reflect.ToolBox + +object Test extends App { + val tb = currentMirror.mkToolBox() + tb.compile(q"true > true") + tb.typecheck(q"true > true") +}
\ No newline at end of file diff --git a/test/junit/scala/collection/IndexedSeqOptimizedTest.scala b/test/junit/scala/collection/IndexedSeqOptimizedTest.scala new file mode 100644 index 0000000000..e5382907af --- /dev/null +++ b/test/junit/scala/collection/IndexedSeqOptimizedTest.scala @@ -0,0 +1,16 @@ +package scala.collection + +import org.junit.runner.RunWith +import org.junit.runners.JUnit4 +import org.junit.Assert._ +import org.junit.Test + +@RunWith(classOf[JUnit4]) +class IndexedSeqOptimizedTest { + + @Test + def notThrowsAnExceptionInLastIndexOf() { + assertEquals(0, (Array(2): collection.mutable.WrappedArray[Int]).lastIndexWhere(_ => true, 1)) + assertEquals(2, "abc123".lastIndexWhere(_.isLetter, 6)) + } +} diff --git a/test/junit/scala/collection/IteratorTest.scala b/test/junit/scala/collection/IteratorTest.scala index cb7cbb40bc..b7a9805c9f 100644 --- a/test/junit/scala/collection/IteratorTest.scala +++ b/test/junit/scala/collection/IteratorTest.scala @@ -17,4 +17,12 @@ class IteratorTest { slidingIt.next assertEquals("Counter should be one, that means we didn't look further than needed", 1, counter) } + + @Test def groupedIteratorIsLazyWhenPadded(): Unit = { + var counter = 0 + def it = new Iterator[Int] { var i = 0 ; def hasNext = { counter = i; true } ; def next = { i += 1; i } } + val slidingIt = it sliding 2 withPadding -1 + slidingIt.next + assertEquals("Counter should be one, that means we didn't look further than needed", 1, counter) + } } diff --git a/test/junit/scala/reflect/internal/util/SourceFileTest.scala b/test/junit/scala/reflect/internal/util/SourceFileTest.scala index 903e705ba2..cad23eba14 100644 --- a/test/junit/scala/reflect/internal/util/SourceFileTest.scala +++ b/test/junit/scala/reflect/internal/util/SourceFileTest.scala @@ -17,6 +17,11 @@ class SourceFileTest { assertFalse(file.isEndOfLine(Int.MaxValue)) } + @Test def si8630_lineToString(): Unit = { + val code = "abc " + assertEquals(code, new BatchSourceFile("", code).lineToString(0)) + } + @Test def si8205_lineToString(): Unit = { assertEquals("", lineContentOf("", 0)) |