diff options
175 files changed, 2102 insertions, 502 deletions
diff --git a/.gitignore b/.gitignore index 32a1665721..20d700dd12 100644 --- a/.gitignore +++ b/.gitignore @@ -39,9 +39,9 @@ # eclipse, intellij /.classpath /.project -/src/intellij/*.iml -/src/intellij/*.ipr -/src/intellij/*.iws +/src/intellij*/*.iml +/src/intellij*/*.ipr +/src/intellij*/*.iws **/.cache /.idea /.settings @@ -272,28 +272,36 @@ TODO: </artifact:dependencies> <!-- JUnit --> - <property name="junit.version" value="4.10"/> + <property name="junit.version" value="4.11"/> <artifact:dependencies pathId="junit.classpath" filesetId="junit.fileset"> <dependency groupId="junit" artifactId="junit" version="${junit.version}"/> </artifact:dependencies> <copy-deps project="junit"/> <!-- Pax runner --> - <property name="pax.exam.version" value="2.6.0"/> + <property name="pax.exam.version" value="3.5.0"/><!-- Last version which supports Java 6 --> + <property name="osgi.felix.version" value="4.0.3"/> + <property name="osgi.equinox.version" value="3.7.1"/> <artifact:dependencies pathId="pax.exam.classpath" filesetId="pax.exam.fileset"> - <dependency groupId="org.ops4j.pax.exam" artifactId="pax-exam-container-native" version="${pax.exam.version}"/> + <dependency groupId="org.ops4j.pax.exam" artifactId="pax-exam-container-native" version="${pax.exam.version}"> + <exclusion groupId="org.osgi" artifactId="org.osgi.core"/><!-- Avoid dragging in a dependency which requires Java >6 --> + </dependency> <dependency groupId="org.ops4j.pax.exam" artifactId="pax-exam-junit4" version="${pax.exam.version}"/> <dependency groupId="org.ops4j.pax.exam" artifactId="pax-exam-link-assembly" version="${pax.exam.version}"/> - <!-- upgraded to 1.6.0 to get fix for https://ops4j1.jira.com/browse/PAXURL-217 - https://ops4j1.jira.com/browse/PAXURL-138 is still unresolved... --> - <dependency groupId="org.ops4j.pax.url" artifactId="pax-url-aether" version="1.6.0"/> - <dependency groupId="org.ops4j.pax.swissbox" artifactId="pax-swissbox-framework" version="1.5.1"/> - <dependency groupId="ch.qos.logback" artifactId="logback-core" version="0.9.20"/> - <dependency groupId="ch.qos.logback" artifactId="logback-classic" version="0.9.20"/> + <dependency groupId="org.ops4j.pax.url" artifactId="pax-url-aether" version="2.2.0"/> + <dependency groupId="org.ops4j.pax.swissbox" artifactId="pax-swissbox-tracker" version="1.8.0"/> + <dependency groupId="ch.qos.logback" artifactId="logback-core" version="1.1.2"/> + <dependency groupId="ch.qos.logback" artifactId="logback-classic" version="1.1.2"/> <dependency groupId="junit" artifactId="junit" version="${junit.version}"/> - <dependency groupId="org.apache.felix" artifactId="org.apache.felix.framework" version="3.2.2"/> </artifact:dependencies> + <artifact:dependencies pathId="osgi.framework.felix"> + <dependency groupId="org.apache.felix" artifactId="org.apache.felix.framework" version="${osgi.felix.version}"/> + </artifact:dependencies> + + <artifact:dependencies pathId="osgi.framework.equinox"> + <dependency groupId="org.eclipse.osgi" artifactId="org.eclipse.osgi" version="${osgi.equinox.version}"/> + </artifact:dependencies> <artifact:remoteRepository id="sonatype-release" url="https://oss.sonatype.org/content/repositories/releases"/> <artifact:remoteRepository id="extra-repo" url="${extra.repo.url}"/> @@ -984,6 +992,16 @@ TODO: <path refid="forkjoin.classpath"/> </path> + <path id="test.osgi.compiler.build.path.felix"> + <path refid="test.osgi.compiler.build.path"/> + <path refid="osgi.framework.felix"/> + </path> + + <path id="test.osgi.compiler.build.path.equinox"> + <path refid="test.osgi.compiler.build.path"/> + <path refid="osgi.framework.equinox"/> + </path> + <path id="test.positions.sub.build.path" path="${build-quick.dir}/classes/library"/> <!-- TODO: consolidate *.includes --> @@ -1351,7 +1369,7 @@ TODO: srcdir="${test.osgi.src}" jvmargs="${scalacfork.jvmargs}"> <include name="**/*.scala"/> - <compilationpath refid="test.osgi.compiler.build.path"/> + <compilationpath refid="test.osgi.compiler.build.path.felix"/> </scalacfork> <touch file="${build-osgi.dir}/test-compile.complete" verbose="no"/> <stopwatch name="test.osgi.compiler.timer" action="total"/> @@ -1365,8 +1383,20 @@ TODO: <stopwatch name="test.osgi.timer"/> <mkdir dir="${test.osgi.classes}"/> + <echo message="Test pass 1 of 2 using Apache Felix ${osgi.felix.version}"/> + <junit fork="yes" haltonfailure="yes"> + <classpath refid="test.osgi.compiler.build.path.felix"/> + <batchtest fork="yes" todir="${build-osgi.dir}"> + <fileset dir="${test.osgi.classes}"> + <include name="**/*Test.class"/> + </fileset> + </batchtest> + <formatter type="xml" /> + </junit> + + <echo message="Test pass 2 of 2 using Eclipse Equinox ${osgi.equinox.version}"/> <junit fork="yes" haltonfailure="yes"> - <classpath refid="test.osgi.compiler.build.path"/> + <classpath refid="test.osgi.compiler.build.path.equinox"/> <batchtest fork="yes" todir="${build-osgi.dir}"> <fileset dir="${test.osgi.classes}"> <include name="**/*Test.class"/> diff --git a/src/compiler/scala/reflect/macros/compiler/DefaultMacroCompiler.scala b/src/compiler/scala/reflect/macros/compiler/DefaultMacroCompiler.scala index a13a778b2f..b8384851da 100644 --- a/src/compiler/scala/reflect/macros/compiler/DefaultMacroCompiler.scala +++ b/src/compiler/scala/reflect/macros/compiler/DefaultMacroCompiler.scala @@ -12,7 +12,7 @@ abstract class DefaultMacroCompiler extends Resolvers import treeInfo._ import definitions._ val runDefinitions = currentRun.runDefinitions - import runDefinitions.{Predef_???, _} + import runDefinitions.Predef_??? val typer: global.analyzer.Typer val context = typer.context diff --git a/src/compiler/scala/reflect/macros/compiler/Errors.scala b/src/compiler/scala/reflect/macros/compiler/Errors.scala index cc4508e696..98fd091e9c 100644 --- a/src/compiler/scala/reflect/macros/compiler/Errors.scala +++ b/src/compiler/scala/reflect/macros/compiler/Errors.scala @@ -11,7 +11,6 @@ trait Errors extends Traces { import analyzer._ import definitions._ import treeInfo._ - import typer.TyperErrorGen._ import typer.infer.InferErrorGen._ import runDefinitions._ def globalSettings = global.settings diff --git a/src/compiler/scala/reflect/macros/compiler/Resolvers.scala b/src/compiler/scala/reflect/macros/compiler/Resolvers.scala index 4484c234aa..d3f49390ea 100644 --- a/src/compiler/scala/reflect/macros/compiler/Resolvers.scala +++ b/src/compiler/scala/reflect/macros/compiler/Resolvers.scala @@ -1,18 +1,12 @@ package scala.reflect.macros package compiler -import scala.reflect.internal.Flags._ -import scala.reflect.macros.TypecheckException - trait Resolvers { self: DefaultMacroCompiler => import global._ import analyzer._ - import definitions._ import treeInfo._ - import gen._ - import runDefinitions._ trait Resolver { self: MacroImplRefCompiler => diff --git a/src/compiler/scala/reflect/macros/compiler/Validators.scala b/src/compiler/scala/reflect/macros/compiler/Validators.scala index a146818ae3..fc932f2b18 100644 --- a/src/compiler/scala/reflect/macros/compiler/Validators.scala +++ b/src/compiler/scala/reflect/macros/compiler/Validators.scala @@ -9,7 +9,7 @@ trait Validators { import global._ import analyzer._ import definitions._ - import runDefinitions.{Predef_???, _} + import runDefinitions.Predef_??? trait Validator { self: MacroImplRefCompiler => diff --git a/src/compiler/scala/reflect/macros/util/Helpers.scala b/src/compiler/scala/reflect/macros/util/Helpers.scala index bddc42d1f9..961c41dab5 100644 --- a/src/compiler/scala/reflect/macros/util/Helpers.scala +++ b/src/compiler/scala/reflect/macros/util/Helpers.scala @@ -54,14 +54,10 @@ trait Helpers { * * @see Metalevels.scala for more information and examples about metalevels */ - def increaseMetalevel(pre: Type, tp: Type): Type = { - val runDefinitions = currentRun.runDefinitions - import runDefinitions._ - + def increaseMetalevel(pre: Type, tp: Type): Type = transparentShallowTransform(RepeatedParamClass, tp) { case tp => typeRef(pre, MacroContextExprClass, List(tp)) } - } /** Transforms c.Expr[T] types into c.Tree and leaves the rest unchanged. */ diff --git a/src/compiler/scala/reflect/quasiquotes/Parsers.scala b/src/compiler/scala/reflect/quasiquotes/Parsers.scala index 007bac27da..97ec7dbfc3 100644 --- a/src/compiler/scala/reflect/quasiquotes/Parsers.scala +++ b/src/compiler/scala/reflect/quasiquotes/Parsers.scala @@ -90,7 +90,7 @@ trait Parsers { self: Quasiquotes => case _ => super.makePatDef(mods, pat, rhs) } } - import treeBuilder.{global => _, unit => _, _} + import treeBuilder.{global => _, unit => _} // q"def foo($x)" override def param(owner: Name, implicitmod: Int, caseParam: Boolean): ValDef = diff --git a/src/compiler/scala/reflect/quasiquotes/Reifiers.scala b/src/compiler/scala/reflect/quasiquotes/Reifiers.scala index 07becdc3c6..cc98717c4e 100644 --- a/src/compiler/scala/reflect/quasiquotes/Reifiers.scala +++ b/src/compiler/scala/reflect/quasiquotes/Reifiers.scala @@ -8,7 +8,6 @@ import scala.reflect.internal.Flags._ trait Reifiers { self: Quasiquotes => import global._ import global.build._ - import global.treeInfo._ import global.definitions._ import Rank._ import universeTypes._ diff --git a/src/compiler/scala/reflect/reify/Reifier.scala b/src/compiler/scala/reflect/reify/Reifier.scala index b1cc797389..a3e0f02dcc 100644 --- a/src/compiler/scala/reflect/reify/Reifier.scala +++ b/src/compiler/scala/reflect/reify/Reifier.scala @@ -21,7 +21,6 @@ abstract class Reifier extends States import global._ import definitions._ private val runDefinitions = currentRun.runDefinitions - import runDefinitions._ val typer: global.analyzer.Typer val universe: Tree diff --git a/src/compiler/scala/reflect/reify/codegen/GenUtils.scala b/src/compiler/scala/reflect/reify/codegen/GenUtils.scala index 4512b2cb6f..de9fec0df5 100644 --- a/src/compiler/scala/reflect/reify/codegen/GenUtils.scala +++ b/src/compiler/scala/reflect/reify/codegen/GenUtils.scala @@ -5,10 +5,6 @@ trait GenUtils { self: Reifier => import global._ - import treeInfo._ - import definitions._ - private val runDefinitions = currentRun.runDefinitions - import runDefinitions._ def reifyList(xs: List[Any]): Tree = mkList(xs map reify) diff --git a/src/compiler/scala/tools/nsc/CompilationUnits.scala b/src/compiler/scala/tools/nsc/CompilationUnits.scala index 0a356ed7b6..1a6843a249 100644 --- a/src/compiler/scala/tools/nsc/CompilationUnits.scala +++ b/src/compiler/scala/tools/nsc/CompilationUnits.scala @@ -8,7 +8,6 @@ package scala.tools.nsc import scala.reflect.internal.util.{ SourceFile, NoSourceFile, FreshNameCreator } import scala.collection.mutable import scala.collection.mutable.{ LinkedHashSet, ListBuffer } -import scala.tools.nsc.reporters.Reporter trait CompilationUnits { global: Global => diff --git a/src/compiler/scala/tools/nsc/Global.scala b/src/compiler/scala/tools/nsc/Global.scala index 452081cff1..9cc9712b44 100644 --- a/src/compiler/scala/tools/nsc/Global.scala +++ b/src/compiler/scala/tools/nsc/Global.scala @@ -9,17 +9,16 @@ package nsc import java.io.{ File, FileOutputStream, PrintWriter, IOException, FileNotFoundException } import java.nio.charset.{ Charset, CharsetDecoder, IllegalCharsetNameException, UnsupportedCharsetException } -import java.util.UUID._ import scala.compat.Platform.currentTime import scala.collection.{ mutable, immutable } import io.{ SourceReader, AbstractFile, Path } import reporters.{ Reporter, ConsoleReporter } -import util.{ ClassPath, MergedClassPath, StatisticsInfo, returning, stackTraceString } +import util.{ ClassPath, StatisticsInfo, returning, stackTraceString } import scala.reflect.ClassTag import scala.reflect.internal.util.{ OffsetPosition, SourceFile, NoSourceFile, BatchSourceFile, ScriptSourceFile } import scala.reflect.internal.pickling.{ PickleBuffer, PickleFormat } import scala.reflect.io.VirtualFile -import symtab.{ Flags, SymbolTable, SymbolLoaders, SymbolTrackers } +import symtab.{ Flags, SymbolTable, SymbolTrackers } import symtab.classfile.Pickler import plugins.Plugins import ast._ @@ -28,7 +27,7 @@ import typechecker._ import transform.patmat.PatternMatching import transform._ import backend.icode.{ ICodes, GenICode, ICodeCheckers } -import backend.{ ScalaPrimitives, Platform, JavaPlatform } +import backend.{ ScalaPrimitives, JavaPlatform } import backend.jvm.GenBCode import backend.jvm.GenASM import backend.opt.{ Inliners, InlineExceptionHandlers, ConstantOptimization, ClosureElimination, DeadCodeElimination } @@ -1232,13 +1231,12 @@ class Global(var currentSettings: Settings, var reporter: Reporter) /** does this run compile given class, module, or case factory? */ // NOTE: Early initialized members temporarily typechecked before the enclosing class, see typedPrimaryConstrBody! - // Here we work around that wrinkle by claiming that a top-level, early-initialized member is compiled in + // Here we work around that wrinkle by claiming that a early-initialized member is compiled in // *every* run. This approximation works because this method is exclusively called with `this` == `currentRun`. def compiles(sym: Symbol): Boolean = if (sym == NoSymbol) false else if (symSource.isDefinedAt(sym)) true - else if (sym.isTopLevel && sym.isEarlyInitialized) true - else if (!sym.isTopLevel) compiles(sym.enclosingTopLevelClass) + else if (!sym.isTopLevel) compiles(sym.enclosingTopLevelClassOrDummy) else if (sym.isModuleClass) compiles(sym.sourceModule) else false diff --git a/src/compiler/scala/tools/nsc/Parsing.scala b/src/compiler/scala/tools/nsc/Parsing.scala index 4dd3c3f378..9e5999ce4f 100644 --- a/src/compiler/scala/tools/nsc/Parsing.scala +++ b/src/compiler/scala/tools/nsc/Parsing.scala @@ -7,7 +7,6 @@ package scala package tools.nsc import scala.reflect.internal.Positions -import scala.tools.nsc.reporters.Reporter /** Similar to Reporting: gather global functionality specific to parsing. */ diff --git a/src/compiler/scala/tools/nsc/Reporting.scala b/src/compiler/scala/tools/nsc/Reporting.scala index c9782de7c8..4d7e9e753f 100644 --- a/src/compiler/scala/tools/nsc/Reporting.scala +++ b/src/compiler/scala/tools/nsc/Reporting.scala @@ -7,7 +7,6 @@ package scala package tools package nsc -import reporters.{ Reporter, ConsoleReporter } import scala.collection.{ mutable, immutable } import scala.reflect.internal.util.StringOps.countElementsAsString diff --git a/src/compiler/scala/tools/nsc/backend/icode/BasicBlocks.scala b/src/compiler/scala/tools/nsc/backend/icode/BasicBlocks.scala index f9551697d2..ad1975ef23 100644 --- a/src/compiler/scala/tools/nsc/backend/icode/BasicBlocks.scala +++ b/src/compiler/scala/tools/nsc/backend/icode/BasicBlocks.scala @@ -300,14 +300,16 @@ trait BasicBlocks { if (!closed) instructionList = instructionList map (x => map.getOrElse(x, x)) else - instrs.zipWithIndex collect { - case (oldInstr, i) if map contains oldInstr => - // SI-6288 clone important here because `replaceInstruction` assigns - // a position to `newInstr`. Without this, a single instruction can - // be added twice, and the position last position assigned clobbers - // all previous positions in other usages. - val newInstr = map(oldInstr).clone() - code.touched |= replaceInstruction(i, newInstr) + instrs.iterator.zipWithIndex foreach { + case (oldInstr, i) => + if (map contains oldInstr) { + // SI-6288 clone important here because `replaceInstruction` assigns + // a position to `newInstr`. Without this, a single instruction can + // be added twice, and the position last position assigned clobbers + // all previous positions in other usages. + val newInstr = map(oldInstr).clone() + code.touched |= replaceInstruction(i, newInstr) + } } ////////////////////// Emit ////////////////////// diff --git a/src/compiler/scala/tools/nsc/backend/jvm/BCodeAsmCommon.scala b/src/compiler/scala/tools/nsc/backend/jvm/BCodeAsmCommon.scala index 54d4a30553..328ec8a033 100644 --- a/src/compiler/scala/tools/nsc/backend/jvm/BCodeAsmCommon.scala +++ b/src/compiler/scala/tools/nsc/backend/jvm/BCodeAsmCommon.scala @@ -6,7 +6,6 @@ package scala.tools.nsc.backend.jvm import scala.tools.nsc.Global -import PartialFunction._ /** * This trait contains code shared between GenBCode and GenASM that depends on types defined in diff --git a/src/compiler/scala/tools/nsc/backend/opt/ConstantOptimization.scala b/src/compiler/scala/tools/nsc/backend/opt/ConstantOptimization.scala index 1fadcb8920..c6e699373b 100644 --- a/src/compiler/scala/tools/nsc/backend/opt/ConstantOptimization.scala +++ b/src/compiler/scala/tools/nsc/backend/opt/ConstantOptimization.scala @@ -7,7 +7,6 @@ package scala package tools.nsc package backend.opt -import scala.tools.nsc.backend.icode.analysis.LubException import scala.annotation.tailrec /** diff --git a/src/compiler/scala/tools/nsc/settings/MutableSettings.scala b/src/compiler/scala/tools/nsc/settings/MutableSettings.scala index 23611bb629..b4987e1240 100644 --- a/src/compiler/scala/tools/nsc/settings/MutableSettings.scala +++ b/src/compiler/scala/tools/nsc/settings/MutableSettings.scala @@ -229,7 +229,8 @@ class MutableSettings(val errorFn: String => Unit) def OutputSetting(outputDirs: OutputDirs, default: String) = add(new OutputSetting(outputDirs, default)) def PhasesSetting(name: String, descr: String, default: String = "") = add(new PhasesSetting(name, descr, default)) def StringSetting(name: String, arg: String, descr: String, default: String) = add(new StringSetting(name, arg, descr, default)) - def ScalaVersionSetting(name: String, arg: String, descr: String, default: ScalaVersion) = add(new ScalaVersionSetting(name, arg, descr, default)) + def ScalaVersionSetting(name: String, arg: String, descr: String, initial: ScalaVersion, default: Option[ScalaVersion] = None) = + add(new ScalaVersionSetting(name, arg, descr, initial, default)) def PathSetting(name: String, descr: String, default: String): PathSetting = { val prepend = StringSetting(name + "/p", "", "", "").internalOnly() val append = StringSetting(name + "/a", "", "", "").internalOnly() @@ -506,28 +507,35 @@ class MutableSettings(val errorFn: String => Unit) withHelpSyntax(name + " <" + arg + ">") } - /** A setting represented by a Scala version, (`default` unless set) */ + /** A setting represented by a Scala version. + * The `initial` value is used if the setting is not specified. + * The `default` value is used if the option is specified without argument (e.g., `-Xmigration`). + */ class ScalaVersionSetting private[nsc]( name: String, val arg: String, descr: String, - default: ScalaVersion) + initial: ScalaVersion, + default: Option[ScalaVersion]) extends Setting(name, descr) { type T = ScalaVersion - protected var v: T = NoScalaVersion + protected var v: T = initial + // This method is invoked if there are no colonated args. In this case the default value is + // used. No arguments are consumed. override def tryToSet(args: List[String]) = { - value = default + default match { + case Some(d) => value = d + case None => errorFn(s"$name requires an argument, the syntax is $helpSyntax") + } Some(args) } override def tryToSetColon(args: List[String]) = args match { - case Nil => value = default; Some(Nil) - case x :: xs => value = ScalaVersion(x, errorFn) ; Some(xs) + case x :: xs => value = ScalaVersion(x, errorFn); Some(xs) + case nil => Some(nil) } - override def tryToSetFromPropertyValue(s: String) = tryToSet(List(s)) - def unparse: List[String] = if (value == NoScalaVersion) Nil else List(s"${name}:${value.unparse}") withHelpSyntax(s"${name}:<${arg}>") diff --git a/src/compiler/scala/tools/nsc/settings/ScalaSettings.scala b/src/compiler/scala/tools/nsc/settings/ScalaSettings.scala index 850534f2cc..c59d56d8f8 100644 --- a/src/compiler/scala/tools/nsc/settings/ScalaSettings.scala +++ b/src/compiler/scala/tools/nsc/settings/ScalaSettings.scala @@ -92,7 +92,8 @@ trait ScalaSettings extends AbsScalaSettings * The previous "-source" option is intended to be used mainly * though this helper. */ - lazy val isScala211: Boolean = (source.value >= ScalaVersion("2.11.0")) + def isScala211: Boolean = source.value >= ScalaVersion("2.11.0") + def isScala212: Boolean = source.value >= ScalaVersion("2.12.0") /** * -X "Advanced" settings @@ -111,7 +112,7 @@ trait ScalaSettings extends AbsScalaSettings val logFreeTerms = BooleanSetting ("-Xlog-free-terms", "Print a message when reification creates a free term.") val logFreeTypes = BooleanSetting ("-Xlog-free-types", "Print a message when reification resorts to generating a free type.") val maxClassfileName = IntSetting ("-Xmax-classfile-name", "Maximum filename length for generated classes", 255, Some((72, 255)), _ => None) - val Xmigration = ScalaVersionSetting ("-Xmigration", "version", "Warn about constructs whose behavior may have changed since version.", AnyScalaVersion) + val Xmigration = ScalaVersionSetting ("-Xmigration", "version", "Warn about constructs whose behavior may have changed since version.", initial = NoScalaVersion, default = Some(AnyScalaVersion)) val nouescape = BooleanSetting ("-Xno-uescape", "Disable handling of \\u unicode escapes.") val Xnojline = BooleanSetting ("-Xnojline", "Do not use JLine for editing.") val Xverify = BooleanSetting ("-Xverify", "Verify generic signatures in generated bytecode (asm backend only.)") @@ -133,7 +134,7 @@ trait ScalaSettings extends AbsScalaSettings val showPhases = BooleanSetting ("-Xshow-phases", "Print a synopsis of compiler phases.") val sourceReader = StringSetting ("-Xsource-reader", "classname", "Specify a custom method for reading source files.", "") val strictInference = BooleanSetting ("-Xstrict-inference", "Don't infer known-unsound types") - val source = ScalaVersionSetting ("-Xsource", "version", "Treat compiler input as Scala source for the specified version, see SI-8126.", ScalaVersion("2.11")) withPostSetHook ( _ => isScala211) + val source = ScalaVersionSetting ("-Xsource", "version", "Treat compiler input as Scala source for the specified version, see SI-8126.", initial = ScalaVersion("2.11")) val XnoPatmatAnalysis = BooleanSetting ("-Xno-patmat-analysis", "Don't perform exhaustivity/unreachability analysis. Also, ignore @switch annotation.") val XfullLubs = BooleanSetting ("-Xfull-lubs", "Retains pre 2.10 behavior of less aggressive truncation of least upper bounds.") diff --git a/src/compiler/scala/tools/nsc/settings/ScalaVersion.scala b/src/compiler/scala/tools/nsc/settings/ScalaVersion.scala index 4f45043c5e..43bdad5882 100644 --- a/src/compiler/scala/tools/nsc/settings/ScalaVersion.scala +++ b/src/compiler/scala/tools/nsc/settings/ScalaVersion.scala @@ -34,7 +34,7 @@ case object NoScalaVersion extends ScalaVersion { * to segregate builds */ case class SpecificScalaVersion(major: Int, minor: Int, rev: Int, build: ScalaBuild) extends ScalaVersion { - def unparse = s"${major}.${minor}.${rev}.${build.unparse}" + def unparse = s"${major}.${minor}.${rev}${build.unparse}" def compare(that: ScalaVersion): Int = that match { case SpecificScalaVersion(thatMajor, thatMinor, thatRev, thatBuild) => diff --git a/src/compiler/scala/tools/nsc/transform/Delambdafy.scala b/src/compiler/scala/tools/nsc/transform/Delambdafy.scala index 835d338ab3..f7b1021ea2 100644 --- a/src/compiler/scala/tools/nsc/transform/Delambdafy.scala +++ b/src/compiler/scala/tools/nsc/transform/Delambdafy.scala @@ -30,7 +30,6 @@ import scala.collection.mutable.LinkedHashMap abstract class Delambdafy extends Transform with TypingTransformers with ast.TreeDSL with TypeAdaptingTransformer { import global._ import definitions._ - import CODE._ val analyzer: global.analyzer.type = global.analyzer diff --git a/src/compiler/scala/tools/nsc/transform/Erasure.scala b/src/compiler/scala/tools/nsc/transform/Erasure.scala index 3d8b2f02f3..db639d0868 100644 --- a/src/compiler/scala/tools/nsc/transform/Erasure.scala +++ b/src/compiler/scala/tools/nsc/transform/Erasure.scala @@ -98,7 +98,7 @@ abstract class Erasure extends AddInterfaces val len = sig.length val copy: Array[Char] = sig.toCharArray var changed = false - while (i < sig.length) { + while (i < len) { val ch = copy(i) if (ch == '.' && last != '>') { copy(i) = '$' @@ -410,7 +410,6 @@ abstract class Erasure extends AddInterfaces def fulldef(sym: Symbol) = if (sym == NoSymbol) sym.toString else s"$sym: ${sym.tpe} in ${sym.owner}" - var noclash = true val clashErrors = mutable.Buffer[(Position, String)]() def clashError(what: String) = { val pos = if (member.owner == root) member.pos else root.pos diff --git a/src/compiler/scala/tools/nsc/transform/OverridingPairs.scala b/src/compiler/scala/tools/nsc/transform/OverridingPairs.scala index bbd11efa7e..c1c025ad48 100644 --- a/src/compiler/scala/tools/nsc/transform/OverridingPairs.scala +++ b/src/compiler/scala/tools/nsc/transform/OverridingPairs.scala @@ -6,7 +6,6 @@ package scala.tools.nsc package transform -import symtab.Flags._ import scala.reflect.internal.SymbolPairs /** A class that yields a kind of iterator (`Cursor`), diff --git a/src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala b/src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala index 908aa69310..9c81e31ad9 100644 --- a/src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala +++ b/src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala @@ -861,11 +861,6 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers { debuglog("%s expands to %s in %s".format(sym, specMember.name.decode, pp(env))) info(specMember) = NormalizedMember(sym) newOverload(sym, specMember, env) - // if this is a class, we insert the normalized member in scope, - // if this is a method, there's no attached scope for it (EmptyScope) - val decls = owner.info.decls - if (decls != EmptyScope) - decls.enter(specMember) specMember } } @@ -1504,20 +1499,13 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers { val residualTargs = symbol.info.typeParams zip baseTargs collect { case (tvar, targ) if !env.contains(tvar) || !isPrimitiveValueClass(env(tvar).typeSymbol) => targ } - // See SI-5583. Don't know why it happens now if it didn't before. - if (specMember.info.typeParams.isEmpty && residualTargs.nonEmpty) { - devWarning("Type args to be applied, but symbol says no parameters: " + ((specMember.defString, residualTargs))) - baseTree - } - else { - ifDebug(assert(residualTargs.length == specMember.info.typeParams.length, - "residual: %s, tparams: %s, env: %s".format(residualTargs, specMember.info.typeParams, env)) - ) + ifDebug(assert(residualTargs.length == specMember.info.typeParams.length, + "residual: %s, tparams: %s, env: %s".format(residualTargs, specMember.info.typeParams, env)) + ) - val tree1 = gen.mkTypeApply(specTree, residualTargs) - debuglog("rewrote " + tree + " to " + tree1) - localTyper.typedOperator(atPos(tree.pos)(tree1)) // being polymorphic, it must be a method - } + val tree1 = gen.mkTypeApply(specTree, residualTargs) + debuglog("rewrote " + tree + " to " + tree1) + localTyper.typedOperator(atPos(tree.pos)(tree1)) // being polymorphic, it must be a method } curTree = tree diff --git a/src/compiler/scala/tools/nsc/transform/Statics.scala b/src/compiler/scala/tools/nsc/transform/Statics.scala index e2508b8d08..4673be6de7 100644 --- a/src/compiler/scala/tools/nsc/transform/Statics.scala +++ b/src/compiler/scala/tools/nsc/transform/Statics.scala @@ -1,9 +1,6 @@ package scala.tools.nsc package transform -import symtab._ -import Flags._ - import collection.mutable.Buffer abstract class Statics extends Transform with ast.TreeDSL { diff --git a/src/compiler/scala/tools/nsc/transform/TailCalls.scala b/src/compiler/scala/tools/nsc/transform/TailCalls.scala index ef534f70fd..16ea3ea90f 100644 --- a/src/compiler/scala/tools/nsc/transform/TailCalls.scala +++ b/src/compiler/scala/tools/nsc/transform/TailCalls.scala @@ -129,6 +129,13 @@ abstract class TailCalls extends Transform { } override def toString = s"${method.name} tparams=$tparams tailPos=$tailPos label=$label label info=${label.info}" + final def noTailContext() = clonedTailContext(false) + final def yesTailContext() = clonedTailContext(true) + protected def clonedTailContext(tailPos: Boolean): TailContext = this match { + case _ if this.tailPos == tailPos => this + case clone: ClonedTailContext => clone.that.clonedTailContext(tailPos) + case _ => new ClonedTailContext(this, tailPos) + } } object EmptyTailContext extends TailContext { @@ -174,7 +181,7 @@ abstract class TailCalls extends Transform { } def containsRecursiveCall(t: Tree) = t exists isRecursiveCall } - class ClonedTailContext(that: TailContext, override val tailPos: Boolean) extends TailContext { + class ClonedTailContext(val that: TailContext, override val tailPos: Boolean) extends TailContext { def method = that.method def tparams = that.tparams def methodPos = that.methodPos @@ -183,9 +190,6 @@ abstract class TailCalls extends Transform { } private var ctx: TailContext = EmptyTailContext - private def noTailContext() = new ClonedTailContext(ctx, tailPos = false) - private def yesTailContext() = new ClonedTailContext(ctx, tailPos = true) - override def transformUnit(unit: CompilationUnit): Unit = { try { @@ -206,16 +210,16 @@ abstract class TailCalls extends Transform { finally this.ctx = saved } - def yesTailTransform(tree: Tree): Tree = transform(tree, yesTailContext()) - def noTailTransform(tree: Tree): Tree = transform(tree, noTailContext()) + def yesTailTransform(tree: Tree): Tree = transform(tree, ctx.yesTailContext()) + def noTailTransform(tree: Tree): Tree = transform(tree, ctx.noTailContext()) def noTailTransforms(trees: List[Tree]) = { - val nctx = noTailContext() - trees map (t => transform(t, nctx)) + val nctx = ctx.noTailContext() + trees mapConserve (t => transform(t, nctx)) } override def transform(tree: Tree): Tree = { /* A possibly polymorphic apply to be considered for tail call transformation. */ - def rewriteApply(target: Tree, fun: Tree, targs: List[Tree], args: List[Tree]) = { + def rewriteApply(target: Tree, fun: Tree, targs: List[Tree], args: List[Tree], mustTransformArgs: Boolean = true) = { val receiver: Tree = fun match { case Select(qual, _) => qual case _ => EmptyTree @@ -223,7 +227,7 @@ abstract class TailCalls extends Transform { def receiverIsSame = ctx.enclosingType.widen =:= receiver.tpe.widen def receiverIsSuper = ctx.enclosingType.widen <:< receiver.tpe.widen def isRecursiveCall = (ctx.method eq fun.symbol) && ctx.tailPos - def transformArgs = noTailTransforms(args) + def transformArgs = if (mustTransformArgs) noTailTransforms(args) else args def matchesTypeArgs = ctx.tparams sameElements (targs map (_.tpe.typeSymbol)) /* Records failure reason in Context for reporting. @@ -265,6 +269,10 @@ abstract class TailCalls extends Transform { !(sym.hasAccessorFlag || sym.isConstructor) } + // intentionally shadowing imports from definitions for performance + val runDefinitions = currentRun.runDefinitions + import runDefinitions.{Boolean_or, Boolean_and} + tree match { case ValDef(_, _, _, _) => if (tree.symbol.isLazy && tree.symbol.hasAnnotation(TailrecClass)) @@ -312,8 +320,13 @@ abstract class TailCalls extends Transform { // the assumption is once we encounter a case, the remainder of the block will consist of cases // the prologue may be empty, usually it is the valdef that stores the scrut val (prologue, cases) = stats span (s => !s.isInstanceOf[LabelDef]) + val transformedPrologue = noTailTransforms(prologue) + val transformedCases = transformTrees(cases) + val transformedStats = + if ((prologue eq transformedPrologue) && (cases eq transformedCases)) stats // allow reuse of `tree` if the subtransform was an identity + else transformedPrologue ++ transformedCases treeCopy.Block(tree, - noTailTransforms(prologue) ++ transformTrees(cases), + transformedStats, transform(expr) ) @@ -380,7 +393,7 @@ abstract class TailCalls extends Transform { if (res ne arg) treeCopy.Apply(tree, fun, res :: Nil) else - rewriteApply(fun, fun, Nil, args) + rewriteApply(fun, fun, Nil, args, mustTransformArgs = false) case Apply(fun, args) => rewriteApply(fun, fun, Nil, args) @@ -421,6 +434,10 @@ abstract class TailCalls extends Transform { def traverseNoTail(tree: Tree) = traverse(tree, maybeTailNew = false) def traverseTreesNoTail(trees: List[Tree]) = trees foreach traverseNoTail + // intentionally shadowing imports from definitions for performance + private val runDefinitions = currentRun.runDefinitions + import runDefinitions.{Boolean_or, Boolean_and} + override def traverse(tree: Tree) = tree match { // we're looking for label(x){x} in tail position, since that means `a` is in tail position in a call `label(a)` case LabelDef(_, List(arg), body@Ident(_)) if arg.symbol == body.symbol => diff --git a/src/compiler/scala/tools/nsc/transform/TypeAdaptingTransformer.scala b/src/compiler/scala/tools/nsc/transform/TypeAdaptingTransformer.scala index f83b6f857e..3b23306386 100644 --- a/src/compiler/scala/tools/nsc/transform/TypeAdaptingTransformer.scala +++ b/src/compiler/scala/tools/nsc/transform/TypeAdaptingTransformer.scala @@ -1,7 +1,6 @@ package scala.tools.nsc package transform -import scala.reflect.internal._ import scala.tools.nsc.ast.TreeDSL import scala.tools.nsc.Global diff --git a/src/compiler/scala/tools/nsc/transform/patmat/ScalacPatternExpanders.scala b/src/compiler/scala/tools/nsc/transform/patmat/ScalacPatternExpanders.scala index 79f5e3bee8..8924394b72 100644 --- a/src/compiler/scala/tools/nsc/transform/patmat/ScalacPatternExpanders.scala +++ b/src/compiler/scala/tools/nsc/transform/patmat/ScalacPatternExpanders.scala @@ -73,9 +73,7 @@ trait ScalacPatternExpanders { * Unfortunately the MethodType does not carry the information of whether * it was unapplySeq, so we have to funnel that information in separately. */ - def unapplyMethodTypes(method: Type, isSeq: Boolean): Extractor = { - val whole = firstParamType(method) - val result = method.finalResultType + def unapplyMethodTypes(whole: Type, result: Type, isSeq: Boolean): Extractor = { val expanded = ( if (result =:= BooleanTpe) Nil else typeOfMemberNamedGet(result) match { @@ -124,11 +122,11 @@ trait ScalacPatternExpanders { case _ => sel } val patterns = newPatterns(args) - val isSeq = sel.symbol.name == nme.unapplySeq val isUnapply = sel.symbol.name == nme.unapply + val extractor = sel.symbol.name match { - case nme.unapply => unapplyMethodTypes(fn.tpe, isSeq = false) - case nme.unapplySeq => unapplyMethodTypes(fn.tpe, isSeq = true) + case nme.unapply => unapplyMethodTypes(firstParamType(fn.tpe), sel.tpe, isSeq = false) + case nme.unapplySeq => unapplyMethodTypes(firstParamType(fn.tpe), sel.tpe, isSeq = true) case _ => applyMethodTypes(fn.tpe) } diff --git a/src/compiler/scala/tools/nsc/typechecker/Contexts.scala b/src/compiler/scala/tools/nsc/typechecker/Contexts.scala index eb29ccf4e1..e278130437 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Contexts.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Contexts.scala @@ -330,7 +330,7 @@ trait Contexts { self: Analyzer => // if set, errors will not be reporter/thrown def bufferErrors = reporter.isBuffering - def reportErrors = !bufferErrors + def reportErrors = !(bufferErrors || reporter.isThrowing) // whether to *report* (which is separate from buffering/throwing) ambiguity errors def ambiguousErrors = this(AmbiguousErrors) @@ -1247,6 +1247,7 @@ trait Contexts { self: Analyzer => def makeImmediate: ContextReporter = this def makeBuffering: ContextReporter = this def isBuffering: Boolean = false + def isThrowing: Boolean = false /** Emit an ambiguous error according to context.ambiguousErrors * @@ -1384,6 +1385,7 @@ trait Contexts { self: Analyzer => * TODO: get rid of it, use ImmediateReporter and a check for reporter.hasErrors where necessary */ private[typechecker] class ThrowingReporter extends ContextReporter { + override def isThrowing = true protected def handleError(pos: Position, msg: String): Unit = throw new TypeError(pos, msg) } diff --git a/src/compiler/scala/tools/nsc/typechecker/MethodSynthesis.scala b/src/compiler/scala/tools/nsc/typechecker/MethodSynthesis.scala index ba183fe3e6..0aa62d771e 100644 --- a/src/compiler/scala/tools/nsc/typechecker/MethodSynthesis.scala +++ b/src/compiler/scala/tools/nsc/typechecker/MethodSynthesis.scala @@ -212,7 +212,9 @@ trait MethodSynthesis { List(cd, mdef) case _ => // Shouldn't happen, but let's give ourselves a reasonable error when it does - abort("No synthetics for " + meth + ": synthetics contains " + context.unit.synthetics.keys.mkString(", ")) + context.error(cd.pos, s"Internal error: Symbol for synthetic factory method not found among ${context.unit.synthetics.keys.mkString(", ")}") + // Soldier on for the sake of the presentation compiler + List(cd) } case _ => stat :: Nil @@ -355,8 +357,9 @@ trait MethodSynthesis { def derivedSym: Symbol = { // Only methods will do! Don't want to pick up any stray // companion objects of the same name. - val result = enclClass.info decl name suchThat (x => x.isMethod && x.isSynthetic) - assert(result != NoSymbol, "not found: "+name+" in "+enclClass+" "+enclClass.info.decls) + val result = enclClass.info decl name filter (x => x.isMethod && x.isSynthetic) + if (result == NoSymbol || result.isOverloaded) + context.error(tree.pos, s"Internal error: Unable to find the synthetic factory method corresponding to implicit class $name in $enclClass / ${enclClass.info.decls}") result } def derivedTree: DefDef = diff --git a/src/compiler/scala/tools/nsc/typechecker/Namers.scala b/src/compiler/scala/tools/nsc/typechecker/Namers.scala index e876d4a6af..a1de5e303b 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Namers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Namers.scala @@ -296,7 +296,7 @@ trait Namers extends MethodSynthesis { } tree.symbol match { case NoSymbol => try dispatch() catch typeErrorHandler(tree, this.context) - case sym => enterExistingSym(sym) + case sym => enterExistingSym(sym, tree) } } @@ -413,6 +413,7 @@ trait Namers extends MethodSynthesis { if (isRedefinition) { updatePosFlags(existing, tree.pos, tree.mods.flags) setPrivateWithin(tree, existing) + clearRenamedCaseAccessors(existing) existing } else assignAndEnterSymbol(tree) setFlag inConstructorFlag @@ -736,7 +737,9 @@ trait Namers extends MethodSynthesis { } // Hooks which are overridden in the presentation compiler - def enterExistingSym(sym: Symbol): Context = this.context + def enterExistingSym(sym: Symbol, tree: Tree): Context = { + this.context + } def enterIfNotThere(sym: Symbol) { } def enterSyntheticSym(tree: Tree): Symbol = { diff --git a/src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala b/src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala index bedca88974..1daff02c23 100644 --- a/src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala +++ b/src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala @@ -54,6 +54,9 @@ trait SyntheticMethods extends ast.TreeDSL { /** Does not force the info of `caseclazz` */ final def caseAccessorName(caseclazz: Symbol, paramName: TermName) = (renamedCaseAccessors get caseclazz).fold(paramName)(_(paramName)) + final def clearRenamedCaseAccessors(caseclazz: Symbol): Unit = { + renamedCaseAccessors -= caseclazz + } /** Add the synthetic methods to case classes. */ diff --git a/src/compiler/scala/tools/nsc/typechecker/Tags.scala b/src/compiler/scala/tools/nsc/typechecker/Tags.scala index 90ec3a89b8..57dc74d2a0 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Tags.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Tags.scala @@ -11,7 +11,6 @@ trait Tags { self: Typer => private val runDefinitions = currentRun.runDefinitions - import runDefinitions._ private def resolveTag(pos: Position, taggedTp: Type, allowMaterialization: Boolean) = enteringTyper { def wrapper (tree: => Tree): Tree = if (allowMaterialization) (context.withMacrosEnabled[Tree](tree)) else (context.withMacrosDisabled[Tree](tree)) @@ -66,7 +65,7 @@ trait Tags { // if someone requests a type tag, but scala-reflect.jar isn't on the library classpath, then bail if (pre == NoType && ApiUniverseClass == NoSymbol) EmptyTree else { - val tagSym = if (concrete) TypeTagClass else WeakTypeTagClass + val tagSym = if (concrete) runDefinitions.TypeTagClass else runDefinitions.WeakTypeTagClass val tagTp = if (pre == NoType) TypeRef(ApiUniverseClass.toTypeConstructor, tagSym, List(tp)) else singleType(pre, pre member tagSym.name) val taggedTp = appliedType(tagTp, List(tp)) resolveTag(pos, taggedTp, allowMaterialization) diff --git a/src/compiler/scala/tools/nsc/typechecker/TypeDiagnostics.scala b/src/compiler/scala/tools/nsc/typechecker/TypeDiagnostics.scala index 1dac27639c..0f90c6a478 100644 --- a/src/compiler/scala/tools/nsc/typechecker/TypeDiagnostics.scala +++ b/src/compiler/scala/tools/nsc/typechecker/TypeDiagnostics.scala @@ -607,7 +607,7 @@ trait TypeDiagnostics { if (!c.owner.exists || c.owner.isClass || c.owner.isMethod || (c.owner.isType && !c.owner.isParameter)) c else enclClassOrMethodOrTypeMember(c.outer) - val tt = tparams.filter(_.name != typeNames.WILDCARD).foreach { tp => + tparams.filter(_.name != typeNames.WILDCARD).foreach { tp => // we don't care about type params shadowing other type params in the same declaration enclClassOrMethodOrTypeMember(context).outer.lookupSymbol(tp.name, s => s != tp.symbol && s.hasRawInfo && reallyExists(s)) match { case LookupSucceeded(_, sym2) => context.warning(tp.pos, diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index aae2d24b32..70acb03584 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -1516,7 +1516,9 @@ 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 cscope = context.outer.makeNewScope(ctor, context.outer.owner) + val dummy = context.outer.owner.newLocalDummy(templ.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. val typer1 = newTyper(cscope) // XXX: see about using the class's symbol.... diff --git a/src/compiler/scala/tools/nsc/typechecker/Unapplies.scala b/src/compiler/scala/tools/nsc/typechecker/Unapplies.scala index cc2d9141ce..fc1f45e358 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Unapplies.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Unapplies.scala @@ -142,17 +142,30 @@ trait Unapplies extends ast.TreeDSL { /** The unapply method corresponding to a case class */ def caseModuleUnapplyMeth(cdef: ClassDef): DefDef = { - val tparams = constrTparamsInvariant(cdef) - val method = constrParamss(cdef) match { + val tparams = constrTparamsInvariant(cdef) + val method = constrParamss(cdef) match { case xs :: _ if xs.nonEmpty && isRepeatedParamType(xs.last.tpt) => nme.unapplySeq case _ => nme.unapply } - val cparams = List(ValDef(Modifiers(PARAM | SYNTHETIC), unapplyParamName, classType(cdef, tparams), EmptyTree)) - val ifNull = if (constrParamss(cdef).head.isEmpty) FALSE else REF(NoneModule) - val body = nullSafe({ case Ident(x) => caseClassUnapplyReturnValue(x, cdef) }, ifNull)(Ident(unapplyParamName)) + val cparams = List(ValDef(Modifiers(PARAM | SYNTHETIC), unapplyParamName, classType(cdef, tparams), EmptyTree)) + val resultType = if (!settings.isScala212) TypeTree() else { // fix for SI-6541 under -Xsource:2.12 + def repeatedToSeq(tp: Tree) = tp match { + case AppliedTypeTree(Select(_, tpnme.REPEATED_PARAM_CLASS_NAME), tps) => AppliedTypeTree(gen.rootScalaDot(tpnme.Seq), tps) + case _ => tp + } + constrParamss(cdef) match { + case Nil | Nil :: _ => + gen.rootScalaDot(tpnme.Boolean) + case params :: _ => + val constrParamTypes = params.map(param => repeatedToSeq(param.tpt)) + AppliedTypeTree(gen.rootScalaDot(tpnme.Option), List(treeBuilder.makeTupleType(constrParamTypes))) + } + } + val ifNull = if (constrParamss(cdef).head.isEmpty) FALSE else REF(NoneModule) + val body = nullSafe({ case Ident(x) => caseClassUnapplyReturnValue(x, cdef) }, ifNull)(Ident(unapplyParamName)) atPos(cdef.pos.focus)( - DefDef(caseMods, method, tparams, List(cparams), TypeTree(), body) + DefDef(caseMods, method, tparams, List(cparams), resultType, body) ) } diff --git a/src/compiler/scala/tools/util/Javap.scala b/src/compiler/scala/tools/util/Javap.scala deleted file mode 100644 index 3cfc1eb2a1..0000000000 --- a/src/compiler/scala/tools/util/Javap.scala +++ /dev/null @@ -1,32 +0,0 @@ -/* NSC -- new Scala compiler - * Copyright 2005-2013 LAMP/EPFL - * @author Paul Phillips - */ - -package scala.tools -package util - -import scala.tools.nsc.util.ScalaClassLoader -import java.io.PrintWriter - -trait JpResult { - def isError: Boolean - def value: Any - def show(): Unit -} - -trait Javap { - def loader: ScalaClassLoader - def printWriter: PrintWriter - def apply(args: Seq[String]): List[JpResult] - def tryFile(path: String): Option[Array[Byte]] - def tryClass(path: String): Array[Byte] -} - -object NoJavap extends Javap { - def loader: ScalaClassLoader = getClass.getClassLoader - def printWriter: PrintWriter = new PrintWriter(System.err, true) - def apply(args: Seq[String]): List[JpResult] = Nil - def tryFile(path: String): Option[Array[Byte]] = None - def tryClass(path: String): Array[Byte] = Array() -} diff --git a/src/intellij-14/README b/src/intellij-14/README new file mode 100644 index 0000000000..310a766a20 --- /dev/null +++ b/src/intellij-14/README @@ -0,0 +1,12 @@ +Use the latest IntelliJ IDEA release and install the Scala plugin from within the IDE. + +Compilation withing IDEA is performed in "-Dlocker.skip=1" mode: the sources are built +directly using the STARR compiler. + +The following steps are required to use IntelliJ IDEA on Scala trunk + - Run "ant init". This will download some JARs from to ./build/deps, which are + included in IntelliJ's classpath. + - Run src/intellij-14/setup.sh + - Open ./src/intellij-14/scala.ipr in IntelliJ + - File, Project Settings, Project, SDK. Create an SDK entry named "1.6" containing the + Java 1.6 SDK diff --git a/src/intellij-14/actors.iml.SAMPLE b/src/intellij-14/actors.iml.SAMPLE new file mode 100644 index 0000000000..3da7a5f777 --- /dev/null +++ b/src/intellij-14/actors.iml.SAMPLE @@ -0,0 +1,14 @@ +<?xml version="1.0" encoding="UTF-8"?> +<module type="JAVA_MODULE" version="4"> + <component name="NewModuleRootManager" inherit-compiler-output="true"> + <exclude-output /> + <content url="file://$MODULE_DIR$/../actors"> + <sourceFolder url="file://$MODULE_DIR$/../actors" isTestSource="false" /> + </content> + <orderEntry type="inheritedJdk" /> + <orderEntry type="sourceFolder" forTests="false" /> + <orderEntry type="module" module-name="forkjoin" /> + <orderEntry type="module" module-name="library" /> + <orderEntry type="library" name="starr-no-deps" level="project" /> + </component> +</module>
\ No newline at end of file diff --git a/src/intellij-14/asm.iml.SAMPLE b/src/intellij-14/asm.iml.SAMPLE new file mode 100644 index 0000000000..9b2fd58ce7 --- /dev/null +++ b/src/intellij-14/asm.iml.SAMPLE @@ -0,0 +1,12 @@ +<?xml version="1.0" encoding="UTF-8"?> +<module type="JAVA_MODULE" version="4"> + <component name="NewModuleRootManager" inherit-compiler-output="true"> + <exclude-output /> + <content url="file://$MODULE_DIR$/../asm"> + <sourceFolder url="file://$MODULE_DIR$/../asm/src" isTestSource="false" /> + <sourceFolder url="file://$MODULE_DIR$/../asm" isTestSource="false" /> + </content> + <orderEntry type="inheritedJdk" /> + <orderEntry type="sourceFolder" forTests="false" /> + </component> +</module>
\ No newline at end of file diff --git a/src/intellij-14/compiler.iml.SAMPLE b/src/intellij-14/compiler.iml.SAMPLE new file mode 100644 index 0000000000..858ca2f2c2 --- /dev/null +++ b/src/intellij-14/compiler.iml.SAMPLE @@ -0,0 +1,16 @@ +<?xml version="1.0" encoding="UTF-8"?> +<module type="JAVA_MODULE" version="4"> + <component name="NewModuleRootManager" inherit-compiler-output="true"> + <exclude-output /> + <content url="file://$MODULE_DIR$/../compiler"> + <sourceFolder url="file://$MODULE_DIR$/../compiler" isTestSource="false" /> + </content> + <orderEntry type="inheritedJdk" /> + <orderEntry type="sourceFolder" forTests="false" /> + <orderEntry type="module" module-name="asm" /> + <orderEntry type="module" module-name="library" /> + <orderEntry type="module" module-name="reflect" /> + <orderEntry type="library" name="ant" level="project" /> + <orderEntry type="library" name="starr-no-deps" level="project" /> + </component> +</module>
\ No newline at end of file diff --git a/src/intellij-14/diff.sh b/src/intellij-14/diff.sh new file mode 100755 index 0000000000..54f9248608 --- /dev/null +++ b/src/intellij-14/diff.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env bash +# +# Diffs the SAMPLE files against the working project config. +# +export SCRIPT_DIR="$( cd "$( dirname "$0" )" && pwd )" +for f in "$SCRIPT_DIR"/*.{iml,ipr}; do + echo $f; diff -u $f.SAMPLE $f; +done diff --git a/src/intellij-14/forkjoin.iml.SAMPLE b/src/intellij-14/forkjoin.iml.SAMPLE new file mode 100644 index 0000000000..42507b2911 --- /dev/null +++ b/src/intellij-14/forkjoin.iml.SAMPLE @@ -0,0 +1,11 @@ +<?xml version="1.0" encoding="UTF-8"?> +<module type="JAVA_MODULE" version="4"> + <component name="NewModuleRootManager" inherit-compiler-output="true"> + <exclude-output /> + <content url="file://$MODULE_DIR$/../forkjoin"> + <sourceFolder url="file://$MODULE_DIR$/../forkjoin" isTestSource="false" /> + </content> + <orderEntry type="inheritedJdk" /> + <orderEntry type="sourceFolder" forTests="false" /> + </component> +</module>
\ No newline at end of file diff --git a/src/intellij-14/interactive.iml.SAMPLE b/src/intellij-14/interactive.iml.SAMPLE new file mode 100644 index 0000000000..db12a7dc9b --- /dev/null +++ b/src/intellij-14/interactive.iml.SAMPLE @@ -0,0 +1,16 @@ +<?xml version="1.0" encoding="UTF-8"?> +<module type="JAVA_MODULE" version="4"> + <component name="NewModuleRootManager" inherit-compiler-output="true"> + <exclude-output /> + <content url="file://$MODULE_DIR$/../interactive"> + <sourceFolder url="file://$MODULE_DIR$/../interactive" isTestSource="false" /> + </content> + <orderEntry type="inheritedJdk" /> + <orderEntry type="sourceFolder" forTests="false" /> + <orderEntry type="module" module-name="compiler" /> + <orderEntry type="module" module-name="library" /> + <orderEntry type="module" module-name="reflect" /> + <orderEntry type="module" module-name="scaladoc" /> + <orderEntry type="library" name="starr-no-deps" level="project" /> + </component> +</module>
\ No newline at end of file diff --git a/src/intellij-14/library.iml.SAMPLE b/src/intellij-14/library.iml.SAMPLE new file mode 100644 index 0000000000..08cccba4b9 --- /dev/null +++ b/src/intellij-14/library.iml.SAMPLE @@ -0,0 +1,13 @@ +<?xml version="1.0" encoding="UTF-8"?> +<module type="JAVA_MODULE" version="4"> + <component name="NewModuleRootManager" inherit-compiler-output="true"> + <exclude-output /> + <content url="file://$MODULE_DIR$/../library"> + <sourceFolder url="file://$MODULE_DIR$/../library" isTestSource="false" /> + </content> + <orderEntry type="inheritedJdk" /> + <orderEntry type="sourceFolder" forTests="false" /> + <orderEntry type="module" module-name="forkjoin" /> + <orderEntry type="library" name="starr-no-deps" level="project" /> + </component> +</module>
\ No newline at end of file diff --git a/src/intellij-14/manual.iml.SAMPLE b/src/intellij-14/manual.iml.SAMPLE new file mode 100644 index 0000000000..2e67076e28 --- /dev/null +++ b/src/intellij-14/manual.iml.SAMPLE @@ -0,0 +1,15 @@ +<?xml version="1.0" encoding="UTF-8"?> +<module type="JAVA_MODULE" version="4"> + <component name="NewModuleRootManager" inherit-compiler-output="true"> + <exclude-output /> + <content url="file://$MODULE_DIR$/../manual"> + <sourceFolder url="file://$MODULE_DIR$/../manual" isTestSource="false" /> + </content> + <orderEntry type="inheritedJdk" /> + <orderEntry type="sourceFolder" forTests="false" /> + <orderEntry type="module" module-name="library" /> + <orderEntry type="library" name="ant" level="project" /> + <orderEntry type="library" name="scaladoc-deps" level="project" /> + <orderEntry type="library" name="starr-no-deps" level="project" /> + </component> +</module>
\ No newline at end of file diff --git a/src/intellij-14/partest-extras.iml.SAMPLE b/src/intellij-14/partest-extras.iml.SAMPLE new file mode 100644 index 0000000000..b3537a949a --- /dev/null +++ b/src/intellij-14/partest-extras.iml.SAMPLE @@ -0,0 +1,18 @@ +<?xml version="1.0" encoding="UTF-8"?> +<module type="JAVA_MODULE" version="4"> + <component name="NewModuleRootManager" inherit-compiler-output="true"> + <exclude-output /> + <content url="file://$MODULE_DIR$/../partest-extras"> + <sourceFolder url="file://$MODULE_DIR$/../partest-extras" isTestSource="false" /> + </content> + <orderEntry type="inheritedJdk" /> + <orderEntry type="sourceFolder" forTests="false" /> + <orderEntry type="module" module-name="asm" /> + <orderEntry type="module" module-name="compiler" /> + <orderEntry type="module" module-name="library" /> + <orderEntry type="module" module-name="reflect" /> + <orderEntry type="module" module-name="repl" /> + <orderEntry type="library" name="partest" level="project" /> + <orderEntry type="library" name="starr-no-deps" level="project" /> + </component> +</module>
\ No newline at end of file diff --git a/src/intellij-14/partest-javaagent.iml.SAMPLE b/src/intellij-14/partest-javaagent.iml.SAMPLE new file mode 100644 index 0000000000..3a387aab0f --- /dev/null +++ b/src/intellij-14/partest-javaagent.iml.SAMPLE @@ -0,0 +1,13 @@ +<?xml version="1.0" encoding="UTF-8"?> +<module type="JAVA_MODULE" version="4"> + <component name="NewModuleRootManager" inherit-compiler-output="true"> + <exclude-output /> + <content url="file://$MODULE_DIR$/../partest-javaagent"> + <sourceFolder url="file://$MODULE_DIR$/../partest-javaagent" isTestSource="false" /> + </content> + <orderEntry type="inheritedJdk" /> + <orderEntry type="sourceFolder" forTests="false" /> + <orderEntry type="module" module-name="asm" /> + <orderEntry type="library" name="starr-no-deps" level="project" /> + </component> +</module>
\ No newline at end of file diff --git a/src/intellij-14/reflect.iml.SAMPLE b/src/intellij-14/reflect.iml.SAMPLE new file mode 100644 index 0000000000..87da13777b --- /dev/null +++ b/src/intellij-14/reflect.iml.SAMPLE @@ -0,0 +1,13 @@ +<?xml version="1.0" encoding="UTF-8"?> +<module type="JAVA_MODULE" version="4"> + <component name="NewModuleRootManager" inherit-compiler-output="true"> + <exclude-output /> + <content url="file://$MODULE_DIR$/../reflect"> + <sourceFolder url="file://$MODULE_DIR$/../reflect" isTestSource="false" /> + </content> + <orderEntry type="inheritedJdk" /> + <orderEntry type="sourceFolder" forTests="false" /> + <orderEntry type="module" module-name="library" /> + <orderEntry type="library" name="starr-no-deps" level="project" /> + </component> +</module>
\ No newline at end of file diff --git a/src/intellij-14/repl.iml.SAMPLE b/src/intellij-14/repl.iml.SAMPLE new file mode 100644 index 0000000000..2437aaae2d --- /dev/null +++ b/src/intellij-14/repl.iml.SAMPLE @@ -0,0 +1,16 @@ +<?xml version="1.0" encoding="UTF-8"?> +<module type="JAVA_MODULE" version="4"> + <component name="NewModuleRootManager" inherit-compiler-output="true"> + <exclude-output /> + <content url="file://$MODULE_DIR$/../repl"> + <sourceFolder url="file://$MODULE_DIR$/../repl" isTestSource="false" /> + </content> + <orderEntry type="inheritedJdk" /> + <orderEntry type="sourceFolder" forTests="false" /> + <orderEntry type="module" module-name="library" /> + <orderEntry type="module" module-name="compiler" /> + <orderEntry type="module" module-name="reflect" /> + <orderEntry type="library" name="repl-deps" level="project" /> + <orderEntry type="library" name="starr-no-deps" level="project" /> + </component> +</module>
\ No newline at end of file diff --git a/src/intellij-14/scala.iml.SAMPLE b/src/intellij-14/scala.iml.SAMPLE new file mode 100644 index 0000000000..9e8718dd45 --- /dev/null +++ b/src/intellij-14/scala.iml.SAMPLE @@ -0,0 +1,11 @@ +<?xml version="1.0" encoding="UTF-8"?> +<module type="JAVA_MODULE" version="4"> + <component name="NewModuleRootManager" inherit-compiler-output="true"> + <exclude-output /> + <content url="file://$MODULE_DIR$/../.."> + <excludeFolder url="file://$MODULE_DIR$/../../build" /> + </content> + <orderEntry type="inheritedJdk" /> + <orderEntry type="sourceFolder" forTests="false" /> + </component> +</module>
\ No newline at end of file diff --git a/src/intellij-14/scala.ipr.SAMPLE b/src/intellij-14/scala.ipr.SAMPLE new file mode 100644 index 0000000000..7c2022f3a9 --- /dev/null +++ b/src/intellij-14/scala.ipr.SAMPLE @@ -0,0 +1,261 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="CompilerConfiguration"> + <option name="DEFAULT_COMPILER" value="Javac" /> + <resourceExtensions /> + <wildcardResourcePatterns> + <entry name="!?*.java" /> + <entry name="!?*.form" /> + <entry name="!?*.class" /> + <entry name="!?*.groovy" /> + <entry name="!?*.scala" /> + <entry name="!?*.flex" /> + <entry name="!?*.kt" /> + <entry name="!?*.clj" /> + </wildcardResourcePatterns> + <annotationProcessing> + <profile default="true" name="Default" enabled="false"> + <processorPath useClasspath="true" /> + </profile> + </annotationProcessing> + </component> + <component name="CopyrightManager" default="" /> + <component name="DaemonCodeAnalyzer"> + <disable_hints /> + </component> + <component name="DependencyValidationManager"> + <option name="SKIP_IMPORT_STATEMENTS" value="false" /> + </component> + <component name="Encoding" useUTFGuessing="true" native2AsciiForPropertiesFiles="false" /> + <component name="EntryPointsManager"> + <entry_points version="2.0" /> + </component> + <component name="ProjectLevelVcsManager" settingsEditedManually="false"> + <OptionsSetting value="true" id="Add" /> + <OptionsSetting value="true" id="Remove" /> + <OptionsSetting value="true" id="Checkout" /> + <OptionsSetting value="true" id="Update" /> + <OptionsSetting value="true" id="Status" /> + <OptionsSetting value="true" id="Edit" /> + <ConfirmationsSetting value="0" id="Add" /> + <ConfirmationsSetting value="0" id="Remove" /> + </component> + <component name="ProjectModuleManager"> + <modules> + <module fileurl="file://$PROJECT_DIR$/actors.iml" filepath="$PROJECT_DIR$/actors.iml" /> + <module fileurl="file://$PROJECT_DIR$/asm.iml" filepath="$PROJECT_DIR$/asm.iml" /> + <module fileurl="file://$PROJECT_DIR$/compiler.iml" filepath="$PROJECT_DIR$/compiler.iml" /> + <module fileurl="file://$PROJECT_DIR$/forkjoin.iml" filepath="$PROJECT_DIR$/forkjoin.iml" /> + <module fileurl="file://$PROJECT_DIR$/interactive.iml" filepath="$PROJECT_DIR$/interactive.iml" /> + <module fileurl="file://$PROJECT_DIR$/library.iml" filepath="$PROJECT_DIR$/library.iml" /> + <module fileurl="file://$PROJECT_DIR$/manual.iml" filepath="$PROJECT_DIR$/manual.iml" /> + <module fileurl="file://$PROJECT_DIR$/partest-extras.iml" filepath="$PROJECT_DIR$/partest-extras.iml" /> + <module fileurl="file://$PROJECT_DIR$/partest-javaagent.iml" filepath="$PROJECT_DIR$/partest-javaagent.iml" /> + <module fileurl="file://$PROJECT_DIR$/reflect.iml" filepath="$PROJECT_DIR$/reflect.iml" /> + <module fileurl="file://$PROJECT_DIR$/repl.iml" filepath="$PROJECT_DIR$/repl.iml" /> + <module fileurl="file://$PROJECT_DIR$/scala.iml" filepath="$PROJECT_DIR$/scala.iml" /> + <module fileurl="file://$PROJECT_DIR$/scaladoc.iml" filepath="$PROJECT_DIR$/scaladoc.iml" /> + <module fileurl="file://$PROJECT_DIR$/scalap.iml" filepath="$PROJECT_DIR$/scalap.iml" /> + <module fileurl="file://$PROJECT_DIR$/test.iml" filepath="$PROJECT_DIR$/test.iml" /> + <module fileurl="file://$PROJECT_DIR$/test-junit.iml" filepath="$PROJECT_DIR$/test-junit.iml" /> + </modules> + </component> + <component name="ProjectRootManager" version="2" languageLevel="JDK_1_6" assert-keyword="true" jdk-15="true" project-jdk-name="1.6" project-jdk-type="JavaSDK"> + <output url="file://$PROJECT_DIR$/../../out" /> + </component> + <component name="PropertiesComponent"> + <property name="GoToClass.includeLibraries" value="false" /> + <property name="GoToClass.toSaveIncludeLibraries" value="false" /> + <property name="GoToFile.includeJavaFiles" value="false" /> + <property name="MemberChooser.sorted" value="false" /> + <property name="MemberChooser.showClasses" value="true" /> + <property name="MemberChooser.copyJavadoc" value="false" /> + <property name="options.lastSelected" value="configurable.group.appearance" /> + <property name="options.splitter.main.proportions" value="0.3" /> + <property name="options.splitter.details.proportions" value="0.2" /> + <property name="options.searchVisible" value="true" /> + </component> + <component name="RunManager"> + <configuration default="true" type="#org.jetbrains.idea.devkit.run.PluginConfigurationType" factoryName="Plugin"> + <module name="" /> + <option name="VM_PARAMETERS" value="-Xmx512m -Xms256m -XX:MaxPermSize=250m -ea" /> + <option name="PROGRAM_PARAMETERS" /> + <method /> + </configuration> + <configuration default="true" type="Remote" factoryName="Remote"> + <option name="USE_SOCKET_TRANSPORT" value="true" /> + <option name="SERVER_MODE" value="false" /> + <option name="SHMEM_ADDRESS" value="javadebug" /> + <option name="HOST" value="localhost" /> + <option name="PORT" value="5005" /> + <method /> + </configuration> + <configuration default="true" type="Applet" factoryName="Applet"> + <module name="" /> + <option name="MAIN_CLASS_NAME" /> + <option name="HTML_FILE_NAME" /> + <option name="HTML_USED" value="false" /> + <option name="WIDTH" value="400" /> + <option name="HEIGHT" value="300" /> + <option name="POLICY_FILE" value="$CARDEA_HOME$/bin/appletviewer.policy" /> + <option name="VM_PARAMETERS" /> + <option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" /> + <option name="ALTERNATIVE_JRE_PATH" /> + <method /> + </configuration> + <configuration default="true" type="TestNG" factoryName="TestNG"> + <extension name="coverage" enabled="false" merge="false" sample_coverage="true" runner="idea" /> + <module name="" /> + <option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" /> + <option name="ALTERNATIVE_JRE_PATH" /> + <option name="SUITE_NAME" /> + <option name="PACKAGE_NAME" /> + <option name="MAIN_CLASS_NAME" /> + <option name="METHOD_NAME" /> + <option name="GROUP_NAME" /> + <option name="TEST_OBJECT" value="CLASS" /> + <option name="VM_PARAMETERS" value="-ea" /> + <option name="PARAMETERS" /> + <option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" /> + <option name="OUTPUT_DIRECTORY" /> + <option name="ANNOTATION_TYPE" /> + <option name="ENV_VARIABLES" /> + <option name="PASS_PARENT_ENVS" value="true" /> + <option name="TEST_SEARCH_SCOPE"> + <value defaultName="moduleWithDependencies" /> + </option> + <option name="USE_DEFAULT_REPORTERS" value="false" /> + <option name="PROPERTIES_FILE" /> + <envs /> + <properties /> + <listeners /> + <method /> + </configuration> + <configuration default="true" type="Application" factoryName="Application"> + <extension name="coverage" enabled="false" merge="false" sample_coverage="true" runner="idea" /> + <option name="MAIN_CLASS_NAME" /> + <option name="VM_PARAMETERS" /> + <option name="PROGRAM_PARAMETERS" /> + <option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" /> + <option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" /> + <option name="ALTERNATIVE_JRE_PATH" /> + <option name="ENABLE_SWING_INSPECTOR" value="false" /> + <option name="ENV_VARIABLES" /> + <option name="PASS_PARENT_ENVS" value="true" /> + <module name="" /> + <envs /> + <method /> + </configuration> + <configuration default="true" type="JUnit" factoryName="JUnit"> + <extension name="coverage" enabled="false" merge="false" sample_coverage="true" runner="idea" /> + <module name="" /> + <option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" /> + <option name="ALTERNATIVE_JRE_PATH" /> + <option name="PACKAGE_NAME" /> + <option name="MAIN_CLASS_NAME" /> + <option name="METHOD_NAME" /> + <option name="TEST_OBJECT" value="class" /> + <option name="VM_PARAMETERS" value="-ea" /> + <option name="PARAMETERS" /> + <option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" /> + <option name="ENV_VARIABLES" /> + <option name="PASS_PARENT_ENVS" value="true" /> + <option name="TEST_SEARCH_SCOPE"> + <value defaultName="moduleWithDependencies" /> + </option> + <envs /> + <patterns /> + <method /> + </configuration> + <list size="0" /> + <configuration name="<template>" type="WebApp" default="true" selected="false"> + <Host>localhost</Host> + <Port>5050</Port> + </configuration> + </component> + <component name="ScalaCompilerConfiguration"> + <parameters> + <parameter value="-sourcepath" /> + <parameter value="$PROJECT_DIR$/../library" /> + </parameters> + </component> + <component name="VcsContentAnnotationSettings"> + <option name="myLimit" value="2678400000" /> + </component> + <component name="VcsDirectoryMappings"> + <mapping directory="$PROJECT_DIR$/../.." vcs="Git" /> + </component> + <component name="VcsManagerConfiguration"> + <option name="myTodoPanelSettings"> + <TodoPanelSettings /> + </option> + </component> + <component name="libraryTable"> + <library name="ant"> + <CLASSES> + <root url="jar://$PROJECT_DIR$/../../lib/ant/ant.jar!/" /> + </CLASSES> + <JAVADOC /> + <SOURCES /> + </library> + <library name="junit"> + <CLASSES> + <root url="file://$PROJECT_DIR$/../../build/deps/junit" /> + </CLASSES> + <JAVADOC /> + <SOURCES /> + <jarDirectory url="file://$PROJECT_DIR$/../../build/deps/junit" recursive="false" /> + </library> + <library name="partest"> + <CLASSES> + <root url="file://$PROJECT_DIR$/../../build/deps/partest" /> + </CLASSES> + <JAVADOC /> + <SOURCES /> + <jarDirectory url="file://$PROJECT_DIR$/../../build/deps/partest" recursive="false" /> + </library> + <library name="repl-deps"> + <CLASSES> + <root url="file://$PROJECT_DIR$/../../build/deps/repl" /> + </CLASSES> + <JAVADOC /> + <SOURCES /> + <jarDirectory url="file://$PROJECT_DIR$/../../build/deps/repl" recursive="false" /> + </library> + <library name="scaladoc-deps"> + <CLASSES> + <root url="file://$PROJECT_DIR$/../../build/deps/scaladoc" /> + </CLASSES> + <JAVADOC /> + <SOURCES /> + <jarDirectory url="file://$PROJECT_DIR$/../../build/deps/scaladoc" recursive="false" /> + </library> + <library name="starr" type="Scala"> + <properties> + <compiler-classpath> + <root url="file://$PROJECT_DIR$/../../build/deps/starr/scala-compiler-2.11.2.jar" /> + <root url="file://$PROJECT_DIR$/../../build/deps/starr/scala-library-2.11.2.jar" /> + <root url="file://$PROJECT_DIR$/../../build/deps/starr/scala-reflect-2.11.2.jar" /> + </compiler-classpath> + </properties> + <CLASSES> + <root url="jar://$PROJECT_DIR$/../../build/deps/starr/scala-library-2.11.2.jar!/" /> + <root url="jar://$PROJECT_DIR$/../../build/deps/starr/scala-reflect-2.11.2.jar!/" /> + </CLASSES> + <JAVADOC /> + <SOURCES /> + </library> + <library name="starr-no-deps" type="Scala"> + <properties> + <compiler-classpath> + <root url="file://$PROJECT_DIR$/../../build/deps/starr/scala-compiler-2.11.2.jar" /> + <root url="file://$PROJECT_DIR$/../../build/deps/starr/scala-library-2.11.2.jar" /> + <root url="file://$PROJECT_DIR$/../../build/deps/starr/scala-reflect-2.11.2.jar" /> + </compiler-classpath> + </properties> + <CLASSES /> + <JAVADOC /> + <SOURCES /> + </library> + </component> +</project>
\ No newline at end of file diff --git a/src/intellij-14/scaladoc.iml.SAMPLE b/src/intellij-14/scaladoc.iml.SAMPLE new file mode 100644 index 0000000000..1e7621ffed --- /dev/null +++ b/src/intellij-14/scaladoc.iml.SAMPLE @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="UTF-8"?> +<module type="JAVA_MODULE" version="4"> + <component name="NewModuleRootManager" inherit-compiler-output="true"> + <exclude-output /> + <content url="file://$MODULE_DIR$/../scaladoc"> + <sourceFolder url="file://$MODULE_DIR$/../scaladoc" isTestSource="false" /> + </content> + <orderEntry type="inheritedJdk" /> + <orderEntry type="sourceFolder" forTests="false" /> + <orderEntry type="module" module-name="compiler" /> + <orderEntry type="module" module-name="library" /> + <orderEntry type="module" module-name="reflect" /> + <orderEntry type="library" name="scaladoc-deps" level="project" /> + <orderEntry type="library" name="partest" level="project" /> + <orderEntry type="library" name="starr-no-deps" level="project" /> + </component> +</module>
\ No newline at end of file diff --git a/src/intellij-14/scalap.iml.SAMPLE b/src/intellij-14/scalap.iml.SAMPLE new file mode 100644 index 0000000000..e09b8d11b6 --- /dev/null +++ b/src/intellij-14/scalap.iml.SAMPLE @@ -0,0 +1,15 @@ +<?xml version="1.0" encoding="UTF-8"?> +<module type="JAVA_MODULE" version="4"> + <component name="NewModuleRootManager" inherit-compiler-output="true"> + <exclude-output /> + <content url="file://$MODULE_DIR$/../scalap"> + <sourceFolder url="file://$MODULE_DIR$/../scalap" isTestSource="false" /> + </content> + <orderEntry type="inheritedJdk" /> + <orderEntry type="sourceFolder" forTests="false" /> + <orderEntry type="module" module-name="compiler" /> + <orderEntry type="module" module-name="library" /> + <orderEntry type="module" module-name="reflect" /> + <orderEntry type="library" name="starr-no-deps" level="project" /> + </component> +</module>
\ No newline at end of file diff --git a/src/intellij-14/setup.sh b/src/intellij-14/setup.sh new file mode 100755 index 0000000000..ec303778ed --- /dev/null +++ b/src/intellij-14/setup.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash +# +# Generates IntelliJ IDEA project files based on the checked-in samples. +# + +set -e +export SCRIPT_DIR="$( cd "$( dirname "$0" )" && pwd )" +echo "About to delete .ipr and .iml files and replace with the .SAMPLE files. Press enter to continue or CTRL-C to cancel." +read + +for f in "$SCRIPT_DIR"/*.SAMPLE; do + g=${f%.SAMPLE} + cp $f $g +done diff --git a/src/intellij-14/test-junit.iml.SAMPLE b/src/intellij-14/test-junit.iml.SAMPLE new file mode 100644 index 0000000000..786f02e2e2 --- /dev/null +++ b/src/intellij-14/test-junit.iml.SAMPLE @@ -0,0 +1,22 @@ +<?xml version="1.0" encoding="UTF-8"?> +<module type="JAVA_MODULE" version="4"> + <component name="NewModuleRootManager" inherit-compiler-output="true"> + <exclude-output /> + <content url="file://$MODULE_DIR$/../../test/junit"> + <sourceFolder url="file://$MODULE_DIR$/../../test/junit" isTestSource="true" /> + </content> + <orderEntry type="inheritedJdk" /> + <orderEntry type="sourceFolder" forTests="false" /> + <orderEntry type="library" name="junit" level="project" /> + <orderEntry type="library" name="scaladoc-deps" level="project" /> + <orderEntry type="module" module-name="actors" /> + <orderEntry type="module" module-name="asm" /> + <orderEntry type="module" module-name="compiler" /> + <orderEntry type="module" module-name="forkjoin" /> + <orderEntry type="module" module-name="library" /> + <orderEntry type="module" module-name="partest-extras" /> + <orderEntry type="module" module-name="reflect" /> + <orderEntry type="module" module-name="repl" /> + <orderEntry type="library" name="starr-no-deps" level="project" /> + </component> +</module>
\ No newline at end of file diff --git a/src/intellij-14/test.iml.SAMPLE b/src/intellij-14/test.iml.SAMPLE new file mode 100644 index 0000000000..a384d72266 --- /dev/null +++ b/src/intellij-14/test.iml.SAMPLE @@ -0,0 +1,22 @@ +<?xml version="1.0" encoding="UTF-8"?> +<module type="JAVA_MODULE" version="4"> + <component name="NewModuleRootManager" inherit-compiler-output="true"> + <exclude-output /> + <content url="file://$MODULE_DIR$/../../test"> + <excludeFolder url="file://$MODULE_DIR$/../../test/junit" /> + </content> + <orderEntry type="inheritedJdk" /> + <orderEntry type="sourceFolder" forTests="false" /> + <orderEntry type="module" module-name="actors" /> + <orderEntry type="module" module-name="asm" /> + <orderEntry type="module" module-name="compiler" /> + <orderEntry type="module" module-name="forkjoin" /> + <orderEntry type="module" module-name="library" /> + <orderEntry type="module" module-name="partest-extras" /> + <orderEntry type="module" module-name="reflect" /> + <orderEntry type="module" module-name="repl" /> + <orderEntry type="library" name="partest" level="project" /> + <orderEntry type="library" name="scaladoc-deps" level="project" /> + <orderEntry type="library" name="starr-no-deps" level="project" /> + </component> +</module>
\ No newline at end of file diff --git a/src/intellij-14/update.sh b/src/intellij-14/update.sh new file mode 100755 index 0000000000..eb6fea782f --- /dev/null +++ b/src/intellij-14/update.sh @@ -0,0 +1,22 @@ +#!/usr/bin/env bash +# +# Updates the .SAMPLE files with the current project files. +# + +set -e +export SCRIPT_DIR="$( cd "$( dirname "$0" )" && pwd )" + +echo "About to create overwrite the .ipr.SAMPLE and .iml.SAMPLE files with the current project files. Press enter to continue or CTRL-C to cancel." +read + +for f in "$SCRIPT_DIR"/*.{iml,ipr}; do + cp $f $f.SAMPLE +done + +for f in "$SCRIPT_DIR"/*.SAMPLE; do + g=${f%.SAMPLE} + if [[ ! -f $g ]]; then + echo "Stale sample file, deleting $f" + rm $f + fi +done diff --git a/src/interactive/scala/tools/nsc/interactive/Global.scala b/src/interactive/scala/tools/nsc/interactive/Global.scala index 174254d523..7df809b6ff 100644 --- a/src/interactive/scala/tools/nsc/interactive/Global.scala +++ b/src/interactive/scala/tools/nsc/interactive/Global.scala @@ -64,7 +64,9 @@ trait InteractiveAnalyzer extends Analyzer { // that case the definitions that were already attributed as // well as any default parameters of such methods need to be // re-entered in the current scope. - override def enterExistingSym(sym: Symbol): Context = { + // + // Tested in test/files/presentation/t8941b + override def enterExistingSym(sym: Symbol, tree: Tree): Context = { if (sym != null && sym.owner.isTerm) { enterIfNotThere(sym) if (sym.isLazy) @@ -72,8 +74,13 @@ trait InteractiveAnalyzer extends Analyzer { for (defAtt <- sym.attachments.get[DefaultsOfLocalMethodAttachment]) defAtt.defaultGetters foreach enterIfNotThere + } else if (sym != null && sym.isClass && sym.isImplicit) { + val owningInfo = sym.owner.info + val existingDerivedSym = owningInfo.decl(sym.name.toTermName).filter(sym => sym.isSynthetic && sym.isMethod) + existingDerivedSym.alternatives foreach (owningInfo.decls.unlink) + enterImplicitWrapper(tree.asInstanceOf[ClassDef]) } - super.enterExistingSym(sym) + super.enterExistingSym(sym, tree) } override def enterIfNotThere(sym: Symbol) { val scope = context.scope @@ -732,7 +739,7 @@ class Global(settings: Settings, _reporter: Reporter, projectName: String = "") } } - private def reloadSource(source: SourceFile) { + private[interactive] def reloadSource(source: SourceFile) { val unit = new RichCompilationUnit(source) unitOfFile(source.file) = unit toBeRemoved -= source.file @@ -781,7 +788,7 @@ class Global(settings: Settings, _reporter: Reporter, projectName: String = "") } /** A fully attributed tree located at position `pos` */ - private def typedTreeAt(pos: Position): Tree = getUnit(pos.source) match { + private[interactive] def typedTreeAt(pos: Position): Tree = getUnit(pos.source) match { case None => reloadSources(List(pos.source)) try typedTreeAt(pos) diff --git a/src/library/scala/Option.scala b/src/library/scala/Option.scala index 66900e7258..86dbffab92 100644 --- a/src/library/scala/Option.scala +++ b/src/library/scala/Option.scala @@ -107,7 +107,7 @@ sealed abstract class Option[+A] extends Product with Serializable { /** Returns the option's value. * @note The option must be nonEmpty. - * @throws Predef.NoSuchElementException if the option is empty. + * @throws java.util.NoSuchElementException if the option is empty. */ def get: A diff --git a/src/library/scala/Predef.scala b/src/library/scala/Predef.scala index 7f717aa6e4..bf7739345e 100644 --- a/src/library/scala/Predef.scala +++ b/src/library/scala/Predef.scala @@ -220,7 +220,7 @@ object Predef extends LowPriorityImplicits with DeprecatedPredef { } /** `???` can be used for marking methods that remain to be implemented. - * @throws A `NotImplementedError` + * @throws NotImplementedError */ def ??? : Nothing = throw new NotImplementedError diff --git a/src/library/scala/Product.scala b/src/library/scala/Product.scala index 0798587772..9cd38ed148 100644 --- a/src/library/scala/Product.scala +++ b/src/library/scala/Product.scala @@ -22,7 +22,7 @@ trait Product extends Any with Equals { * product `A(x,,1,,, ..., x,,k,,)`, returns `x,,(n+1),,` where `0 < n < k`. * * @param n the index of the element to return - * @throws `IndexOutOfBoundsException` + * @throws IndexOutOfBoundsException * @return the element `n` elements after the first element */ def productElement(n: Int): Any diff --git a/src/library/scala/StringContext.scala b/src/library/scala/StringContext.scala index 2632994a34..e60fa2f290 100644 --- a/src/library/scala/StringContext.scala +++ b/src/library/scala/StringContext.scala @@ -58,7 +58,7 @@ case class StringContext(parts: String*) { /** Checks that the length of the given argument `args` is one less than the number * of `parts` supplied to the enclosing `StringContext`. * @param `args` The arguments to be checked. - * @throws An `IllegalArgumentException` if this is not the case. + * @throws IllegalArgumentException if this is not the case. */ def checkLengths(args: Seq[Any]): Unit = if (parts.length != args.length + 1) @@ -85,10 +85,11 @@ case class StringContext(parts: String*) { * will print the string `1 + 1 = 2`. * * @param `args` The arguments to be inserted into the resulting string. - * @throws An `IllegalArgumentException` + * @throws IllegalArgumentException * if the number of `parts` in the enclosing `StringContext` does not exceed * the number of arguments `arg` by exactly 1. - * @throws A `StringContext.InvalidEscapeException` if a `parts` string contains a backslash (`\`) character + * @throws StringContext.InvalidEscapeException + * if a `parts` string contains a backslash (`\`) character * that does not start a valid escape sequence. */ def s(args: Any*): String = standardInterpolator(treatEscapes, args) @@ -109,7 +110,7 @@ case class StringContext(parts: String*) { * }}} * * @param `args` The arguments to be inserted into the resulting string. - * @throws An `IllegalArgumentException` + * @throws IllegalArgumentException * if the number of `parts` in the enclosing `StringContext` does not exceed * the number of arguments `arg` by exactly 1. */ @@ -144,10 +145,11 @@ case class StringContext(parts: String*) { * }}} * * @param `args` The arguments to be inserted into the resulting string. - * @throws An `IllegalArgumentException` + * @throws IllegalArgumentException * if the number of `parts` in the enclosing `StringContext` does not exceed * the number of arguments `arg` by exactly 1. - * @throws A `StringContext.InvalidEscapeException` if a `parts` string contains a backslash (`\`) character + * @throws StringContext.InvalidEscapeException + * if a `parts` string contains a backslash (`\`) character * that does not start a valid escape sequence. * * Note: The `f` method works by assembling a format string from all the `parts` strings and using diff --git a/src/library/scala/collection/GenSeqLike.scala b/src/library/scala/collection/GenSeqLike.scala index c3bad60072..1c4f233e22 100644 --- a/src/library/scala/collection/GenSeqLike.scala +++ b/src/library/scala/collection/GenSeqLike.scala @@ -47,7 +47,7 @@ trait GenSeqLike[+A, +Repr] extends Any with GenIterableLike[A, Repr] with Equal * * @param idx The index to select. * @return the element of this $coll at index `idx`, where `0` indicates the first element. - * @throws `IndexOutOfBoundsException` if `idx` does not satisfy `0 <= idx < length`. + * @throws IndexOutOfBoundsException if `idx` does not satisfy `0 <= idx < length`. */ def apply(idx: Int): A diff --git a/src/library/scala/collection/GenTraversableLike.scala b/src/library/scala/collection/GenTraversableLike.scala index ca098e57b9..8b9d3e7a17 100644 --- a/src/library/scala/collection/GenTraversableLike.scala +++ b/src/library/scala/collection/GenTraversableLike.scala @@ -63,7 +63,7 @@ trait GenTraversableLike[+A, +Repr] extends Any with GenTraversableOnce[A] with /** Selects the first element of this $coll. * $orderDependent * @return the first element of this $coll. - * @throws `NoSuchElementException` if the $coll is empty. + * @throws NoSuchElementException if the $coll is empty. */ def head: A @@ -83,7 +83,7 @@ trait GenTraversableLike[+A, +Repr] extends Any with GenTraversableOnce[A] with * $orderDependent * @return a $coll consisting of all elements of this $coll * except the first one. - * @throws `UnsupportedOperationException` if the $coll is empty. + * @throws UnsupportedOperationException if the $coll is empty. */ def tail: Repr @@ -105,7 +105,7 @@ trait GenTraversableLike[+A, +Repr] extends Any with GenTraversableOnce[A] with * $orderDependent * @return a $coll consisting of all elements of this $coll * except the last one. - * @throws `UnsupportedOperationException` if the $coll is empty. + * @throws UnsupportedOperationException if the $coll is empty. */ def init: Repr diff --git a/src/library/scala/collection/GenTraversableOnce.scala b/src/library/scala/collection/GenTraversableOnce.scala index 0cd91409cf..8c7c754af8 100644 --- a/src/library/scala/collection/GenTraversableOnce.scala +++ b/src/library/scala/collection/GenTraversableOnce.scala @@ -268,7 +268,7 @@ trait GenTraversableOnce[+A] extends Any { * op(x_1, op(x_2, ..., op(x_{n-1}, x_n)...)) * }}} * where `x,,1,,, ..., x,,n,,` are the elements of this $coll. - * @throws `UnsupportedOperationException` if this $coll is empty. + * @throws UnsupportedOperationException if this $coll is empty. */ def reduceRight[B >: A](op: (A, B) => B): B diff --git a/src/library/scala/collection/LinearSeqOptimized.scala b/src/library/scala/collection/LinearSeqOptimized.scala index 8635b090b9..a28d796d5b 100755 --- a/src/library/scala/collection/LinearSeqOptimized.scala +++ b/src/library/scala/collection/LinearSeqOptimized.scala @@ -44,7 +44,7 @@ trait LinearSeqOptimized[+A, +Repr <: LinearSeqOptimized[A, Repr]] extends Linea /** Selects an element by its index in the $coll. * Note: the execution of `apply` may take time proportial to the index value. - * @throws `IndexOutOfBoundsException` if `idx` does not satisfy `0 <= idx < length`. + * @throws IndexOutOfBoundsException if `idx` does not satisfy `0 <= idx < length`. */ def apply(n: Int): A = { val rest = drop(n) diff --git a/src/library/scala/collection/MapLike.scala b/src/library/scala/collection/MapLike.scala index 5ec7d5c615..d133400570 100644 --- a/src/library/scala/collection/MapLike.scala +++ b/src/library/scala/collection/MapLike.scala @@ -222,7 +222,7 @@ self => * but it might be overridden in subclasses. * * @param key the given key value for which a binding is missing. - * @throws `NoSuchElementException` + * @throws NoSuchElementException */ def default(key: A): B = throw new NoSuchElementException("key not found: " + key) diff --git a/src/library/scala/collection/TraversableLike.scala b/src/library/scala/collection/TraversableLike.scala index d3a7db6968..32d31f0be8 100644 --- a/src/library/scala/collection/TraversableLike.scala +++ b/src/library/scala/collection/TraversableLike.scala @@ -419,7 +419,7 @@ trait TraversableLike[+A, +Repr] extends Any /** Selects the first element of this $coll. * $orderDependent * @return the first element of this $coll. - * @throws `NoSuchElementException` if the $coll is empty. + * @throws NoSuchElementException if the $coll is empty. */ def head: A = { var result: () => A = () => throw new NoSuchElementException @@ -473,7 +473,7 @@ trait TraversableLike[+A, +Repr] extends Any * $orderDependent * @return a $coll consisting of all elements of this $coll * except the last one. - * @throws `UnsupportedOperationException` if the $coll is empty. + * @throws UnsupportedOperationException if the $coll is empty. */ def init: Repr = { if (isEmpty) throw new UnsupportedOperationException("empty.init") diff --git a/src/library/scala/collection/TraversableOnce.scala b/src/library/scala/collection/TraversableOnce.scala index 13cd99d910..2eab58009c 100644 --- a/src/library/scala/collection/TraversableOnce.scala +++ b/src/library/scala/collection/TraversableOnce.scala @@ -159,7 +159,7 @@ trait TraversableOnce[+A] extends Any with GenTraversableOnce[A] { * op( op( ... op(x_1, x_2) ..., x_{n-1}), x_n) * }}} * where `x,,1,,, ..., x,,n,,` are the elements of this $coll. - * @throws `UnsupportedOperationException` if this $coll is empty. */ + * @throws UnsupportedOperationException if this $coll is empty. */ def reduceLeft[B >: A](op: (B, A) => B): B = { if (isEmpty) throw new UnsupportedOperationException("empty.reduceLeft") diff --git a/src/library/scala/collection/generic/GenericTraversableTemplate.scala b/src/library/scala/collection/generic/GenericTraversableTemplate.scala index cd48cd23f4..64cf1cfb1e 100644 --- a/src/library/scala/collection/generic/GenericTraversableTemplate.scala +++ b/src/library/scala/collection/generic/GenericTraversableTemplate.scala @@ -45,7 +45,7 @@ trait GenericTraversableTemplate[+A, +CC[X] <: GenTraversable[X]] extends HasNew /** Selects the first element of this $coll. * * @return the first element of this $coll. - * @throws `NoSuchElementException` if the $coll is empty. + * @throws NoSuchElementException if the $coll is empty. */ def head: A @@ -202,7 +202,7 @@ trait GenericTraversableTemplate[+A, +CC[X] <: GenTraversable[X]] extends HasNew * element type of this $coll is a `Traversable`. * @return a two-dimensional $coll of ${coll}s which has as ''n''th row * the ''n''th column of this $coll. - * @throws `IllegalArgumentException` if all collections in this $coll + * @throws IllegalArgumentException if all collections in this $coll * are not of the same size. */ @migration("`transpose` throws an `IllegalArgumentException` if collections are not uniformly sized.", "2.9.0") diff --git a/src/library/scala/collection/immutable/List.scala b/src/library/scala/collection/immutable/List.scala index aa9dec2761..9bfefc3de2 100644 --- a/src/library/scala/collection/immutable/List.scala +++ b/src/library/scala/collection/immutable/List.scala @@ -290,7 +290,6 @@ sealed abstract class List[+A] extends AbstractSeq[A] if (this eq Nil) Nil.asInstanceOf[That] else { var rest = this var h: ::[B] = null - var x: A = null.asInstanceOf[A] // Special case for first element do { val x: Any = pf.applyOrElse(rest.head, List.partialNotApplied) diff --git a/src/library/scala/collection/immutable/ListSet.scala b/src/library/scala/collection/immutable/ListSet.scala index 89d1a9640e..a6e6fba0a5 100644 --- a/src/library/scala/collection/immutable/ListSet.scala +++ b/src/library/scala/collection/immutable/ListSet.scala @@ -111,7 +111,7 @@ class ListSet[A] extends AbstractSet[A] /** Creates a new iterator over all elements contained in this set. * - * @throws Predef.NoSuchElementException + * @throws java.util.NoSuchElementException * @return the new iterator */ def iterator: Iterator[A] = new AbstractIterator[A] { @@ -127,12 +127,12 @@ class ListSet[A] extends AbstractSet[A] } /** - * @throws Predef.NoSuchElementException + * @throws java.util.NoSuchElementException */ override def head: A = throw new NoSuchElementException("Set has no elements") /** - * @throws Predef.NoSuchElementException + * @throws java.util.NoSuchElementException */ override def tail: ListSet[A] = throw new NoSuchElementException("Next of an empty set") diff --git a/src/library/scala/collection/immutable/Queue.scala b/src/library/scala/collection/immutable/Queue.scala index 264304db68..98266716cc 100644 --- a/src/library/scala/collection/immutable/Queue.scala +++ b/src/library/scala/collection/immutable/Queue.scala @@ -53,7 +53,7 @@ class Queue[+A] protected(protected val in: List[A], protected val out: List[A]) * * @param n index of the element to return * @return the element at position `n` in this queue. - * @throws Predef.NoSuchElementException if the queue is too short. + * @throws java.util.NoSuchElementException if the queue is too short. */ override def apply(n: Int): A = { val len = out.length @@ -120,7 +120,7 @@ class Queue[+A] protected(protected val in: List[A], protected val out: List[A]) /** Returns a tuple with the first element in the queue, * and a new queue with this element removed. * - * @throws Predef.NoSuchElementException + * @throws java.util.NoSuchElementException * @return the first element of the queue. */ def dequeue: (A, Queue[A]) = out match { @@ -139,7 +139,7 @@ class Queue[+A] protected(protected val in: List[A], protected val out: List[A]) /** Returns the first element in the queue, or throws an error if there * is no element contained in the queue. * - * @throws Predef.NoSuchElementException + * @throws java.util.NoSuchElementException * @return the first element. */ def front: A = head diff --git a/src/library/scala/collection/immutable/Stack.scala b/src/library/scala/collection/immutable/Stack.scala index b77b16f23f..1c28093b2c 100644 --- a/src/library/scala/collection/immutable/Stack.scala +++ b/src/library/scala/collection/immutable/Stack.scala @@ -95,7 +95,7 @@ class Stack[+A] protected (protected val elems: List[A]) /** Returns the top element of the stack. An error is signaled if * there is no element on the stack. * - * @throws Predef.NoSuchElementException + * @throws java.util.NoSuchElementException * @return the top element. */ def top: A = @@ -105,7 +105,7 @@ class Stack[+A] protected (protected val elems: List[A]) /** Removes the top element from the stack. * Note: should return `(A, Stack[A])` as for queues (mics) * - * @throws Predef.NoSuchElementException + * @throws java.util.NoSuchElementException * @return the new stack without the former top element. */ def pop: Stack[A] = diff --git a/src/library/scala/collection/immutable/Stream.scala b/src/library/scala/collection/immutable/Stream.scala index 714d5117d3..09a69b8096 100644 --- a/src/library/scala/collection/immutable/Stream.scala +++ b/src/library/scala/collection/immutable/Stream.scala @@ -225,7 +225,7 @@ self => * }}} * * @return The first element of the `Stream`. - * @throws Predef.NoSuchElementException if the stream is empty. + * @throws java.util.NoSuchElementException if the stream is empty. */ def head: A @@ -236,7 +236,7 @@ self => * returns the lazy result. * * @return The tail of the `Stream`. - * @throws Predef.UnsupportedOperationException if the stream is empty. + * @throws UnsupportedOperationException if the stream is empty. */ def tail: Stream[A] @@ -876,7 +876,7 @@ self => * @return A new `Stream` containing everything but the last element. If your * `Stream` represents an infinite series, this method will not return. * - * @throws `Predef.UnsupportedOperationException` if the stream is empty. + * @throws UnsupportedOperationException if the stream is empty. */ override def init: Stream[A] = if (isEmpty) super.init diff --git a/src/library/scala/collection/immutable/StringLike.scala b/src/library/scala/collection/immutable/StringLike.scala index bf93a38f55..f0daaf25a5 100644 --- a/src/library/scala/collection/immutable/StringLike.scala +++ b/src/library/scala/collection/immutable/StringLike.scala @@ -230,31 +230,31 @@ self => def r(groupNames: String*): Regex = new Regex(toString, groupNames: _*) /** - * @throws `java.lang.IllegalArgumentException` - If the string does not contain a parsable boolean. + * @throws java.lang.IllegalArgumentException - If the string does not contain a parsable boolean. */ def toBoolean: Boolean = parseBoolean(toString) /** - * @throws `java.lang.NumberFormatException` - If the string does not contain a parsable byte. + * @throws java.lang.NumberFormatException - If the string does not contain a parsable byte. */ def toByte: Byte = java.lang.Byte.parseByte(toString) /** - * @throws `java.lang.NumberFormatException` - If the string does not contain a parsable short. + * @throws java.lang.NumberFormatException - If the string does not contain a parsable short. */ def toShort: Short = java.lang.Short.parseShort(toString) /** - * @throws `java.lang.NumberFormatException` - If the string does not contain a parsable int. + * @throws java.lang.NumberFormatException - If the string does not contain a parsable int. */ def toInt: Int = java.lang.Integer.parseInt(toString) /** - * @throws `java.lang.NumberFormatException` - If the string does not contain a parsable long. + * @throws java.lang.NumberFormatException - If the string does not contain a parsable long. */ def toLong: Long = java.lang.Long.parseLong(toString) /** - * @throws `java.lang.NumberFormatException` - If the string does not contain a parsable float. + * @throws java.lang.NumberFormatException - If the string does not contain a parsable float. */ def toFloat: Float = java.lang.Float.parseFloat(toString) /** - * @throws `java.lang.NumberFormatException` - If the string does not contain a parsable double. + * @throws java.lang.NumberFormatException - If the string does not contain a parsable double. */ def toDouble: Double = java.lang.Double.parseDouble(toString) @@ -287,7 +287,7 @@ self => * understands. * * @param args the arguments used to instantiating the pattern. - * @throws `java.lang.IllegalArgumentException` + * @throws java.lang.IllegalArgumentException */ def format(args : Any*): String = java.lang.String.format(toString, args map unwrapArg: _*) @@ -304,7 +304,7 @@ self => * * @param l an instance of `java.util.Locale` * @param args the arguments used to instantiating the pattern. - * @throws `java.lang.IllegalArgumentException` + * @throws java.lang.IllegalArgumentException */ def formatLocal(l: java.util.Locale, args: Any*): String = java.lang.String.format(l, toString, args map unwrapArg: _*) diff --git a/src/library/scala/collection/mutable/AnyRefMap.scala b/src/library/scala/collection/mutable/AnyRefMap.scala index 47fb66744e..fccc9d83e6 100644 --- a/src/library/scala/collection/mutable/AnyRefMap.scala +++ b/src/library/scala/collection/mutable/AnyRefMap.scala @@ -224,7 +224,7 @@ extends AbstractMap[K, V] override def put(key: K, value: V): Option[V] = { val h = hashOf(key) val k = key - var i = seekEntryOrOpen(h, k) + val i = seekEntryOrOpen(h, k) if (i < 0) { val j = i & IndexMask _hashes(j) = h @@ -251,7 +251,7 @@ extends AbstractMap[K, V] override def update(key: K, value: V): Unit = { val h = hashOf(key) val k = key - var i = seekEntryOrOpen(h, k) + val i = seekEntryOrOpen(h, k) if (i < 0) { val j = i & IndexMask _hashes(j) = h diff --git a/src/library/scala/collection/mutable/ArrayBuffer.scala b/src/library/scala/collection/mutable/ArrayBuffer.scala index 2d43b352c5..8df606222f 100644 --- a/src/library/scala/collection/mutable/ArrayBuffer.scala +++ b/src/library/scala/collection/mutable/ArrayBuffer.scala @@ -133,7 +133,7 @@ class ArrayBuffer[A](override protected val initialSize: Int) * * @param n the index where a new element will be inserted. * @param seq the traversable object providing all elements to insert. - * @throws Predef.IndexOutOfBoundsException if `n` is out of bounds. + * @throws IndexOutOfBoundsException if `n` is out of bounds. */ def insertAll(n: Int, seq: Traversable[A]) { if (n < 0 || n > size0) throw new IndexOutOfBoundsException(n.toString) @@ -150,7 +150,7 @@ class ArrayBuffer[A](override protected val initialSize: Int) * * @param n the index which refers to the first element to delete. * @param count the number of elements to delete - * @throws Predef.IndexOutOfBoundsException if `n` is out of bounds. + * @throws IndexOutOfBoundsException if `n` is out of bounds. */ override def remove(n: Int, count: Int) { require(count >= 0, "removing negative number of elements") diff --git a/src/library/scala/collection/mutable/BitSet.scala b/src/library/scala/collection/mutable/BitSet.scala index 43d23acc1a..faa4155317 100644 --- a/src/library/scala/collection/mutable/BitSet.scala +++ b/src/library/scala/collection/mutable/BitSet.scala @@ -110,7 +110,7 @@ class BitSet(protected final var elems: Array[Long]) extends AbstractSet[Int] * @return the bitset itself. */ def |= (other: BitSet): this.type = { - ensureCapacity(other.nwords) + ensureCapacity(other.nwords - 1) for (i <- 0 until other.nwords) elems(i) = elems(i) | other.word(i) this @@ -121,7 +121,7 @@ class BitSet(protected final var elems: Array[Long]) extends AbstractSet[Int] * @return the bitset itself. */ def &= (other: BitSet): this.type = { - ensureCapacity(other.nwords) + ensureCapacity(other.nwords - 1) for (i <- 0 until other.nwords) elems(i) = elems(i) & other.word(i) this @@ -132,7 +132,7 @@ class BitSet(protected final var elems: Array[Long]) extends AbstractSet[Int] * @return the bitset itself. */ def ^= (other: BitSet): this.type = { - ensureCapacity(other.nwords) + ensureCapacity(other.nwords - 1) for (i <- 0 until other.nwords) elems(i) = elems(i) ^ other.word(i) this @@ -143,7 +143,7 @@ class BitSet(protected final var elems: Array[Long]) extends AbstractSet[Int] * @return the bitset itself. */ def &~= (other: BitSet): this.type = { - ensureCapacity(other.nwords) + ensureCapacity(other.nwords - 1) for (i <- 0 until other.nwords) elems(i) = elems(i) & ~other.word(i) this diff --git a/src/library/scala/collection/mutable/ListBuffer.scala b/src/library/scala/collection/mutable/ListBuffer.scala index 5e838d0d88..8faaf97741 100644 --- a/src/library/scala/collection/mutable/ListBuffer.scala +++ b/src/library/scala/collection/mutable/ListBuffer.scala @@ -132,7 +132,7 @@ final class ListBuffer[A] * * @param n the index of the element to replace. * @param x the new element. - * @throws Predef.IndexOutOfBoundsException if `n` is out of bounds. + * @throws IndexOutOfBoundsException if `n` is out of bounds. */ def update(n: Int, x: A) { // We check the bounds early, so that we don't trigger copying. @@ -217,7 +217,7 @@ final class ListBuffer[A] * * @param n the index where a new element will be inserted. * @param seq the iterable object providing all elements to insert. - * @throws Predef.IndexOutOfBoundsException if `n` is out of bounds. + * @throws IndexOutOfBoundsException if `n` is out of bounds. */ def insertAll(n: Int, seq: Traversable[A]) { // We check the bounds early, so that we don't trigger copying. @@ -330,7 +330,7 @@ final class ListBuffer[A] * @param n the index which refers to the element to delete. * @return n the element that was formerly at position `n`. * @note an element must exists at position `n`. - * @throws Predef.IndexOutOfBoundsException if `n` is out of bounds. + * @throws IndexOutOfBoundsException if `n` is out of bounds. */ def remove(n: Int): A = { if (n < 0 || n >= len) throw new IndexOutOfBoundsException(n.toString()) diff --git a/src/library/scala/collection/mutable/LongMap.scala b/src/library/scala/collection/mutable/LongMap.scala index ef488a3697..5fafe23d9f 100644 --- a/src/library/scala/collection/mutable/LongMap.scala +++ b/src/library/scala/collection/mutable/LongMap.scala @@ -81,7 +81,7 @@ extends AbstractMap[Long, V] private def toIndex(k: Long): Int = { // Part of the MurmurHash3 32 bit finalizer val h = ((k ^ (k >>> 32)) & 0xFFFFFFFFL).toInt - var x = (h ^ (h >>> 16)) * 0x85EBCA6B + val x = (h ^ (h >>> 16)) * 0x85EBCA6B (x ^ (x >>> 13)) & mask } @@ -311,7 +311,7 @@ extends AbstractMap[Long, V] } } else { - var i = seekEntryOrOpen(key) + val i = seekEntryOrOpen(key) if (i < 0) { val j = i & IndexMask _keys(j) = key diff --git a/src/library/scala/collection/mutable/PriorityQueue.scala b/src/library/scala/collection/mutable/PriorityQueue.scala index a6e538528a..4a9a5d4008 100644 --- a/src/library/scala/collection/mutable/PriorityQueue.scala +++ b/src/library/scala/collection/mutable/PriorityQueue.scala @@ -126,7 +126,7 @@ class PriorityQueue[A](implicit val ord: Ordering[A]) /** Returns the element with the highest priority in the queue, * and removes this element from the queue. * - * @throws Predef.NoSuchElementException + * @throws java.util.NoSuchElementException * @return the element with the highest priority. */ def dequeue(): A = diff --git a/src/library/scala/collection/mutable/Queue.scala b/src/library/scala/collection/mutable/Queue.scala index 7c890fe309..03d387a535 100644 --- a/src/library/scala/collection/mutable/Queue.scala +++ b/src/library/scala/collection/mutable/Queue.scala @@ -58,7 +58,7 @@ extends MutableList[A] /** Returns the first element in the queue, and removes this element * from the queue. * - * @throws Predef.NoSuchElementException + * @throws java.util.NoSuchElementException * @return the first element of the queue. */ def dequeue(): A = diff --git a/src/library/scala/collection/mutable/SetLike.scala b/src/library/scala/collection/mutable/SetLike.scala index a377b03124..81a71adc91 100644 --- a/src/library/scala/collection/mutable/SetLike.scala +++ b/src/library/scala/collection/mutable/SetLike.scala @@ -208,7 +208,7 @@ trait SetLike[A, +This <: SetLike[A, This] with Set[A]] /** Send a message to this scriptable object. * * @param cmd the message to send. - * @throws `Predef.UnsupportedOperationException` + * @throws UnsupportedOperationException * if the message was not understood. */ @deprecated("Scripting is deprecated.", "2.11.0") diff --git a/src/library/scala/collection/mutable/Stack.scala b/src/library/scala/collection/mutable/Stack.scala index 53b6c59939..1a92f23b7b 100644 --- a/src/library/scala/collection/mutable/Stack.scala +++ b/src/library/scala/collection/mutable/Stack.scala @@ -125,7 +125,7 @@ extends AbstractSeq[A] * the element from the stack. An error is signaled if there is no * element on the stack. * - * @throws Predef.NoSuchElementException + * @throws java.util.NoSuchElementException * @return the top element */ def top: A = @@ -133,7 +133,7 @@ extends AbstractSeq[A] /** Removes the top element from the stack. * - * @throws Predef.NoSuchElementException + * @throws java.util.NoSuchElementException * @return the top element */ def pop(): A = { diff --git a/src/library/scala/compat/Platform.scala b/src/library/scala/compat/Platform.scala index 875d811b9b..4c82d6e15b 100644 --- a/src/library/scala/compat/Platform.scala +++ b/src/library/scala/compat/Platform.scala @@ -70,9 +70,9 @@ object Platform { * @param elemClass the `Class` object of the component type of the array * @param length the length of the new array. * @return an array of the given component type as an `AnyRef`. - * @throws `java.lang.NullPointerException` If `elemClass` is `null`. - * @throws `java.lang.IllegalArgumentException` if componentType is [[scala.Unit]] or `java.lang.Void.TYPE` - * @throws `java.lang.NegativeArraySizeException` if the specified length is negative + * @throws java.lang.NullPointerException If `elemClass` is `null`. + * @throws java.lang.IllegalArgumentException if componentType is [[scala.Unit]] or `java.lang.Void.TYPE` + * @throws java.lang.NegativeArraySizeException if the specified length is negative */ @inline def createArray(elemClass: Class[_], length: Int): AnyRef = @@ -80,7 +80,7 @@ object Platform { /** Assigns the value of 0 to each element in the array. * @param arr A non-null Array[Int]. - * @throws `java.lang.NullPointerException` If `arr` is `null`. + * @throws java.lang.NullPointerException If `arr` is `null`. */ @inline def arrayclear(arr: Array[Int]) { java.util.Arrays.fill(arr, 0) } @@ -92,9 +92,9 @@ object Platform { * * @param name the fully qualified name of the desired class. * @return the `Class` object for the class with the specified name. - * @throws `java.lang.LinkageError` if the linkage fails - * @throws `java.lang.ExceptionInInitializerError` if the initialization provoked by this method fails - * @throws `java.lang.ClassNotFoundException` if the class cannot be located + * @throws java.lang.LinkageError if the linkage fails + * @throws java.lang.ExceptionInInitializerError if the initialization provoked by this method fails + * @throws java.lang.ClassNotFoundException if the class cannot be located * @example {{{ * val a = scala.compat.Platform.getClassForName("java.lang.Integer") // returns the Class[_] for java.lang.Integer * }}} diff --git a/src/library/scala/concurrent/package.scala b/src/library/scala/concurrent/package.scala index 4d88253de4..4843d28679 100644 --- a/src/library/scala/concurrent/package.scala +++ b/src/library/scala/concurrent/package.scala @@ -47,8 +47,8 @@ package object concurrent { * Blocking on an [[Awaitable]] should be done using [[Await.result]] instead of `blocking`. * * @param body A piece of code which contains potentially blocking or long running calls. - * @throws `CancellationException` if the computation was cancelled - * @throws `InterruptedException` in the case that a wait within the blocking `body` was interrupted + * @throws CancellationException if the computation was cancelled + * @throws InterruptedException in the case that a wait within the blocking `body` was interrupted */ @throws(classOf[Exception]) def blocking[T](body: =>T): T = BlockContext.current.blockOn(body)(scala.concurrent.AwaitPermission) diff --git a/src/library/scala/reflect/ClassTag.scala b/src/library/scala/reflect/ClassTag.scala index bced505273..2f4aa9cb84 100644 --- a/src/library/scala/reflect/ClassTag.scala +++ b/src/library/scala/reflect/ClassTag.scala @@ -2,8 +2,7 @@ package scala package reflect import java.lang.{ Class => jClass } -import scala.language.{implicitConversions, existentials} -import scala.runtime.ScalaRunTime.{ arrayClass, arrayElementClass } +import scala.runtime.ScalaRunTime.arrayElementClass /** * diff --git a/src/library/scala/util/Either.scala b/src/library/scala/util/Either.scala index b1a932be7e..e196d403c2 100644 --- a/src/library/scala/util/Either.scala +++ b/src/library/scala/util/Either.scala @@ -274,7 +274,7 @@ object Either { */ final case class LeftProjection[+A, +B](e: Either[A, B]) { /** - * Returns the value from this `Left` or throws `Predef.NoSuchElementException` + * Returns the value from this `Left` or throws `java.util.NoSuchElementException` * if this is a `Right`. * * {{{ @@ -282,7 +282,7 @@ object Either { * Right(12).left.get // NoSuchElementException * }}} * - * @throws Predef.NoSuchElementException if the projection is [[scala.util.Right]] + * @throws java.util.NoSuchElementException if the projection is [[scala.util.Right]] */ def get = e match { case Left(a) => a @@ -440,14 +440,14 @@ object Either { /** * Returns the value from this `Right` or throws - * `Predef.NoSuchElementException` if this is a `Left`. + * `java.util.NoSuchElementException` if this is a `Left`. * * {{{ * Right(12).right.get // 12 * Left(12).right.get // NoSuchElementException * }}} * - * @throws Predef.NoSuchElementException if the projection is `Left`. + * @throws java.util.NoSuchElementException if the projection is `Left`. */ def get = e match { case Left(_) => throw new NoSuchElementException("Either.right.value on Left") diff --git a/src/reflect/scala/reflect/internal/AnnotationInfos.scala b/src/reflect/scala/reflect/internal/AnnotationInfos.scala index fcef4dd6be..6863cdfd82 100644 --- a/src/reflect/scala/reflect/internal/AnnotationInfos.scala +++ b/src/reflect/scala/reflect/internal/AnnotationInfos.scala @@ -15,7 +15,6 @@ import scala.language.postfixOps /** AnnotationInfo and its helpers */ trait AnnotationInfos extends api.Annotations { self: SymbolTable => import definitions._ - import treeInfo._ // Common annotation code between Symbol and Type. // For methods altering the annotation list, on Symbol it mutates diff --git a/src/reflect/scala/reflect/internal/Definitions.scala b/src/reflect/scala/reflect/internal/Definitions.scala index 70375d974c..6b979795ec 100644 --- a/src/reflect/scala/reflect/internal/Definitions.scala +++ b/src/reflect/scala/reflect/internal/Definitions.scala @@ -905,12 +905,14 @@ trait Definitions extends api.StandardDefinitions { ) } - def EnumType(sym: Symbol) = + def EnumType(sym: Symbol) = { // given (in java): "class A { enum E { VAL1 } }" // - sym: the symbol of the actual enumeration value (VAL1) // - .owner: the ModuleClassSymbol of the enumeration (object E) // - .linkedClassOfClass: the ClassSymbol of the enumeration (class E) - sym.owner.linkedClassOfClass.tpe + // SI-6613 Subsequent runs of the resident compiler demand the phase discipline here. + enteringPhaseNotLaterThan(picklerPhase)(sym.owner.linkedClassOfClass).tpe + } /** Given a class symbol C with type parameters T1, T2, ... Tn * which have upper/lower bounds LB1/UB1, LB1/UB2, ..., LBn/UBn, @@ -1116,7 +1118,7 @@ trait Definitions extends api.StandardDefinitions { lazy val ScalaInlineClass = requiredClass[scala.inline] lazy val ScalaNoInlineClass = requiredClass[scala.noinline] lazy val SerialVersionUIDAttr = requiredClass[scala.SerialVersionUID] - lazy val SerialVersionUIDAnnotation = AnnotationInfo(SerialVersionUIDAttr.tpe, List(Literal(Constant(0))), List()) + lazy val SerialVersionUIDAnnotation = AnnotationInfo(SerialVersionUIDAttr.tpe, List(), List(nme.value -> LiteralAnnotArg(Constant(0)))) lazy val SpecializedClass = requiredClass[scala.specialized] lazy val ThrowsClass = requiredClass[scala.throws[_]] lazy val TransientAttr = requiredClass[scala.transient] @@ -1437,6 +1439,10 @@ trait Definitions extends api.StandardDefinitions { lazy val isUnbox = unboxMethod.values.toSet[Symbol] lazy val isBox = boxMethod.values.toSet[Symbol] + lazy val Boolean_and = definitions.Boolean_and + lazy val Boolean_or = definitions.Boolean_or + lazy val Boolean_not = definitions.Boolean_not + lazy val Option_apply = getMemberMethod(OptionModule, nme.apply) lazy val List_apply = DefinitionsClass.this.List_apply diff --git a/src/reflect/scala/reflect/internal/Internals.scala b/src/reflect/scala/reflect/internal/Internals.scala index 26f3bfd9d0..ad4cec5b4d 100644 --- a/src/reflect/scala/reflect/internal/Internals.scala +++ b/src/reflect/scala/reflect/internal/Internals.scala @@ -9,7 +9,6 @@ import scala.ref.WeakReference import scala.reflect.api.Universe import scala.reflect.macros.Attachments import scala.reflect.internal.util.FreshNameCreator -import scala.reflect.internal.Flags._ import scala.reflect.internal.util.ListOfNil trait Internals extends api.Internals { diff --git a/src/reflect/scala/reflect/internal/Printers.scala b/src/reflect/scala/reflect/internal/Printers.scala index 2ce861898f..c4953b2c1f 100644 --- a/src/reflect/scala/reflect/internal/Printers.scala +++ b/src/reflect/scala/reflect/internal/Printers.scala @@ -761,7 +761,7 @@ trait Printers extends api.Printers { self: SymbolTable => val build.SyntacticClassDef(_, _, _, ctorMods, vparamss, earlyDefs, parents, selfType, body) = cl // constructor's modifier - if (ctorMods.hasFlag(AccessFlags)) { + if (ctorMods.hasFlag(AccessFlags) || ctorMods.hasAccessBoundary) { print(" ") printModifiers(ctorMods, primaryCtorParam = false) } diff --git a/src/reflect/scala/reflect/internal/ReificationSupport.scala b/src/reflect/scala/reflect/internal/ReificationSupport.scala index 759bd2e791..c418321234 100644 --- a/src/reflect/scala/reflect/internal/ReificationSupport.scala +++ b/src/reflect/scala/reflect/internal/ReificationSupport.scala @@ -7,7 +7,6 @@ import util._ trait ReificationSupport { self: SymbolTable => import definitions._ - import internal._ class ReificationSupportImpl extends ReificationSupportApi { def selectType(owner: Symbol, name: String): TypeSymbol = @@ -123,7 +122,7 @@ trait ReificationSupport { self: SymbolTable => if (vd.rhs.nonEmpty) newmods |= DEFAULTPARAM copyValDef(vd)(mods = newmods | extraFlags) case _ => - throw new IllegalArgumentException(s"$tree is not valid represenation of a parameter, " + + throw new IllegalArgumentException(s"$tree is not valid representation of a parameter, " + """consider reformatting it into q"val $name: $T = $default" shape""") } diff --git a/src/reflect/scala/reflect/internal/StdNames.scala b/src/reflect/scala/reflect/internal/StdNames.scala index 99ff6a10b4..f2517fff54 100644 --- a/src/reflect/scala/reflect/internal/StdNames.scala +++ b/src/reflect/scala/reflect/internal/StdNames.scala @@ -128,6 +128,7 @@ trait StdNames { final val AnyRef: NameType = "AnyRef" final val Array: NameType = "Array" final val List: NameType = "List" + final val Option: NameType = "Option" final val Seq: NameType = "Seq" final val Symbol: NameType = "Symbol" final val WeakTypeTag: NameType = "WeakTypeTag" diff --git a/src/reflect/scala/reflect/internal/SymbolPairs.scala b/src/reflect/scala/reflect/internal/SymbolPairs.scala index c088e8f57c..4763e77a34 100644 --- a/src/reflect/scala/reflect/internal/SymbolPairs.scala +++ b/src/reflect/scala/reflect/internal/SymbolPairs.scala @@ -8,7 +8,6 @@ package reflect package internal import scala.collection.mutable -import Flags._ import util.HashSet import scala.annotation.tailrec diff --git a/src/reflect/scala/reflect/internal/Symbols.scala b/src/reflect/scala/reflect/internal/Symbols.scala index 2c039ab5a7..51f06b1d6d 100644 --- a/src/reflect/scala/reflect/internal/Symbols.scala +++ b/src/reflect/scala/reflect/internal/Symbols.scala @@ -173,7 +173,6 @@ trait Symbols extends api.Symbols { self: SymbolTable => with HasFlags with Annotatable[Symbol] with Attachable { - // makes sure that all symbols that runtime reflection deals with are synchronized private def isSynchronized = this.isInstanceOf[scala.reflect.runtime.SynchronizedSymbols#SynchronizedSymbol] private def isAprioriThreadsafe = isThreadsafe(AllOps) @@ -1592,13 +1591,11 @@ trait Symbols extends api.Symbols { self: SymbolTable => assert(isCompilerUniverse) if (infos == null || runId(infos.validFrom) == currentRunId) { infos - } else if (isPackageClass) { - // SI-7801 early phase package scopes are mutated in new runs (Namers#enterPackage), so we have to - // discard transformed infos, rather than just marking them as from this run. - val oldest = infos.oldest - oldest.validFrom = validTo - this.infos = oldest - oldest + } else if (infos ne infos.oldest) { + // SI-8871 Discard all but the first element of type history. Specialization only works in the resident + // compiler / REPL if re-run its info transformer in this run to correctly populate its + // per-run caches, e.g. typeEnv + adaptInfos(infos.oldest) } else { val prev1 = adaptInfos(infos.prev) if (prev1 ne infos.prev) prev1 @@ -2157,6 +2154,12 @@ trait Symbols extends api.Symbols { self: SymbolTable => if (isClass) this else moduleClass } else owner.enclosingTopLevelClass + /** The top-level class or local dummy symbol containing this symbol. */ + def enclosingTopLevelClassOrDummy: Symbol = + if (isTopLevel) { + if (isClass) this else moduleClass.orElse(this) + } else owner.enclosingTopLevelClassOrDummy + /** Is this symbol defined in the same scope and compilation unit as `that` symbol? */ def isCoDefinedWith(that: Symbol) = ( !rawInfoIsNoType @@ -3505,6 +3508,7 @@ trait Symbols extends api.Symbols { self: SymbolTable => override def enclClassChain = Nil override def enclClass: Symbol = this override def enclosingTopLevelClass: Symbol = this + override def enclosingTopLevelClassOrDummy: Symbol = this override def enclosingPackageClass: Symbol = this override def enclMethod: Symbol = this override def associatedFile = NoAbstractFile diff --git a/src/reflect/scala/reflect/internal/Trees.scala b/src/reflect/scala/reflect/internal/Trees.scala index af533b21bc..35de3adff6 100644 --- a/src/reflect/scala/reflect/internal/Trees.scala +++ b/src/reflect/scala/reflect/internal/Trees.scala @@ -8,7 +8,6 @@ package reflect package internal import Flags._ -import pickling.PickleFormat._ import scala.collection.{ mutable, immutable } import scala.reflect.macros.Attachments import util.Statistics diff --git a/src/reflect/scala/reflect/internal/transform/PostErasure.scala b/src/reflect/scala/reflect/internal/transform/PostErasure.scala index f0c7d0f050..dd4f044818 100644 --- a/src/reflect/scala/reflect/internal/transform/PostErasure.scala +++ b/src/reflect/scala/reflect/internal/transform/PostErasure.scala @@ -5,7 +5,6 @@ package transform trait PostErasure { val global: SymbolTable import global._ - import definitions._ object elimErasedValueType extends TypeMap { def apply(tp: Type) = tp match { diff --git a/src/reflect/scala/reflect/macros/Parsers.scala b/src/reflect/scala/reflect/macros/Parsers.scala index 720b754649..5fc0fd5078 100644 --- a/src/reflect/scala/reflect/macros/Parsers.scala +++ b/src/reflect/scala/reflect/macros/Parsers.scala @@ -13,7 +13,7 @@ trait Parsers { /** Parses a string with a Scala expression into an abstract syntax tree. * Only works for expressions, i.e. parsing a package declaration will fail. - * @throws [[scala.reflect.macros.ParseException]] + * @throws scala.reflect.macros.ParseException */ def parse(code: String): Tree } diff --git a/src/reflect/scala/reflect/macros/Typers.scala b/src/reflect/scala/reflect/macros/Typers.scala index d0dccb469d..bd608601dc 100644 --- a/src/reflect/scala/reflect/macros/Typers.scala +++ b/src/reflect/scala/reflect/macros/Typers.scala @@ -2,8 +2,6 @@ package scala package reflect package macros -import scala.reflect.internal.{Mode => InternalMode} - /** * <span class="badge badge-red" style="float: right;">EXPERIMENTAL</span> * @@ -72,7 +70,7 @@ trait Typers { * `withImplicitViewsDisabled` recursively prohibits implicit views (though, implicit vals will still be looked up and filled in), default value is false * `withMacrosDisabled` recursively prohibits macro expansions and macro-based implicits, default value is false * - * @throws [[scala.reflect.macros.TypecheckException]] + * @throws scala.reflect.macros.TypecheckException */ def typecheck(tree: Tree, mode: TypecheckMode = TERMmode, pt: Type = universe.WildcardType, silent: Boolean = false, withImplicitViewsDisabled: Boolean = false, withMacrosDisabled: Boolean = false): Tree @@ -84,7 +82,7 @@ trait Typers { * Such errors don't vanish and can be inspected by turning on -Xlog-implicits. * Unlike in `typecheck`, `silent` is true by default. * - * @throws [[scala.reflect.macros.TypecheckException]] + * @throws scala.reflect.macros.TypecheckException */ def inferImplicitValue(pt: Type, silent: Boolean = true, withMacrosDisabled: Boolean = false, pos: Position = enclosingPosition): Tree @@ -96,7 +94,7 @@ trait Typers { * Such errors don't vanish and can be inspected by turning on -Xlog-implicits. * Unlike in `typecheck`, `silent` is true by default. * - * @throws [[scala.reflect.macros.TypecheckException]] + * @throws scala.reflect.macros.TypecheckException */ def inferImplicitView(tree: Tree, from: Type, to: Type, silent: Boolean = true, withMacrosDisabled: Boolean = false, pos: Position = enclosingPosition): Tree diff --git a/src/reflect/scala/reflect/runtime/JavaMirrors.scala b/src/reflect/scala/reflect/runtime/JavaMirrors.scala index b7f229b6e5..a0da3f3bbf 100644 --- a/src/reflect/scala/reflect/runtime/JavaMirrors.scala +++ b/src/reflect/scala/reflect/runtime/JavaMirrors.scala @@ -1191,7 +1191,7 @@ private[scala] trait JavaMirrors extends internal.SymbolTable with api.JavaUnive * - top-level classes * - Scala classes that were generated via jclassToScala * - classes that have a class owner that has a corresponding Java class - * @throws A `ClassNotFoundException` for all Scala classes not in one of these categories. + * @throws ClassNotFoundException for all Scala classes not in one of these categories. */ @throws(classOf[ClassNotFoundException]) def classToJava(clazz: ClassSymbol): jClass[_] = classCache.toJava(clazz) { diff --git a/src/reflect/scala/reflect/runtime/JavaUniverse.scala b/src/reflect/scala/reflect/runtime/JavaUniverse.scala index fe39e1f245..7848753e69 100644 --- a/src/reflect/scala/reflect/runtime/JavaUniverse.scala +++ b/src/reflect/scala/reflect/runtime/JavaUniverse.scala @@ -5,7 +5,7 @@ package runtime import scala.reflect.internal.{TreeInfo, SomePhase} import scala.reflect.internal.{SymbolTable => InternalSymbolTable} import scala.reflect.runtime.{SymbolTable => RuntimeSymbolTable} -import scala.reflect.api.{TreeCreator, TypeCreator, Universe} +import scala.reflect.api.{TypeCreator, Universe} /** An implementation of [[scala.reflect.api.Universe]] for runtime reflection using JVM classloaders. * diff --git a/src/reflect/scala/reflect/runtime/SymbolTable.scala b/src/reflect/scala/reflect/runtime/SymbolTable.scala index 02155578f8..092bbd711f 100644 --- a/src/reflect/scala/reflect/runtime/SymbolTable.scala +++ b/src/reflect/scala/reflect/runtime/SymbolTable.scala @@ -2,8 +2,6 @@ package scala package reflect package runtime -import scala.reflect.internal.Flags._ - /** * This symbol table trait fills in the definitions so that class information is obtained by refection. * It can be used either from a reflexive universe (class scala.reflect.runtime.JavaUniverse), or else from diff --git a/src/reflect/scala/reflect/runtime/SynchronizedSymbols.scala b/src/reflect/scala/reflect/runtime/SynchronizedSymbols.scala index f5e16c6640..6d0cb0df45 100644 --- a/src/reflect/scala/reflect/runtime/SynchronizedSymbols.scala +++ b/src/reflect/scala/reflect/runtime/SynchronizedSymbols.scala @@ -2,8 +2,7 @@ package scala package reflect package runtime -import scala.reflect.io.AbstractFile -import scala.collection.{ immutable, mutable } +import scala.collection.immutable import scala.reflect.internal.Flags._ private[reflect] trait SynchronizedSymbols extends internal.Symbols { self: SymbolTable => diff --git a/src/repl/scala/tools/nsc/interpreter/IMain.scala b/src/repl/scala/tools/nsc/interpreter/IMain.scala index 20b5a79aaa..3f4922a602 100644 --- a/src/repl/scala/tools/nsc/interpreter/IMain.scala +++ b/src/repl/scala/tools/nsc/interpreter/IMain.scala @@ -1190,6 +1190,8 @@ class IMain(@BeanProperty val factory: ScriptEngineFactory, initialSettings: Set finally isettings.unwrapStrings = saved } + def withoutTruncating[A](body: => A): A = reporter withoutTruncating body + def symbolDefString(sym: Symbol) = { TypeStrings.quieter( exitingTyper(sym.defString), diff --git a/src/repl/scala/tools/nsc/interpreter/JavapClass.scala b/src/repl/scala/tools/nsc/interpreter/JavapClass.scala index 3cb6ba11c1..ebca3e7e62 100644 --- a/src/repl/scala/tools/nsc/interpreter/JavapClass.scala +++ b/src/repl/scala/tools/nsc/interpreter/JavapClass.scala @@ -9,7 +9,7 @@ package interpreter import java.lang.{ ClassLoader => JavaClassLoader, Iterable => JIterable } import scala.tools.nsc.util.ScalaClassLoader -import java.io.{ ByteArrayInputStream, CharArrayWriter, FileNotFoundException, PrintWriter, Writer } +import java.io.{ ByteArrayInputStream, CharArrayWriter, FileNotFoundException, PrintWriter, StringWriter, Writer } import java.util.{ Locale } import java.util.concurrent.ConcurrentLinkedQueue import javax.tools.{ Diagnostic, DiagnosticCollector, DiagnosticListener, @@ -18,39 +18,47 @@ import javax.tools.{ Diagnostic, DiagnosticCollector, DiagnosticListener, import scala.reflect.io.{ AbstractFile, Directory, File, Path } import scala.io.Source import scala.util.{ Try, Success, Failure } -import scala.util.Properties.lineSeparator +import scala.util.Properties.{ lineSeparator => EOL } import scala.util.matching.Regex -import scala.collection.JavaConverters +import scala.collection.JavaConverters._ import scala.collection.generic.Clearable import java.net.URL import scala.language.reflectiveCalls +import PartialFunction.{ cond => when } import Javap._ +/** Javap command implementation. Supports platform tool for Java 6 or 7+. + * Adds a few options for REPL world, to show bodies of `App` classes and closures. + */ class JavapClass( val loader: ScalaClassLoader, val printWriter: PrintWriter, intp: Option[IMain] = None -) extends scala.tools.util.Javap { +) extends Javap { import JavapTool.ToolArgs import JavapClass._ lazy val tool = JavapTool() - /** Run the tool. Option args start with "-". + /** Run the tool. Option args start with "-", except that "-" itself + * denotes the last REPL result. * The default options are "-protected -verbose". * Byte data for filename args is retrieved with findBytes. + * @return results for invoking JpResult.show() */ def apply(args: Seq[String]): List[JpResult] = { val (options, classes) = args partition (s => (s startsWith "-") && s.length > 1) - val (flags, upgraded) = upgrade(options) + val (flags, upgraded) = upgrade(options) import flags.{ app, fun, help, raw } + val targets = if (fun && !help) FunFinder(loader, intp).funs(classes) else classes + if (help || classes.isEmpty) List(JpResult(JavapTool.helper(printWriter))) else if (targets.isEmpty) - List(JpResult("No anonfuns found.")) + List(JpResult("No closures found.")) else - tool(raw, upgraded)(targets map (klass => targeted(klass, app))) + tool(raw, upgraded)(targets map (targeted(_, app))) // JavapTool.apply } /** Cull our tool options. */ @@ -79,8 +87,10 @@ class JavapClass( case s => s } val targetedBytes = if (app) findAppBody(req) else (path, findBytes(req)) - if (targetedBytes._2.isEmpty) throw new FileNotFoundException(s"Could not find class bytes for '$path'") - targetedBytes + targetedBytes match { + case (_, bytes) if bytes.isEmpty => throw new FileNotFoundException(s"Could not find class bytes for '$path'") + case ok => ok + } } private def findAppBody(path: String): (String, Array[Byte]) = { @@ -89,16 +99,12 @@ class JavapClass( // assumes only the first match is of interest (because only one endpoint is generated). def findNewStyle(bytes: Array[Byte]) = { import scala.tools.asm.ClassReader - import scala.tools.asm.tree.ClassNode - import PartialFunction.cond - import JavaConverters._ - val rdr = new ClassReader(bytes) - val nod = new ClassNode - rdr.accept(nod, 0) //foo/Bar.delayedEndpoint$foo$Bar$1 val endpoint = "delayedEndpoint".r.unanchored - def isEndPoint(s: String) = (s contains '$') && cond(s) { case endpoint() => true } - nod.methods.asScala collectFirst { case m if isEndPoint(m.name) => m.name } + def isEndPoint(s: String) = (s contains '$') && when(s) { case endpoint() => true } + new ClassReader(bytes) withMethods { methods => + methods collectFirst { case m if isEndPoint(m.name) => m.name } + } } // try new style, and add foo#delayedEndpoint$bar$1 to filter on the endpoint def asNewStyle(bytes: Array[Byte]) = Some(bytes) filter (_.nonEmpty) flatMap { bs => @@ -122,8 +128,7 @@ class JavapClass( def findBytes(path: String): Array[Byte] = tryFile(path) getOrElse tryClass(path) - /** Assume the string is a path and try to find the classfile - * it represents. + /** Assume the string is a path and try to find the classfile it represents. */ def tryFile(path: String): Option[Array[Byte]] = (Try (File(path.asClassResource)) filter (_.exists) map (_.toByteArray())).toOption @@ -202,55 +207,67 @@ class JavapClass( w } + def filterLines(target: String, text: String): String = { + // take Foo# as Foo#apply for purposes of filtering. Useful for -fun Foo#; + // if apply is added here, it's for other than -fun: javap Foo#, perhaps m#? + val filterOn = target.splitHashMember._2 map { s => if (s.isEmpty) "apply" else s } + var filtering = false // true if in region matching filter + // turn filtering on/off given the pattern of interest + def filterStatus(line: String, pattern: String) = { + def isSpecialized(method: String) = (method startsWith pattern+"$") && (method endsWith "$sp") + def isAnonymized(method: String) = (pattern == "$anonfun") && (method startsWith "$anonfun$") + // cheap heuristic, todo maybe parse for the java sig. + // method sigs end in paren semi + def isAnyMethod = line endsWith ");" + // take the method name between the space char and left paren. + // accept exact match or something that looks like what we might be asking for. + def isOurMethod = { + val lparen = line lastIndexOf '(' + val blank = line.lastIndexOf(' ', lparen) + if (blank < 0) false + else { + val method = line.substring(blank+1, lparen) + (method == pattern || isSpecialized(method) || isAnonymized(method)) + } + } + filtering = + if (filtering) { + // next blank line terminates section + // in non-verbose mode, next line is next method, more or less + line.trim.nonEmpty && (!isAnyMethod || isOurMethod) + } else { + isAnyMethod && isOurMethod + } + filtering + } + // do we output this line? + def checkFilter(line: String) = filterOn map (filterStatus(line, _)) getOrElse true + val sw = new StringWriter + val pw = new PrintWriter(sw) + for { + line <- Source.fromString(text).getLines() + if checkFilter(line) + } pw println line + pw.flush() + sw.toString + } + /** Create a Showable with output massage. * @param raw show ugly repl names * @param target attempt to filter output to show region of interest * @param preamble other messages to output */ - def showWithPreamble(raw: Boolean, target: String, preamble: String = ""): Showable = new Showable { - // ReplStrippingWriter clips and scrubs on write(String) - // circumvent it by write(mw, 0, mw.length) or wrap it in withoutUnwrapping - def show() = - if (raw && intp.isDefined) intp.get withoutUnwrapping { writeLines() } - else writeLines() - private def writeLines() { - // take Foo# as Foo#apply for purposes of filtering. Useful for -fun Foo#; - // if apply is added here, it's for other than -fun: javap Foo#, perhaps m#? - val filterOn = target.splitHashMember._2 map { s => if (s.isEmpty) "apply" else s } - var filtering = false // true if in region matching filter - // turn filtering on/off given the pattern of interest - def filterStatus(line: String, pattern: String) = { - // cheap heuristic, todo maybe parse for the java sig. - // method sigs end in paren semi - def isAnyMethod = line.endsWith(");") - def isOurMethod = { - val lparen = line.lastIndexOf('(') - val blank = line.lastIndexOf(' ', lparen) - if (blank < 0) false - else { - val method = line.substring(blank+1, lparen) - (method == pattern || ((method startsWith pattern+"$") && (method endsWith "$sp"))) - } - } - filtering = - if (filtering) { - // next blank line terminates section - // for -public, next line is next method, more or less - line.trim.nonEmpty && !isAnyMethod - } else { - isAnyMethod && isOurMethod - } - filtering - } - // do we output this line? - def checkFilter(line: String) = filterOn map (filterStatus(line, _)) getOrElse true - for { - line <- Source.fromString(preamble + written).getLines() - if checkFilter(line) - } printWriter write f"$line%n" - printWriter.flush() + def showWithPreamble(raw: Boolean, target: String, preamble: String = ""): Showable = + new Showable { + private def writeLines() = filterLines(target, preamble + written) + val output = writeLines() + + // ReplStrippingWriter clips and scrubs on write(String) + // circumvent it by write(mw, 0, mw.length) or wrap it in withoutUnwrapping + def show() = + if (raw && intp.isDefined) intp.get withoutUnwrapping { printWriter.write(output, 0, output.length) } + else intp.get withoutTruncating(printWriter write output) } - } } class JavapTool6 extends JavapTool { @@ -291,6 +308,7 @@ class JavapClass( } class JavapTool7 extends JavapTool { + import JavapTool._ type Task = { def call(): Boolean // true = ok //def run(args: Array[String]): Int // all args @@ -322,19 +340,14 @@ class JavapClass( /** All diagnostic messages. * @param locale Locale for diagnostic messages, null by default. */ - def messages(implicit locale: Locale = null) = { - import JavaConverters._ - diagnostics.asScala.map(_ getMessage locale).toList - } + def messages(implicit locale: Locale = null) = diagnostics.asScala.map(_ getMessage locale).toList + // don't filter this message if raw, since the names are likely to differ + private val container = "Binary file .* contains .*".r def reportable(raw: Boolean): String = { - // don't filter this message if raw, since the names are likely to differ - val container = "Binary file .* contains .*".r - val m = if (raw) messages - else messages filter (_ match { case container() => false case _ => true }) + val m = if (raw) messages else messages filterNot (when(_) { case container() => true }) clear() - if (m.nonEmpty) m mkString ("", lineSeparator, lineSeparator) - else "" + if (m.nonEmpty) m mkString ("", EOL, EOL) else "" } } val reporter = new JavaReporter @@ -396,7 +409,6 @@ class JavapClass( def task(options: Seq[String], classes: Seq[String], inputs: Seq[Input]): Task = { //ServiceLoader.load(classOf[javax.tools.DisassemblerTool]). //getTask(writer, fileManager, reporter, options.asJava, classes.asJava) - import JavaConverters.asJavaIterableConverter TaskCtor.newInstance(writer, fileManager(inputs), reporter, options.asJava, classes.asJava) .orFailed (throw new IllegalStateException) } @@ -476,7 +488,7 @@ class JavapClass( object ToolArgs { def fromArgs(args: Seq[String]): (ToolArgs, Seq[String]) = ((ToolArgs(), Seq[String]()) /: (args flatMap massage)) { case ((t,others), s) => s match { - case "-fun" => (t copy (fun=true), others) + case "-fun" => (t copy (fun=true), others :+ "-private") case "-app" => (t copy (app=true), others) case "-help" => (t copy (help=true), others) case "-raw" => (t copy (raw=true), others) @@ -542,24 +554,26 @@ class JavapClass( val DefaultOptions = List("-protected", "-verbose") - def isAvailable = Seq(Env, Tool) exists (cn => hasClass(loader, cn)) - private def hasClass(cl: ScalaClassLoader, cn: String) = cl.tryToInitializeClass[AnyRef](cn).isDefined - private def isTaskable(cl: ScalaClassLoader) = hasClass(cl, Tool) + def isAvailable = Seq(Env, Tool) exists (hasClass(loader, _)) /** Select the tool implementation for this platform. */ - def apply() = if (isTaskable(loader)) new JavapTool7 else new JavapTool6 + def apply() = if (hasClass(loader, Tool)) new JavapTool7 else new JavapTool6 } } object JavapClass { + import scala.tools.asm.ClassReader + import scala.tools.asm.tree.{ ClassNode, MethodNode } + def apply( loader: ScalaClassLoader = ScalaClassLoader.appLoader, printWriter: PrintWriter = new PrintWriter(System.out, true), intp: Option[IMain] = None ) = new JavapClass(loader, printWriter, intp) + /** Match foo#bar, both groups are optional (may be null). */ val HashSplit = "([^#]+)?(?:#(.+)?)?".r // We enjoy flexibility in specifying either a fully-qualified class name com.acme.Widget @@ -580,9 +594,9 @@ object JavapClass { else (s take i, Some(s drop i+1)) } } - implicit class ClassLoaderOps(val cl: ClassLoader) extends AnyVal { + implicit class ClassLoaderOps(val loader: ScalaClassLoader) extends AnyVal { private def parentsOf(x: ClassLoader): List[ClassLoader] = if (x == null) Nil else x :: parentsOf(x.getParent) - def parents: List[ClassLoader] = parentsOf(cl) + def parents: List[ClassLoader] = parentsOf(loader) /* all file locations */ def locations = { def alldirs = parents flatMap (_ match { @@ -596,7 +610,7 @@ object JavapClass { /* only the file location from which the given class is loaded */ def locate(k: String): Option[Path] = { Try { - val klass = try cl loadClass k catch { + val klass = try loader loadClass k catch { case _: NoClassDefFoundError => null // let it snow } // cf ScalaClassLoader.originOfClass @@ -608,44 +622,66 @@ object JavapClass { } } /* would classBytes succeed with a nonempty array */ - def resourceable(className: String): Boolean = cl.getResource(className.asClassResource) != null + def resourceable(className: String): Boolean = loader.getResource(className.asClassResource) != null + + /* class reader of class bytes */ + def classReader(resource: String): ClassReader = new ClassReader(loader classBytes resource) + } + implicit class `class reader convenience`(val reader: ClassReader) extends AnyVal { + def withMethods[A](f: Seq[MethodNode] => A): A = { + val cls = new ClassNode + reader.accept(cls, 0) + f(cls.methods.asScala) + } } implicit class PathOps(val p: Path) extends AnyVal { import scala.tools.nsc.io.Jar def isJar = Jar isJarOrZip p } + implicit class `fun with files`(val f: AbstractFile) extends AnyVal { + def descend(path: Seq[String]): Option[AbstractFile] = { + def lookup(f: AbstractFile, path: Seq[String]): Option[AbstractFile] = path match { + case p if p.isEmpty => Option(f) + case p => Option(f.lookupName(p.head, directory = true)) flatMap (lookup(_, p.tail)) + } + lookup(f, path) + } + } implicit class URLOps(val url: URL) extends AnyVal { def isFile: Boolean = url.getProtocol == "file" } object FunFinder { def apply(loader: ScalaClassLoader, intp: Option[IMain]) = new FunFinder(loader, intp) } + // FunFinder.funs(ks) finds anonfuns class FunFinder(loader: ScalaClassLoader, intp: Option[IMain]) { + // manglese for closure: typename, $anonfun or lamba, opt method, digits + val closure = """(.*)\$(\$anonfun|lambda)(?:\$+([^$]+))?\$(\d+)""".r + + // manglese for closure + val cleese = "(?:anonfun|lambda)" + // class k, candidate f without prefix - def isFunOfClass(k: String, f: String) = { - val p = (s"${Regex quote k}\\$$+anonfun").r - (p findPrefixOf f).nonEmpty - } + def isFunOfClass(k: String, f: String) = (s"${Regex quote k}\\$$+$cleese".r findPrefixOf f).nonEmpty + // class k, candidate f without prefix, method m - def isFunOfMethod(k: String, m: String, f: String) = { - val p = (s"${Regex quote k}\\$$+anonfun\\$$${Regex quote m}\\$$").r - (p findPrefixOf f).nonEmpty - } - def isFunOfTarget(k: String, m: Option[String], f: String) = - if (m.isEmpty) isFunOfClass(k, f) - else isFunOfMethod(k, m.get, f) - def listFunsInAbsFile(k: String, m: Option[String], d: AbstractFile) = { - for (f <- d; if !f.isDirectory && isFunOfTarget(k, m, f.name)) yield f.name - } - // path prefix p, class k, dir d - def listFunsInDir(p: String, k: String, m: Option[String])(d: Directory) = { - val subdir = Path(p) - for (f <- (d / subdir).toDirectory.list; if f.isFile && isFunOfTarget(k, m, f.name)) + def isFunOfMethod(k: String, m: String, f: String) = + (s"${Regex quote k}\\$$+$cleese\\$$+${Regex quote m}\\$$".r findPrefixOf f).nonEmpty + + def isFunOfTarget(target: Target, f: String) = + target.member map (isFunOfMethod(target.name, _, f)) getOrElse isFunOfClass(target.name, f) + + def listFunsInAbsFile(target: Target)(d: AbstractFile) = + for (f <- d; if !f.isDirectory && isFunOfTarget(target, f.name)) yield f.name + + def listFunsInDir(target: Target)(d: Directory) = { + val subdir = Path(target.prefix) + for (f <- (d / subdir).toDirectory.list; if f.isFile && isFunOfTarget(target, f.name)) yield f.name } - // path prefix p, class k, jar file f - def listFunsInJar(p: String, k: String, m: Option[String])(f: File) = { + + def listFunsInJar(target: Target)(f: File) = { import java.util.jar.JarEntry import scala.tools.nsc.io.Jar def maybe(e: JarEntry) = { @@ -654,78 +690,133 @@ object JavapClass { if (parts.length < 2) ("", e.getName) else (parts.init mkString "/", parts.last) } - if (path == p && isFunOfTarget(k, m, name)) Some(name) else None + if (path == target.prefix && isFunOfTarget(target, name)) Some(name) else None } (new Jar(f) map maybe).flatten } def loadable(name: String) = loader resourceable name - // translated class, optional member, opt member to filter on, whether it is repl output - def translate(s: String): (String, Option[String], Option[String], Boolean) = { + case class Target(path: String, member: Option[String], filter: Option[String], isRepl: Boolean, isModule: Boolean) { + val splat = path split "\\." + val name = splat.last + val prefix = if (splat.length > 1) splat.init mkString "/" else "" + val pkg = if (splat.length > 1) splat.init mkString "." else "" + val targetName = s"$name${ if (isModule) "$" else "" }" + } + // translated class, optional member, opt member to filter on, whether it is repl output and a module + def translate(s: String): Target = { val (k0, m0) = s.splitHashMember - val k = k0.asClassName + val isModule = k0 endsWith "$" + val k = (k0 stripSuffix "$").asClassName val member = m0 filter (_.nonEmpty) // take Foo# as no member, not "" val filter = m0 flatMap { case "" => Some("apply") case _ => None } // take Foo# as filter on apply // class is either something replish or available to loader // $line.$read$$etc$Foo#member - ((intp flatMap (_ translatePath k) filter (loadable) map ((_, member, filter, true))) + ((intp flatMap (_ translatePath k) filter (loadable) map (x => Target(x stripSuffix "$", member, filter, true, isModule))) // s = "f" and $line.$read$$etc$#f is what we're after, // ignoring any #member (except take # as filter on #apply) - orElse (intp flatMap (_ translateEnclosingClass k) map ((_, Some(k), filter, true))) - getOrElse ((k, member, filter, false))) + orElse (intp flatMap (_ translateEnclosingClass k) map (x => Target(x stripSuffix "$", Some(k), filter, true, isModule))) + getOrElse (Target(k, member, filter, false, isModule))) } /** Find the classnames of anonfuns associated with k, * where k may be an available class or a symbol in scope. */ - def funsOf(k0: String): Seq[String] = { + def funsOf(selection: String): Seq[String] = { // class is either something replish or available to loader - val (k, member, filter, isReplish) = translate(k0) - val splat = k split "\\." - val name = splat.last - val prefix = if (splat.length > 1) splat.init mkString "/" else "" - val pkg = if (splat.length > 1) splat.init mkString "." else "" + val target = translate(selection) + // reconstitute an anonfun with a package // if filtered, add the hash back, e.g. pkg.Foo#bar, pkg.Foo$anon$1#apply def packaged(s: String) = { - val p = if (pkg.isEmpty) s else s"$pkg.$s" - val pm = filter map (p + "#" + _) - pm getOrElse p + val p = if (target.pkg.isEmpty) s else s"${target.pkg}.$s" + target.filter map (p + "#" + _) getOrElse p } - // is this translated path in (usually virtual) repl outdir? or loadable from filesystem? - val fs = if (isReplish) { - def outed(d: AbstractFile, p: Seq[String]): Option[AbstractFile] = { - if (p.isEmpty) Option(d) - else Option(d.lookupName(p.head, directory = true)) flatMap (f => outed(f, p.tail)) - } - outed(intp.get.replOutput.dir, splat.init) map { d => - listFunsInAbsFile(name, member, d) map packaged - } - } else { - loader locate k map { w => - if (w.isDirectory) listFunsInDir(prefix, name, member)(w.toDirectory) map packaged - else if (w.isJar) listFunsInJar(prefix, name, member)(w.toFile) map packaged - else Nil + // find closure classes in repl outdir or try asking the classloader where to look + val fs = + if (target.isRepl) + (intp.get.replOutput.dir descend target.splat.init) map { d => + listFunsInAbsFile(target)(d) map (_.asClassName) map packaged + } + else + loader locate target.path map { + case d if d.isDirectory => listFunsInDir(target)(d.toDirectory) map packaged + case j if j.isJar => listFunsInJar(target)(j.toFile) map packaged + case _ => Nil + } + val res = fs map (_.to[Seq]) getOrElse Seq() + // on second thought, we don't care about lamba method classes, just the impl methods + val rev = + res flatMap { + case x @ closure(_, "lambda", _, _) => labdaMethod(x, target) + //target.member flatMap (_ => labdaMethod(x, target)) getOrElse s"${target.name}#$$anonfun" + case x => Some(x) + } + rev + } + // given C$lambda$$g$n for member g and n in 1..N, find the C.accessor$x + // and the C.$anonfun$x it forwards to. + def labdaMethod(lambda: String, target: Target): Option[String] = { + import scala.tools.asm.ClassReader + import scala.tools.asm.Opcodes.INVOKESTATIC + import scala.tools.asm.tree.{ ClassNode, MethodInsnNode } + // the accessor methods invoked statically by the apply of the given closure class + def accesses(s: String): Seq[(String, String)] = { + val accessor = """accessor\$\d+""".r + loader classReader s withMethods { ms => + ms filter (_.name == "apply") flatMap (_.instructions.toArray.collect { + case i: MethodInsnNode if i.getOpcode == INVOKESTATIC && when(i.name) { case accessor(_*) => true } => (i.owner, i.name) + }) } } - fs match { - case Some(xs) => xs.to[Seq] // maybe empty - case None => Seq() // nothing found, e.g., junk input + // get the k.$anonfun for the accessor k.m + def anonOf(k: String, m: String): String = { + val res = + loader classReader k withMethods { ms => + ms filter (_.name == m) flatMap (_.instructions.toArray.collect { + case i: MethodInsnNode if i.getOpcode == INVOKESTATIC && i.name.startsWith("$anonfun") => i.name + }) + } + assert(res.size == 1) + res.head + } + // the lambdas invoke accessors that call the anonfuns of interest. Filter k on the k#$anonfuns. + val ack = accesses(lambda) + assert(ack.size == 1) // There can be only one. + ack.head match { + case (k, _) if target.isModule && !(k endsWith "$") => None + case (k, m) => Some(s"${k}#${anonOf(k, m)}") } } - def funs(ks: Seq[String]) = ks flatMap funsOf _ + /** Translate the supplied targets to patterns for anonfuns. + * Pattern is typename $ label [[$]$func] $n where label is $anonfun or lamba, + * and lambda includes the extra dollar, func is a method name, and n is an int. + * The typename for a nested class is dollar notation, Betty$Bippy. + * + * If C has anonfun closure classes, then use C$$anonfun$f$1 (various names, C# filters on apply). + * If C has lambda closure classes, then use C#$anonfun (special-cased by output filter). + */ + def funs(ks: Seq[String]): Seq[String] = ks flatMap funsOf } } +trait Javap { + def loader: ScalaClassLoader + def printWriter: PrintWriter + def apply(args: Seq[String]): List[Javap.JpResult] + def tryFile(path: String): Option[Array[Byte]] + def tryClass(path: String): Array[Byte] +} + object Javap { def isAvailable(cl: ScalaClassLoader = ScalaClassLoader.appLoader) = JavapClass(cl).JavapTool.isAvailable def apply(path: String): Unit = apply(Seq(path)) def apply(args: Seq[String]): Unit = JavapClass() apply args foreach (_.show()) - trait Showable { + private[interpreter] trait Showable { def show(): Unit } - sealed trait JpResult extends scala.tools.util.JpResult { + sealed trait JpResult { type ResultType def isError: Boolean def value: ResultType @@ -751,8 +842,13 @@ object Javap { def isError = false def show() = value.show() // output to tool's PrintWriter } - implicit class Lastly[A](val t: Try[A]) extends AnyVal { - private def effect[X](last: =>Unit)(a: X): Try[A] = { last; t } - def lastly(last: =>Unit): Try[A] = t transform (effect(last) _, effect(last) _) - } +} + +object NoJavap extends Javap { + import Javap._ + def loader: ScalaClassLoader = getClass.getClassLoader + def printWriter: PrintWriter = new PrintWriter(System.err, true) + def apply(args: Seq[String]): List[JpResult] = Nil + def tryFile(path: String): Option[Array[Byte]] = None + def tryClass(path: String): Array[Byte] = Array() } diff --git a/src/repl/scala/tools/nsc/interpreter/package.scala b/src/repl/scala/tools/nsc/interpreter/package.scala index 079097d7a2..56f1e65376 100644 --- a/src/repl/scala/tools/nsc/interpreter/package.scala +++ b/src/repl/scala/tools/nsc/interpreter/package.scala @@ -11,6 +11,7 @@ import scala.reflect.runtime.{ universe => ru } import scala.reflect.{ClassTag, classTag} import scala.reflect.api.{Mirror, TypeCreator, Universe => ApiUniverse} import scala.util.control.Exception.catching +import scala.util.Try /** The main REPL related classes and values are as follows. * In addition to standard compiler classes Global and Settings, there are: @@ -196,4 +197,14 @@ package object interpreter extends ReplConfig with ReplStrings { } } } + + /* debug assist + private[nsc] implicit class `smart stringifier`(val sc: StringContext) extends AnyVal { + import StringContext._, runtime.ScalaRunTime.stringOf + def ss(args: Any*): String = sc.standardInterpolator(treatEscapes, args map stringOf) + } debug assist */ + private[nsc] implicit class `try lastly`[A](val t: Try[A]) extends AnyVal { + private def effect[X](last: =>Unit)(a: X): Try[A] = { last; t } + def lastly(last: =>Unit): Try[A] = t transform (effect(last) _, effect(last) _) + } } diff --git a/src/scaladoc/scala/tools/nsc/doc/base/CommentFactoryBase.scala b/src/scaladoc/scala/tools/nsc/doc/base/CommentFactoryBase.scala index 7cd8fa8e51..d31b877262 100755 --- a/src/scaladoc/scala/tools/nsc/doc/base/CommentFactoryBase.scala +++ b/src/scaladoc/scala/tools/nsc/doc/base/CommentFactoryBase.scala @@ -345,12 +345,28 @@ trait CommentFactoryBase { this: MemberLookupBase => Map.empty[String, Body] ++ pairs } + def linkedExceptions: Map[String, Body] = { + val m = allSymsOneTag(SimpleTagKey("throws")) + + m.map { case (name,body) => + val link = memberLookup(pos, name, site) + val newBody = body match { + case Body(List(Paragraph(Chain(content)))) => + val descr = Text(" ") +: content + val entityLink = EntityLink(Monospace(Text(name)), link) + Body(List(Paragraph(Chain(entityLink +: descr)))) + case _ => body + } + (name, newBody) + } + } + val com = createComment ( body0 = Some(parseWikiAtSymbol(docBody.toString, pos, site)), authors0 = allTags(SimpleTagKey("author")), see0 = allTags(SimpleTagKey("see")), result0 = oneTag(SimpleTagKey("return")), - throws0 = allSymsOneTag(SimpleTagKey("throws")), + throws0 = linkedExceptions, valueParams0 = allSymsOneTag(SimpleTagKey("param")), typeParams0 = allSymsOneTag(SimpleTagKey("tparam")), version0 = oneTag(SimpleTagKey("version")), diff --git a/src/scaladoc/scala/tools/nsc/doc/html/page/Template.scala b/src/scaladoc/scala/tools/nsc/doc/html/page/Template.scala index b5a8d1ac36..f3df2b0bb4 100644 --- a/src/scaladoc/scala/tools/nsc/doc/html/page/Template.scala +++ b/src/scaladoc/scala/tools/nsc/doc/html/page/Template.scala @@ -605,7 +605,7 @@ class Template(universe: doc.Universe, generator: DiagramGenerator, tpl: DocTemp <dd>{ val exceptionsXml: List[NodeSeq] = for((name, body) <- comment.throws.toList.sortBy(_._1) ) yield - <span class="cmt">{Text(name) ++ bodyToHtml(body)}</span> + <span class="cmt">{bodyToHtml(body)}</span> exceptionsXml.reduceLeft(_ ++ Text("") ++ _) }</dd> } diff --git a/src/scaladoc/scala/tools/partest/ScaladocModelTest.scala b/src/scaladoc/scala/tools/partest/ScaladocModelTest.scala index 70423cc7dc..fa3e8ff5cb 100644 --- a/src/scaladoc/scala/tools/partest/ScaladocModelTest.scala +++ b/src/scaladoc/scala/tools/partest/ScaladocModelTest.scala @@ -182,14 +182,16 @@ abstract class ScaladocModelTest extends DirectTest { } } - def countLinks(c: Comment, p: EntityLink => Boolean) = { - def countLinks(body: Any): Int = body match { + def countLinks(c: Comment, p: EntityLink => Boolean): Int = countLinksInBody(c.body, p) + + def countLinksInBody(body: Body, p: EntityLink => Boolean): Int = { + def countLinks(b: Any): Int = b match { case el: EntityLink if p(el) => 1 case s: Seq[_] => s.toList.map(countLinks(_)).sum case p: Product => p.productIterator.toList.map(countLinks(_)).sum case _ => 0 } - countLinks(c.body) + countLinks(body) } def testDiagram(doc: DocTemplateEntity, diag: Option[Diagram], nodes: Int, edges: Int) = { diff --git a/test/files/neg/t5091.check b/test/files/neg/t5091.check new file mode 100644 index 0000000000..abd24e3145 --- /dev/null +++ b/test/files/neg/t5091.check @@ -0,0 +1,9 @@ +t5091.scala:8: error: recursive value xxx needs type + val param = bar(xxx) + ^ +t5091.scala:7: warning: type-checking the invocation of method foo checks if the named argument expression 'param = ...' is a valid assignment +in the current scope. The resulting type inference error (see above) can be fixed by providing an explicit type in the local definition for param. + val xxx = foo(param = null) + ^ +one warning found +one error found diff --git a/test/pending/pos/t5091.scala b/test/files/neg/t5091.scala index 217e83f66d..217e83f66d 100644 --- a/test/pending/pos/t5091.scala +++ b/test/files/neg/t5091.scala diff --git a/test/files/neg/t7636.check b/test/files/neg/t7636.check index f70d50bee3..12391cccc8 100644 --- a/test/files/neg/t7636.check +++ b/test/files/neg/t7636.check @@ -4,7 +4,7 @@ t7636.scala:3: error: illegal inheritance; ^ t7636.scala:3: error: type mismatch; found : Either[_$2,_$3(in constructor C)] where type _$3(in constructor C), type _$2 - required: Either[_, _$3(in object Main)] where type _$3(in object Main) + required: Either[_, _$3(in value <local Main>)] where type _$3(in value <local Main>) class C extends ResultTable(Left(5):Either[_,_])(5) ^ two errors found diff --git a/test/files/pos/t3439.scala b/test/files/pos/t3439.scala new file mode 100644 index 0000000000..ccc75cc4cf --- /dev/null +++ b/test/files/pos/t3439.scala @@ -0,0 +1,26 @@ +class Base[M](i: Int) + +// was "implicit modifier not allowed on top level objects" +class D1()(implicit i: Int) extends Base({println(i); 0}) + +// what "no implicit value of type Int found" +class D2()(implicit i: Int) extends Base(implicitly[Int]) + + +abstract class ParametricMessage[M: Manifest](msg: M) { def message = msg } +case class ParametricMessage1[M: Manifest](msg: M, p1: Class[_]) extends ParametricMessage(msg) + + +class Wrap { + class Base[M](i: Int) + + // was "implicit modifier not allowed on top level objects" + class D1()(implicit i: Int) extends Base({println(i); 0}) + + // what "no implicit value of type Int found" + class D2()(implicit i: Int) extends Base(implicitly[Int]) + + + abstract class ParametricMessage[M: Manifest](msg: M) { def message = msg } + case class ParametricMessage1[M: Manifest](msg: M, p1: Class[_]) extends ParametricMessage(msg) +} diff --git a/test/files/pos/t5217.scala b/test/files/pos/t5217.scala new file mode 100644 index 0000000000..1fe3f5696f --- /dev/null +++ b/test/files/pos/t5217.scala @@ -0,0 +1,17 @@ +// private types and terms of companion module are +// available in scope of ctor params. +// before 2.10.1, class B in object A cannot be accessed in object A +object A { + private class B + private val b: B = new B + private type C = Int + def apply(): A = new A() +} +// if not private, then default arg results in: +// private class B escapes its defining scope as part of type A.B +class A private (b: A.B = A.b, c: A.C = 42) + +object C { + private class B +} +class C(b: C.B) diff --git a/test/files/pos/t5454.scala b/test/files/pos/t5454.scala new file mode 100644 index 0000000000..4045f3b57b --- /dev/null +++ b/test/files/pos/t5454.scala @@ -0,0 +1,10 @@ +object IllegalInheritance { + trait A + implicit def a = new A {} // def => val + //val r = implicitly[A] // uncomment + + class B[T](t : T)(implicit a : A) // remove implicit param block + + class C extends B/*[Int]*/(23) // uncomment + val c = new C // comment +} diff --git a/test/files/pos/t6051.scala b/test/files/pos/t6051.scala new file mode 100644 index 0000000000..854524feb9 --- /dev/null +++ b/test/files/pos/t6051.scala @@ -0,0 +1,19 @@ +object Foo1 { + def foo(x: Int, y: Int = 10) = x*y + lazy val y = foo(x = 20) +} + +object Foo2 { + def foo(x: Int, y: Int = 10) = x*y + val y = foo(x = 20) +} + +object Foo3 { + def foo(x: Int, y: Int = 10) = x*y + def y = foo(x = 20) +} + +object Foo4 { + def foo(x: Int, y: Int = 10) = x*y + var y = foo(x = 20) +} diff --git a/test/files/pos/t8893.scala b/test/files/pos/t8893.scala new file mode 100644 index 0000000000..b87c8bdd3c --- /dev/null +++ b/test/files/pos/t8893.scala @@ -0,0 +1,129 @@ +// Took > 10 minutes to run the tail call phase. +object Test { + def a(): Option[String] = Some("a") + + def main(args: Array[String]) { + a() match { + case Some(b1) => + a() match { + case Some(b2) => + a() match { + case Some(b3) => + a() match { + case Some(b4) => + a() match { + case Some(b5) => + a() match { + case Some(b6) => + a() match { + case Some(b7) => + a() match { + case Some(b8) => + a() match { + case Some(b9) => + a() match { + case Some(b10) => + a() match { + case Some(b11) => + a() match { + case Some(b12) => + a() match { + case Some(b13) => + a() match { + case Some(b14) => + a() match { + case Some(b15) => + a() match { + case Some(b16) => + a() match { + case Some(b17) => + a() match { + case Some(b18) => + a() match { + case Some(b19) => + a() match { + case Some(b20) => + a() match { + case Some(b21) => + a() match { + case Some(b22) => + a() match { + case Some(b23) => + a() match { + case Some(b24) => + a() match { + case Some(b25) => + a() match { + case Some(b26) => + a() match { + case Some(b27) => + a() match { + case Some(b28) => + a() match { + case Some(b29) => + a() match { + case Some(b30) => + println("yay") + case None => None + } + case None => None + } + case None => None + } + case None => None + } + case None => None + } + case None => None + } + case None => None + } + case None => None + } + case None => None + } + case None => None + } + case None => None + } + case None => None + } + case None => None + } + case None => None + } + case None => None + } + case None => None + } + case None => None + } + case None => None + } + case None => None + } + case None => None + } + case None => None + } + case None => None + } + case None => None + } + case None => None + } + case None => None + } + case None => None + } + case None => None + } + case None => None + } + case None => None + } + case None => None + } + } +} + diff --git a/test/files/pos/t8934a/A_1.scala b/test/files/pos/t8934a/A_1.scala new file mode 100644 index 0000000000..6c1f29d030 --- /dev/null +++ b/test/files/pos/t8934a/A_1.scala @@ -0,0 +1,18 @@ +import language.experimental.macros +import reflect.macros.whitebox.Context + +object Unapply { + def impl1(c: Context)(a: c.Tree): c.Tree = { + import c.universe._ + q"(new { def unapply[T](a: String): Option[(Int, String)] = ??? }).unapply($a)" + } + def unapply(a: Any): Any = macro impl1 +} + +object UnapplySeq { + def impl1(c: Context)(a: c.Tree): c.Tree = { + import c.universe._ + q"(new { def unapplySeq[T](a: String): Option[(Int, Seq[String])] = ??? }).unapplySeq($a)" + } + def unapplySeq(a: Any): Any = macro impl1 +} diff --git a/test/files/pos/t8934a/Test_2.flags b/test/files/pos/t8934a/Test_2.flags new file mode 100644 index 0000000000..618dfe2b75 --- /dev/null +++ b/test/files/pos/t8934a/Test_2.flags @@ -0,0 +1 @@ +-Ystop-after:typer -Ymacro-expand:discard -nowarn diff --git a/test/files/pos/t8934a/Test_2.scala b/test/files/pos/t8934a/Test_2.scala new file mode 100644 index 0000000000..e1792ed3c5 --- /dev/null +++ b/test/files/pos/t8934a/Test_2.scala @@ -0,0 +1,12 @@ +object Test { + "" match { + case Unapply(a, b) => + a: Int + b: String + case UnapplySeq(a, b1, b2) => + a: Int + b1: String + b2: String + } +} +// These used to fail `too many patterns` under -Ymacro-expand:discard diff --git a/test/files/pos/t8962.scala b/test/files/pos/t8962.scala new file mode 100644 index 0000000000..4331c154ba --- /dev/null +++ b/test/files/pos/t8962.scala @@ -0,0 +1,31 @@ +package test.nestedcov + +sealed abstract class Outer[+A] +case class Let[+A](expr: Outer[Inner[A]]) extends Outer[A] + +sealed abstract class Inner[+A] + +sealed abstract class Outer2[+A, +B] +case class Let2[+A](expr: Outer2[Inner2[A], A]) extends Outer2[A, A] + +sealed abstract class Inner2[+A] + +sealed abstract class Outer3[+A, +B] +case class Let3[+A](expr: Outer3[A, A]) extends Outer3[A, A] + +object NestedCov { + def run[A](nc: Outer[A]) = nc match { + case Let(expr) => + expr : Outer[Inner[A]] + } + + def run2[A](nc: Outer2[A, A]) = nc match { + case Let2(expr) => + expr : Outer2[Inner2[A], A] + } + + def run3[A](nc: Outer3[A, A]) = nc match { + case Let3(expr) => + expr : Outer3[A, A] + } +} diff --git a/test/files/presentation/private-case-class-members.check b/test/files/presentation/private-case-class-members.check new file mode 100644 index 0000000000..678f9a34e6 --- /dev/null +++ b/test/files/presentation/private-case-class-members.check @@ -0,0 +1 @@ +Test OK diff --git a/test/files/presentation/private-case-class-members/Test.scala b/test/files/presentation/private-case-class-members/Test.scala new file mode 100644 index 0000000000..e64c8238ea --- /dev/null +++ b/test/files/presentation/private-case-class-members/Test.scala @@ -0,0 +1,34 @@ +import scala.tools.nsc.interactive.tests.InteractiveTest +import scala.reflect.internal.util.SourceFile +import scala.tools.nsc.interactive.Response + +object Test extends InteractiveTest { + override def execute(): Unit = { + val source = loadSourceAndWaitUntilTypechecked("State.scala") + checkErrors(source) + } + + private def loadSourceAndWaitUntilTypechecked(sourceName: String): SourceFile = { + val sourceFile = sourceFiles.find(_.file.name == sourceName).head + compiler.askToDoFirst(sourceFile) + val res = new Response[Unit] + compiler.askReload(List(sourceFile), res) + res.get + askLoadedTyped(sourceFile).get + // the second round of type-checking makes it fail + compiler.askReload(List(sourceFile), res) + res.get + askLoadedTyped(sourceFile).get + + sourceFile + } + + private def checkErrors(source: SourceFile): Unit = compiler.getUnitOf(source) match { + case Some(unit) => + val problems = unit.problems.toList + if(problems.isEmpty) reporter.println("Test OK") + else problems.foreach(problem => reporter.println(problem.msg)) + + case None => reporter.println("No compilation unit found for " + source.file.name) + } +} diff --git a/test/files/presentation/private-case-class-members/src/State.scala b/test/files/presentation/private-case-class-members/src/State.scala new file mode 100644 index 0000000000..c31817076c --- /dev/null +++ b/test/files/presentation/private-case-class-members/src/State.scala @@ -0,0 +1,5 @@ +object State +case class State(private val foo: Int) + +case class State2(private val foo: Int) +object State2 diff --git a/test/files/presentation/quasiquotes.flags b/test/files/presentation/quasiquotes.flags new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/test/files/presentation/quasiquotes.flags diff --git a/test/files/presentation/t8934.check b/test/files/presentation/t8934.check new file mode 100644 index 0000000000..0ece87f808 --- /dev/null +++ b/test/files/presentation/t8934.check @@ -0,0 +1,2 @@ +reload: Source.scala +Test OK diff --git a/test/files/presentation/t8934/Runner.scala b/test/files/presentation/t8934/Runner.scala new file mode 100644 index 0000000000..944f458391 --- /dev/null +++ b/test/files/presentation/t8934/Runner.scala @@ -0,0 +1,27 @@ +import scala.tools.nsc.interactive.tests.InteractiveTest +import scala.reflect.internal.util.SourceFile +import scala.tools.nsc.interactive.Response + +object Test extends InteractiveTest { + + override def execute(): Unit = { + val src = loadSourceAndWaitUntilTypechecked("Source.scala") + checkErrors(src) + } + + private def loadSourceAndWaitUntilTypechecked(sourceName: String): SourceFile = { + val sourceFile = sourceFiles.find(_.file.name == sourceName).head + askReload(List(sourceFile)).get + askLoadedTyped(sourceFile).get + sourceFile + } + + private def checkErrors(source: SourceFile): Unit = compiler.getUnitOf(source) match { + case Some(unit) => + val problems = unit.problems.toList + if(problems.isEmpty) reporter.println("Test OK") + else problems.foreach(problem => reporter.println(problem.msg)) + + case None => reporter.println("No compilation unit found for " + source.file.name) + } +} diff --git a/test/files/presentation/t8934/src/Source.scala b/test/files/presentation/t8934/src/Source.scala new file mode 100644 index 0000000000..769c8fd38b --- /dev/null +++ b/test/files/presentation/t8934/src/Source.scala @@ -0,0 +1,10 @@ +class Quasi { + import reflect.runtime.universe._ + + def test: Unit = { + (null: Any) match { + case q"$foo($bar)" => + } + () + } +} diff --git a/test/files/presentation/t8941.check b/test/files/presentation/t8941.check new file mode 100644 index 0000000000..341804903a --- /dev/null +++ b/test/files/presentation/t8941.check @@ -0,0 +1,7 @@ +reload: Source.scala + +askType at Source.scala(6,7) +================================================================================ +[response] askTypeAt (6,7) +scala.this.Predef.??? +================================================================================ diff --git a/test/files/presentation/t8941/Runner.scala b/test/files/presentation/t8941/Runner.scala new file mode 100644 index 0000000000..0a8923a583 --- /dev/null +++ b/test/files/presentation/t8941/Runner.scala @@ -0,0 +1,11 @@ +import scala.tools.nsc.interactive.tests.InteractiveTest + +object Test extends InteractiveTest { + override def runDefaultTests() { + // make sure typer is done.. the virtual pattern matcher might translate + // some trees and mess up positions. But we'll catch it red handed! + // sourceFiles foreach (src => askLoadedTyped(src).get) + super.runDefaultTests() + } + +} diff --git a/test/files/presentation/t8941/src/Source.scala b/test/files/presentation/t8941/src/Source.scala new file mode 100644 index 0000000000..7438cccb03 --- /dev/null +++ b/test/files/presentation/t8941/src/Source.scala @@ -0,0 +1,8 @@ +object Foo { + implicit class MatCreator(val ctx: StringContext) extends AnyVal { + def m(args: Any*): Unit = { + ctx.checkLengths(args) + } + ???/*?*/ + } +} diff --git a/test/files/presentation/t8941b/IdempotencyTest.scala b/test/files/presentation/t8941b/IdempotencyTest.scala new file mode 100644 index 0000000000..af01b36898 --- /dev/null +++ b/test/files/presentation/t8941b/IdempotencyTest.scala @@ -0,0 +1,73 @@ +package scala.tools.nsc +package interactive +package tests.core + +import reporters.{Reporter => CompilerReporter} +import scala.tools.nsc.interactive.InteractiveReporter +import scala.reflect.internal.util.SourceFile + +/** Determistically interrupts typechecking of `code` when a defintion named + * `MagicInterruptionMarker` is typechecked, and then performs a targetted + * typecheck of the tree at the specal comment marker marker + */ +abstract class IdempotencyTest { self => + private val settings = new Settings + settings.usejavacp.value = true + + private object Break extends scala.util.control.ControlThrowable + + private val compilerReporter: CompilerReporter = new InteractiveReporter { + override def compiler = self.compiler + } + + object compiler extends Global(settings, compilerReporter) { + override def checkForMoreWork(pos: Position) { + } + override def signalDone(context: Context, old: Tree, result: Tree) { + // println("signalDone: " + old.toString.take(50).replaceAll("\n", "\\n")) + if (!interrupted && analyzer.lockedCount == 0 && interruptsEnabled && shouldInterrupt(result)) { + interrupted = true + val typed = typedTreeAt(markerPosition) + checkTypedTree(typed) + throw Break + } + super.signalDone(context, old, result) + } + + // we're driving manually using our own thread, disable the check here. + override def assertCorrectThread() {} + } + + import compiler._ + + private var interrupted = false + + // Extension points + protected def code: String + protected def shouldInterrupt(tree: Tree): Boolean = { + tree.symbol != null && tree.symbol.name.toString == "MagicInterruptionMarker" + } + protected def checkTypedTree(tree: Tree): Unit = {} + + + private val source: SourceFile = newSourceFile(code) + private def markerPosition: Position = source.position(code.indexOf("/*?*/")) + + def assertNoProblems() { + val problems = getUnit(source).get.problems + assert(problems.isEmpty, problems.mkString("\n")) + } + + def show() { + reloadSource(source) + try { + typedTree(source, true) + assert(false, "Expected to break out of typechecking.") + } catch { + case Break => // expected + } + assertNoProblems() + } + + def main(args: Array[String]) { show() } +} diff --git a/test/files/presentation/t8941b/Test.scala b/test/files/presentation/t8941b/Test.scala new file mode 100644 index 0000000000..7269a14286 --- /dev/null +++ b/test/files/presentation/t8941b/Test.scala @@ -0,0 +1,53 @@ +import scala.tools.nsc.interactive.tests.core.IdempotencyTest + +// At the time of writing this test, removing any part of `enterExistingSym` +// leads to a failure. +object Test { + def main(args: Array[String]) { + test(""" + object Foo { + def term { + def foo(c: String = "") = c + class MagicInterruptionMarker + foo()/*?*/ + } + } + """) + + test(""" + object Foo { + def term { + def foo = 42 + class MagicInterruptionMarker + foo/*?*/ + } + } + """) + + test(""" + object Foo { + def term { + lazy val foo = 42 + class MagicInterruptionMarker + foo/*?*/ + } + } + """) + + test(""" + object Foo { + implicit class C(val a: String) extends AnyVal + class MagicInterruptionMarker + ""/*?*/ + } + """) + } + + def test(code0: String) { + val t = new IdempotencyTest { + def code = code0 + } + t.show() + } +} + diff --git a/test/files/res/t6613.check b/test/files/res/t6613.check new file mode 100644 index 0000000000..bbd9331b16 --- /dev/null +++ b/test/files/res/t6613.check @@ -0,0 +1,5 @@ + +nsc> +nsc> +nsc> +nsc> diff --git a/test/files/res/t6613.res b/test/files/res/t6613.res new file mode 100644 index 0000000000..e3fa000fdd --- /dev/null +++ b/test/files/res/t6613.res @@ -0,0 +1,3 @@ +t6613/Enummy.java +t6613/Broken.scala +t6613/Broken.scala diff --git a/test/files/res/t6613/Broken.scala b/test/files/res/t6613/Broken.scala new file mode 100644 index 0000000000..9bcd12dbe1 --- /dev/null +++ b/test/files/res/t6613/Broken.scala @@ -0,0 +1 @@ +class Broken() { def broken() = Enummy.Broke.CHIP } diff --git a/test/files/res/t6613/Enummy.java b/test/files/res/t6613/Enummy.java new file mode 100644 index 0000000000..1863ef1297 --- /dev/null +++ b/test/files/res/t6613/Enummy.java @@ -0,0 +1 @@ +public class Enummy { public enum Broke { SHARD, CHIP } } diff --git a/test/files/res/t8871.check b/test/files/res/t8871.check new file mode 100644 index 0000000000..bbd9331b16 --- /dev/null +++ b/test/files/res/t8871.check @@ -0,0 +1,5 @@ + +nsc> +nsc> +nsc> +nsc> diff --git a/test/files/res/t8871.res b/test/files/res/t8871.res new file mode 100644 index 0000000000..9b1a5fb57f --- /dev/null +++ b/test/files/res/t8871.res @@ -0,0 +1,4 @@ +t8871/tag.scala +t8871/usetag.scala +t8871/usetag.scala + diff --git a/test/files/res/t8871/tag.scala b/test/files/res/t8871/tag.scala new file mode 100644 index 0000000000..1a1803b77d --- /dev/null +++ b/test/files/res/t8871/tag.scala @@ -0,0 +1,3 @@ +class Tag { + @inline def apply[@specialized A, T](a: A): A = a +} diff --git a/test/files/res/t8871/usetag.scala b/test/files/res/t8871/usetag.scala new file mode 100644 index 0000000000..139d768552 --- /dev/null +++ b/test/files/res/t8871/usetag.scala @@ -0,0 +1,6 @@ +trait Foo + +object Test { + val y = new Tag().apply[Double, Foo](3.3) + // under FSC, this gave t8871/usetag.scala:4: error: wrong number of type parameters for method apply$mDc$sp: [T](a: Double)Double +} diff --git a/test/files/run/delambdafy_uncurry_byname_inline.check b/test/files/run/delambdafy_uncurry_byname_inline.check index 0dc69b379a..d96a995f44 100644 --- a/test/files/run/delambdafy_uncurry_byname_inline.check +++ b/test/files/run/delambdafy_uncurry_byname_inline.check @@ -7,7 +7,7 @@ package <empty> { }; def bar(x: () => Int): Int = x.apply(); def foo(): Int = Foo.this.bar({ - @SerialVersionUID(0) final <synthetic> class $anonfun extends scala.runtime.AbstractFunction0[Int] with Serializable { + @SerialVersionUID(value = 0) final <synthetic> class $anonfun extends scala.runtime.AbstractFunction0[Int] with Serializable { def <init>(): <$anon: () => Int> = { $anonfun.super.<init>(); () diff --git a/test/files/run/delambdafy_uncurry_inline.check b/test/files/run/delambdafy_uncurry_inline.check index e2b024b462..5521cc4a2c 100644 --- a/test/files/run/delambdafy_uncurry_inline.check +++ b/test/files/run/delambdafy_uncurry_inline.check @@ -7,7 +7,7 @@ package <empty> { }; def bar(): Unit = { val f: Int => Int = { - @SerialVersionUID(0) final <synthetic> class $anonfun extends scala.runtime.AbstractFunction1[Int,Int] with Serializable { + @SerialVersionUID(value = 0) final <synthetic> class $anonfun extends scala.runtime.AbstractFunction1[Int,Int] with Serializable { def <init>(): <$anon: Int => Int> = { $anonfun.super.<init>(); () diff --git a/test/files/run/global-showdef.check b/test/files/run/global-showdef.check index 4c2fd41a1a..4ac96b4315 100644 --- a/test/files/run/global-showdef.check +++ b/test/files/run/global-showdef.check @@ -1,14 +1,14 @@ <<-- class foo.bar.Bippy after phase 'typer' -->> def showdefTestMemberClass1: Int +<<-- object foo.bar.Bippy after phase 'typer' -->> + def showdefTestMemberObject2: String <<-- type foo.bar.Bippy.BippyType after phase 'typer' -->> def showdefTestMemberType1: Unit +<<-- object foo.bar.Bippy.Boppity.Boo after phase 'typer' -->> + def showdefTestMemberObject1: String <<-- type foo.bar.Bippy.BippyType after phase 'typer' -->> def showdefTestMemberType2: Unit <<-- class foo.bar.Bippy.Boppity after phase 'typer' -->> def showdefTestMemberClass2: Int <<-- class foo.bar.Bippy.Boppity.Boo after phase 'typer' -->> def showdefTestMemberClass3: Int -<<-- object foo.bar.Bippy after phase 'typer' -->> - def showdefTestMemberObject2: String -<<-- object foo.bar.Bippy.Boppity.Boo after phase 'typer' -->> - def showdefTestMemberObject1: String diff --git a/test/files/run/global-showdef.scala b/test/files/run/global-showdef.scala index 1d4891fd1f..276fcc1e7c 100644 --- a/test/files/run/global-showdef.scala +++ b/test/files/run/global-showdef.scala @@ -1,11 +1,10 @@ -import scala.tools.nsc._ -import scala.reflect.io.AbstractFile +import scala.tools.partest.DirectTest import scala.tools.nsc.util.stringFromStream -import scala.reflect.internal.util.{ SourceFile, BatchSourceFile } -import scala.tools.nsc.reporters.ConsoleReporter -object Test { - val src: SourceFile = new BatchSourceFile("src", """ +object Test extends DirectTest { + override def extraSettings: String = "-usejavacp -Yshow:typer -Ystop-after:typer" + + override def code = """ package foo.bar class Bippy { @@ -32,39 +31,28 @@ object Bippy { def showdefTestMemberObject2 = "abc" } - """) + """ + + override def show(): Unit = { + val classes = List("Bippy", "Bippy#BippyType", "Bippy.BippyType", "Bippy#Boppity", "Bippy#Boppity#Boo") + val objects = List("Bippy", "Bippy#Boppity#Boo") + + def interesting(line: String) = (line contains "def showdefTestMember") || (line startsWith "<<-- ") - def mkCompiler(args: String*) = { - val settings = new Settings() - val command = new CompilerCommand("-usejavacp" :: args.toList, settings) + def run(args: String*) = slurp(args: _*).lines filter interesting foreach println - new Global(settings) + classes.zipAll(objects, "", "") foreach { + case (c, "") => run("-Xshow-class", c) + case (c, o) => run("-Xshow-class", c, "-Xshow-object", o) + } } - def slurp(body: => Unit): String = stringFromStream { stream => + // slurp the compilation result + def slurp(args: String*): String = stringFromStream { stream => Console.withOut(stream) { Console.withErr(stream) { - body + compile(args: _*) } } } - def lines(args: String*): List[String] = { - val output = slurp { - val compiler = mkCompiler(args: _*) - val run = new compiler.Run() - run.compileSources(List(src)) - } - output.lines.toList - } - def showClass(name: String) = lines("-Yshow:typer", "-Xshow-class", name) - def showObject(name: String) = lines("-Yshow:typer", "-Xshow-object", name) - - def show(xs: List[String]) = { - xs filter (x => (x contains "def showdefTestMember") || (x startsWith "<<-- ")) foreach println - } - - def main(args: Array[String]) { - show(List("Bippy", "Bippy#BippyType", "Bippy.BippyType", "Bippy#Boppity", "Bippy#Boppity#Boo") flatMap showClass) - show(List("Bippy", "Bippy#Boppity#Boo") flatMap showObject) - } } diff --git a/test/files/run/repl-javap-lambdas.scala b/test/files/run/repl-javap-lambdas.scala new file mode 100644 index 0000000000..15e5bf6877 --- /dev/null +++ b/test/files/run/repl-javap-lambdas.scala @@ -0,0 +1,23 @@ +import scala.tools.partest.JavapTest +import scala.tools.nsc.Settings + +// see repl-javap-memfun.java for the complementary version +object Test extends JavapTest { + override def transformSettings(s: Settings) = { s.Ydelambdafy.value = "method" ; s } + def code = """ + |object Betty { + | List(1,2,3) count (_ % 2 != 0) + | def f = List(1,2,3) filter (_ % 2 != 0) map (_ * 2) + | def g = List(1,2,3) filter (_ % 2 == 0) map (_ * 3) map (_ + 1) + |} + |:javap -fun Betty#g + """.stripMargin + + // three anonfuns of Betty#g + override def yah(res: Seq[String]) = { + import PartialFunction.{ cond => when } + val r = """\s*private static final .* \$anonfun\$\d+\(.*""".r + def filtered = res filter (when(_) { case r(_*) => true }) + 3 == filtered.size + } +} diff --git a/test/files/run/repl-javap-memfun.scala b/test/files/run/repl-javap-memfun.scala index d2b4243c8b..d10ebcb399 100644 --- a/test/files/run/repl-javap-memfun.scala +++ b/test/files/run/repl-javap-memfun.scala @@ -1,6 +1,10 @@ import scala.tools.partest.JavapTest +import scala.tools.nsc.Settings +// see repl-javap-lambdas.scala for the complementary version object Test extends JavapTest { + // asserting the default + override def transformSettings(s: Settings) = { s.Ydelambdafy.value = "inline" ; s } def code = """ |object Betty { | List(1,2,3) count (_ % 2 != 0) diff --git a/test/files/run/t4950.check b/test/files/run/t4950.check new file mode 100644 index 0000000000..3f3a302b62 --- /dev/null +++ b/test/files/run/t4950.check @@ -0,0 +1,9 @@ +Type in expressions to have them evaluated. +Type :help for more information. + +scala> val 1 = 2 +scala.MatchError: 2 (of class java.lang.Integer) + +scala> val List(1) = List(1) + +scala> :quit diff --git a/test/files/run/t4950.scala b/test/files/run/t4950.scala new file mode 100644 index 0000000000..cef06027bf --- /dev/null +++ b/test/files/run/t4950.scala @@ -0,0 +1,12 @@ +import scala.tools.partest.ReplTest + +object Test extends ReplTest { + // Filter out the abbreviated stacktrace "... X elided" + // because the number seems to differ between versions/platforms/... + override def show = eval() filterNot (_ contains "elided") foreach println + def code = +""" +val 1 = 2 +val List(1) = List(1) +""" +} diff --git a/test/files/run/t6028.check b/test/files/run/t6028.check index 55ff42d8d7..edc8b22d6d 100644 --- a/test/files/run/t6028.check +++ b/test/files/run/t6028.check @@ -24,7 +24,7 @@ package <empty> { (new <$anon: Function0>(T.this, tryyParam, tryyLocal): Function0) } }; - @SerialVersionUID(0) final <synthetic> class $anonfun$foo$1 extends scala.runtime.AbstractFunction0$mcI$sp with Serializable { + @SerialVersionUID(value = 0) final <synthetic> class $anonfun$foo$1 extends scala.runtime.AbstractFunction0$mcI$sp with Serializable { def <init>($outer: T, methodParam$1: Int, methodLocal$1: Int): <$anon: Function0> = { $anonfun$foo$1.super.<init>(); () @@ -60,7 +60,7 @@ package <empty> { }; scala.this.Predef.print(scala.Int.box(barParam$1)) }; - @SerialVersionUID(0) final <synthetic> class $anonfun$tryy$1 extends scala.runtime.AbstractFunction0$mcV$sp with Serializable { + @SerialVersionUID(value = 0) final <synthetic> class $anonfun$tryy$1 extends scala.runtime.AbstractFunction0$mcV$sp with Serializable { def <init>($outer: T, tryyParam$1: Int, tryyLocal$1: runtime.IntRef): <$anon: Function0> = { $anonfun$tryy$1.super.<init>(); () diff --git a/test/files/run/t6541-option.scala b/test/files/run/t6541-option.scala new file mode 100644 index 0000000000..2c10c9e09d --- /dev/null +++ b/test/files/run/t6541-option.scala @@ -0,0 +1,19 @@ +import scala.tools.partest.ReplTest + +object Test extends ReplTest { + def code = """ +:setting -Xsource:2.12 +case class C12(clazz: Class[_]) +val o: Option[Class[T] forSome { type T}] = C12.unapply(C12(classOf[String])) + +:setting -Xsource:2.11 +import scala.language.existentials +case class C11(clazz: Class[_]) +val o: Option[Class[T]] forSome { type T } = C11.unapply(C11(classOf[String])) + """ + + override def show() = { + val r = eval().mkString("\n") + assert(!(r.contains("warning") || r.contains("error")), r) + } +} diff --git a/test/files/run/t6541.flags b/test/files/run/t6541.flags new file mode 100644 index 0000000000..68d0ddfec2 --- /dev/null +++ b/test/files/run/t6541.flags @@ -0,0 +1 @@ +-feature -Xfatal-warnings -Xsource:2.12
\ No newline at end of file diff --git a/test/files/run/t6541.scala b/test/files/run/t6541.scala new file mode 100644 index 0000000000..f127143691 --- /dev/null +++ b/test/files/run/t6541.scala @@ -0,0 +1,25 @@ +class A +class B[T](x: T) +case class C(a: A, b: B[_]) + +case class D(a: A, b: B[_]*) + +case class E(c: Class[_]) + +object Test extends App { + def f1(c: C) = c match { + case C(a, b) => () + } + + def f2(d: D) = d match { + case D(a, b1, b2) => () + } + + def f3(e: E) = e match { + case E(c) => () + } + + f1(C(new A, new B(1))) + f2(D(new A, new B(1), new B(2))) + f3(E(classOf[E])) +} diff --git a/test/files/run/t6555.check b/test/files/run/t6555.check index 9ac115a13f..e3b467ce7c 100644 --- a/test/files/run/t6555.check +++ b/test/files/run/t6555.check @@ -6,7 +6,7 @@ package <empty> { () }; private[this] val f: Int => Int = { - @SerialVersionUID(0) final <synthetic> class $anonfun extends scala.runtime.AbstractFunction1$mcII$sp with Serializable { + @SerialVersionUID(value = 0) final <synthetic> class $anonfun extends scala.runtime.AbstractFunction1$mcII$sp with Serializable { def <init>(): <$anon: Int => Int> = { $anonfun.super.<init>(); () diff --git a/test/files/run/t8893.scala b/test/files/run/t8893.scala new file mode 100644 index 0000000000..6fef8ae912 --- /dev/null +++ b/test/files/run/t8893.scala @@ -0,0 +1,40 @@ +import annotation.tailrec + +object Test { + def a(): Option[String] = Some("a") + + def test1: Any = { + a() match { + case Some(b1) => + a() match { + case Some(b2) => + @tailrec + def tick(i: Int): Unit = if (i < 0) () else tick(i - 1) + tick(10000000) // testing that this doesn't SOE + case None => None + } + case None => None + } + } + + def test2: Any = { + a() match { + case Some(b1) => + a() match { + case Some(b2) => + @tailrec + def tick(i: Int): Unit = if (i < 0) () else tick(i - 1) + tick(10000000) // testing that this doesn't SOE + case None => test1 + } + case None => + test1 // not a tail call + test1 + } + } + + def main(args: Array[String]) { + test1 + test2 + } +} diff --git a/test/files/run/t8893b.scala b/test/files/run/t8893b.scala new file mode 100644 index 0000000000..19120871aa --- /dev/null +++ b/test/files/run/t8893b.scala @@ -0,0 +1,15 @@ +// Testing that recursive calls in tail positions are replaced with +// jumps, even though the method contains recursive calls outside +// of the tail position. +object Test { + def tick(i : Int): Unit = + if (i == 0) () + else if (i == 42) { + tick(0) /*not in tail posiiton*/ + tick(i - 1) + } else tick(i - 1) + + def main(args: Array[String]): Unit = { + tick(1000000) + } +} diff --git a/test/files/run/t8960.scala b/test/files/run/t8960.scala new file mode 100644 index 0000000000..c6bcd0770c --- /dev/null +++ b/test/files/run/t8960.scala @@ -0,0 +1,66 @@ +object Test extends App { + def test(o: AnyRef, sp: Boolean = false) = { + if (sp) assert(o.getClass.getSuperclass.getName contains "$sp") + val Some(f) = o.getClass.getDeclaredFields.find(_.getName == "serialVersionUID") + assert(f.getLong(null) == 0l) + } + + test(() => (), sp = true) + test(() => 1, sp = true) + test(() => "") + + test((x: Int) => x, sp = true) + test((x: Boolean) => x) + test((x: Int) => "") + + test((x1: Int, x2: Int) => 0d, sp = true) + test((x1: Int, x2: AnyRef) => 0d) + test((x1: Any, x2: Any) => x1) + + // scala> println((for (i <- 3 to 22) yield (for (j <- 1 to i) yield s"x$j: Int").mkString(" test((", ", ", ") => x1)")).mkString("\n")) + + test((x1: Int, x2: Int, x3: Int) => x1) + test((x1: Int, x2: Int, x3: Int, x4: Int) => x1) + test((x1: Int, x2: Int, x3: Int, x4: Int, x5: Int) => x1) + test((x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int) => x1) + test((x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int) => x1) + test((x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int) => x1) + test((x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int) => x1) + test((x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int) => x1) + test((x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int) => x1) + test((x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int) => x1) + test((x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int) => x1) + test((x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int) => x1) + test((x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int, x15: Int) => x1) + test((x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int, x15: Int, x16: Int) => x1) + test((x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int, x15: Int, x16: Int, x17: Int) => x1) + test((x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int, x15: Int, x16: Int, x17: Int, x18: Int) => x1) + test((x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int, x15: Int, x16: Int, x17: Int, x18: Int, x19: Int) => x1) + test((x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int, x15: Int, x16: Int, x17: Int, x18: Int, x19: Int, x20: Int) => x1) + test((x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int, x15: Int, x16: Int, x17: Int, x18: Int, x19: Int, x20: Int, x21: Int) => x1) + test((x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int, x15: Int, x16: Int, x17: Int, x18: Int, x19: Int, x20: Int, x21: Int, x22: Int) => x1) + + test({ + case x: Int => x + }: PartialFunction[Int, Int], sp = true) + + test({ + case x: Int => x + }: PartialFunction[Any, Any]) + + test({ + case x: Int => () + }: PartialFunction[Int, Unit], sp = true) + + test({ + case x: String => 1 + }: PartialFunction[String, Int]) + + test({ + case x: String => () + }: PartialFunction[String, Unit]) + + test({ + case x: String => x + }: PartialFunction[String, String]) +} diff --git a/test/files/run/xMigration.check b/test/files/run/xMigration.check new file mode 100644 index 0000000000..378f7bb6c3 --- /dev/null +++ b/test/files/run/xMigration.check @@ -0,0 +1,49 @@ +Type in expressions to have them evaluated. +Type :help for more information. + +scala> Map(1 -> "eis").values // no warn +res0: Iterable[String] = MapLike(eis) + +scala> :setting -Xmigration:none + +scala> Map(1 -> "eis").values // no warn +res1: Iterable[String] = MapLike(eis) + +scala> :setting -Xmigration:any + +scala> Map(1 -> "eis").values // warn +<console>:8: warning: method values in trait MapLike has changed semantics in version 2.8.0: +`values` returns `Iterable[B]` rather than `Iterator[B]`. + Map(1 -> "eis").values // warn + ^ +res2: Iterable[String] = MapLike(eis) + +scala> :setting -Xmigration:2.8 + +scala> Map(1 -> "eis").values // no warn +res3: Iterable[String] = MapLike(eis) + +scala> :setting -Xmigration:2.7 + +scala> Map(1 -> "eis").values // warn +<console>:8: warning: method values in trait MapLike has changed semantics in version 2.8.0: +`values` returns `Iterable[B]` rather than `Iterator[B]`. + Map(1 -> "eis").values // warn + ^ +res4: Iterable[String] = MapLike(eis) + +scala> :setting -Xmigration:2.11 + +scala> Map(1 -> "eis").values // no warn +res5: Iterable[String] = MapLike(eis) + +scala> :setting -Xmigration // same as :any + +scala> Map(1 -> "eis").values // warn +<console>:8: warning: method values in trait MapLike has changed semantics in version 2.8.0: +`values` returns `Iterable[B]` rather than `Iterator[B]`. + Map(1 -> "eis").values // warn + ^ +res6: Iterable[String] = MapLike(eis) + +scala> :quit diff --git a/test/files/run/xMigration.scala b/test/files/run/xMigration.scala new file mode 100644 index 0000000000..688e878397 --- /dev/null +++ b/test/files/run/xMigration.scala @@ -0,0 +1,19 @@ +import scala.tools.partest.ReplTest + +object Test extends ReplTest { + def code = """ +Map(1 -> "eis").values // no warn +:setting -Xmigration:none +Map(1 -> "eis").values // no warn +:setting -Xmigration:any +Map(1 -> "eis").values // warn +:setting -Xmigration:2.8 +Map(1 -> "eis").values // no warn +:setting -Xmigration:2.7 +Map(1 -> "eis").values // warn +:setting -Xmigration:2.11 +Map(1 -> "eis").values // no warn +:setting -Xmigration // same as :any +Map(1 -> "eis").values // warn + """ +} diff --git a/test/junit/scala/collection/mutable/BitSetTest.scala b/test/junit/scala/collection/mutable/BitSetTest.scala new file mode 100644 index 0000000000..8d164b50d4 --- /dev/null +++ b/test/junit/scala/collection/mutable/BitSetTest.scala @@ -0,0 +1,22 @@ +package scala.collection.mutable + +import org.junit.runner.RunWith +import org.junit.runners.JUnit4 +import org.junit.{Test, Ignore} + +@RunWith(classOf[JUnit4]) +class BitSetTest { + // Test for SI-8910 + @Test def capacityExpansionTest() { + val bitSet = BitSet.empty + val size = bitSet.toBitMask.length + bitSet ^= bitSet + assert(bitSet.toBitMask.length == size, "Capacity of bitset changed after ^=") + bitSet |= bitSet + assert(bitSet.toBitMask.length == size, "Capacity of bitset changed after |=") + bitSet &= bitSet + assert(bitSet.toBitMask.length == size, "Capacity of bitset changed after &=") + bitSet &~= bitSet + assert(bitSet.toBitMask.length == size, "Capacity of bitset changed after &~=") + } +} diff --git a/test/junit/scala/reflect/internal/PrintersTest.scala b/test/junit/scala/reflect/internal/PrintersTest.scala index ca9b4671b2..7043c26d5e 100644 --- a/test/junit/scala/reflect/internal/PrintersTest.scala +++ b/test/junit/scala/reflect/internal/PrintersTest.scala @@ -354,6 +354,13 @@ trait ClassPrintTests { | def y = "test" |}""") + @Test def testClassConstructorModifiers = assertPrintedCode("class X private (x: scala.Int)") + + @Test def testClassConstructorModifierVisibility = assertPrintedCode(sm""" + |object A { + | class X protected[A] (x: scala.Int) + |}""") + @Test def testClassWithPublicParams = assertPrintedCode("class X(val x: scala.Int, val s: scala.Predef.String)") @Test def testClassWithParams1 = assertPrintedCode("class X(x: scala.Int, s: scala.Predef.String)") diff --git a/test/junit/scala/tools/nsc/settings/ScalaVersionTest.scala b/test/junit/scala/tools/nsc/settings/ScalaVersionTest.scala new file mode 100644 index 0000000000..77a2da828e --- /dev/null +++ b/test/junit/scala/tools/nsc/settings/ScalaVersionTest.scala @@ -0,0 +1,18 @@ +package scala.tools.nsc +package settings + +import org.junit.Assert._ +import org.junit.Test +import org.junit.runner.RunWith +import org.junit.runners.JUnit4 +import scala.tools.testing.AssertUtil.assertThrows + +@RunWith(classOf[JUnit4]) +class ScalaVersionTest { + // SI-8711 + @Test def versionUnparse() { + val v = "2.11.3" + + assertEquals(ScalaVersion(v).unparse, v) + } +} diff --git a/test/junit/scala/tools/nsc/settings/SettingsTest.scala b/test/junit/scala/tools/nsc/settings/SettingsTest.scala index eda0c27834..96f83c4c2f 100644 --- a/test/junit/scala/tools/nsc/settings/SettingsTest.scala +++ b/test/junit/scala/tools/nsc/settings/SettingsTest.scala @@ -164,4 +164,20 @@ class SettingsTest { assertThrows[IllegalArgumentException](check("-m:a,b,-ab")(_ => true), _ contains "'ab' cannot be negated") assertThrows[IllegalArgumentException](check("-m:a,ac,-uber,uber")(_ => true), _ contains "'uber' cannot be negated") } + + @Test def xSourceTest(): Unit = { + def check(expected: String, args: String*): Unit = { + val s = new MutableSettings(msg => throw new IllegalArgumentException(msg)) + val (_, residual) = s.processArguments(args.toList, processAll = true) + assert(residual.isEmpty) + assertTrue(s.source.value == ScalaVersion(expected)) + } + check(expected = "2.11.0") // default + check(expected = "2.11.0", "-Xsource:2.11") + check(expected = "2.10", "-Xsource:2.10.0") + check(expected = "2.12", "-Xsource:2.12") + assertThrows[IllegalArgumentException](check(expected = "2.11", "-Xsource"), _ == "-Xsource requires an argument, the syntax is -Xsource:<version>") + assertThrows[IllegalArgumentException](check(expected = "2.11", "-Xsource", "2.11"), _ == "-Xsource requires an argument, the syntax is -Xsource:<version>") + assertThrows[IllegalArgumentException](check(expected = "2.11", "-Xsource:2.invalid"), _ contains "There was a problem parsing 2.invalid") + } } diff --git a/test/osgi/src/BasicLibrary.scala b/test/osgi/src/BasicLibrary.scala index 6618f02102..ee8b7634ff 100644 --- a/test/osgi/src/BasicLibrary.scala +++ b/test/osgi/src/BasicLibrary.scala @@ -7,19 +7,16 @@ import org.ops4j.pax.exam.CoreOptions._ import org.junit.Test import org.junit.runner.RunWith import org.ops4j.pax.exam -import org.ops4j.pax.exam.junit.{ - Configuration, - ExamReactorStrategy, - JUnit4TestRunner -} -import org.ops4j.pax.exam.spi.reactors.AllConfinedStagedReactorFactory -import org.ops4j.pax.swissbox.framework.ServiceLookup +import org.ops4j.pax.exam.Configuration +import org.ops4j.pax.exam.junit.PaxExam +import org.ops4j.pax.exam.spi.reactors.{ ExamReactorStrategy, PerMethod } +import org.ops4j.pax.swissbox.tracker.ServiceLookup import org.osgi.framework.BundleContext -@RunWith(classOf[JUnit4TestRunner]) -@ExamReactorStrategy(Array(classOf[AllConfinedStagedReactorFactory])) +@RunWith(classOf[PaxExam]) +@ExamReactorStrategy(Array(classOf[PerMethod])) class BasicLibraryTest extends ScalaOsgiHelper { @Configuration def config(): Array[exam.Option] = diff --git a/test/osgi/src/BasicReflection.scala b/test/osgi/src/BasicReflection.scala index d601f04f89..53ab7e5345 100644 --- a/test/osgi/src/BasicReflection.scala +++ b/test/osgi/src/BasicReflection.scala @@ -10,13 +10,10 @@ import org.ops4j.pax.exam.CoreOptions._ import org.junit.Test import org.junit.runner.RunWith import org.ops4j.pax.exam -import org.ops4j.pax.exam.junit.{ - Configuration, - ExamReactorStrategy, - JUnit4TestRunner -} -import org.ops4j.pax.exam.spi.reactors.AllConfinedStagedReactorFactory -import org.ops4j.pax.swissbox.framework.ServiceLookup +import org.ops4j.pax.exam.Configuration +import org.ops4j.pax.exam.junit.PaxExam +import org.ops4j.pax.exam.spi.reactors.{ ExamReactorStrategy, PerMethod } +import org.ops4j.pax.swissbox.tracker.ServiceLookup import org.osgi.framework.BundleContext @@ -38,8 +35,8 @@ class C { object M -@RunWith(classOf[JUnit4TestRunner]) -@ExamReactorStrategy(Array(classOf[AllConfinedStagedReactorFactory])) +@RunWith(classOf[PaxExam]) +@ExamReactorStrategy(Array(classOf[PerMethod])) class BasicReflectionTest extends ScalaOsgiHelper { @Configuration diff --git a/test/osgi/src/BasicTest.scala b/test/osgi/src/BasicTest.scala index 109b7b911a..5adf87ecc1 100644 --- a/test/osgi/src/BasicTest.scala +++ b/test/osgi/src/BasicTest.scala @@ -6,21 +6,18 @@ import org.ops4j.pax.exam.CoreOptions._ import org.junit.Test import org.junit.runner.RunWith import org.ops4j.pax.exam -import org.ops4j.pax.exam.junit.{ - Configuration, - ExamReactorStrategy, - JUnit4TestRunner -} -import org.ops4j.pax.exam.spi.reactors.AllConfinedStagedReactorFactory -import org.ops4j.pax.swissbox.framework.ServiceLookup +import org.ops4j.pax.exam.Configuration +import org.ops4j.pax.exam.junit.PaxExam +import org.ops4j.pax.exam.spi.reactors.{ ExamReactorStrategy, PerMethod } +import org.ops4j.pax.swissbox.tracker.ServiceLookup import org.osgi.framework.BundleContext -@RunWith(classOf[JUnit4TestRunner]) -@ExamReactorStrategy(Array(classOf[AllConfinedStagedReactorFactory])) +@RunWith(classOf[PaxExam]) +@ExamReactorStrategy(Array(classOf[PerMethod])) class BasicTest extends ScalaOsgiHelper { @Configuration def config(): Array[exam.Option] = { diff --git a/test/osgi/src/ReflectionToolboxTest.scala b/test/osgi/src/ReflectionToolboxTest.scala index bb48078e95..a23de18d07 100644 --- a/test/osgi/src/ReflectionToolboxTest.scala +++ b/test/osgi/src/ReflectionToolboxTest.scala @@ -8,13 +8,10 @@ import org.ops4j.pax.exam.CoreOptions._ import org.junit.Test import org.junit.runner.RunWith import org.ops4j.pax.exam -import org.ops4j.pax.exam.junit.{ - Configuration, - ExamReactorStrategy, - JUnit4TestRunner -} -import org.ops4j.pax.exam.spi.reactors.AllConfinedStagedReactorFactory -import org.ops4j.pax.swissbox.framework.ServiceLookup +import org.ops4j.pax.exam.Configuration +import org.ops4j.pax.exam.junit.PaxExam +import org.ops4j.pax.exam.spi.reactors.{ ExamReactorStrategy, PerMethod } +import org.ops4j.pax.swissbox.tracker.ServiceLookup import org.osgi.framework.BundleContext @@ -22,8 +19,8 @@ class C { val f1 = 2 } -@RunWith(classOf[JUnit4TestRunner]) -@ExamReactorStrategy(Array(classOf[AllConfinedStagedReactorFactory])) +@RunWith(classOf[PaxExam]) +@ExamReactorStrategy(Array(classOf[PerMethod])) class ReflectionToolBoxTest extends ScalaOsgiHelper { @Configuration diff --git a/test/osgi/src/ScalaOsgiHelper.scala b/test/osgi/src/ScalaOsgiHelper.scala index 084afe8643..7ba8883bb8 100644 --- a/test/osgi/src/ScalaOsgiHelper.scala +++ b/test/osgi/src/ScalaOsgiHelper.scala @@ -20,19 +20,19 @@ trait ScalaOsgiHelper { def standardOptions: Array[exam.Option] = { val bundles = (allBundleFiles map makeBundle) - bundles ++ Array[exam.Option](felix(), equinox(), junitBundles()) + bundles ++ Array[exam.Option](junitBundles()) // to change the local repo used (for some operations, but not all -- which is why I didn't bother): // systemProperty("org.ops4j.pax.url.mvn.localRepository").value(sys.props("maven.repo.local"))) } def justReflectionOptions: Array[exam.Option] = { val bundles = filteredBundleFiles("scala-library", "scala-reflect") - bundles ++ Array[exam.Option](felix(), equinox(), junitBundles()) + bundles ++ Array[exam.Option](junitBundles()) } def justCoreLibraryOptions: Array[exam.Option] = { val bundles = filteredBundleFiles("scala-library") - bundles ++ Array[exam.Option](felix(), equinox(), junitBundles()) + bundles ++ Array[exam.Option](junitBundles()) } } diff --git a/test/pending/pos/t3439.scala b/test/pending/pos/t3439.scala deleted file mode 100644 index 425f1aeeb5..0000000000 --- a/test/pending/pos/t3439.scala +++ /dev/null @@ -1,2 +0,0 @@ -abstract class ParametricMessage[M: Manifest](msg: M) { def message = msg } -case class ParametricMessage1[M: Manifest](msg: M, p1: Class[_]) extends ParametricMessage(msg) diff --git a/test/scaladoc/run/t6626.check b/test/scaladoc/run/t6626.check new file mode 100644 index 0000000000..de3a6c5c0b --- /dev/null +++ b/test/scaladoc/run/t6626.check @@ -0,0 +1,7 @@ +newSource:10: warning: Could not find any member to link for "SomeUnknownException". + /** + ^ +newSource:10: warning: Could not find any member to link for "IOException". + /** + ^ +Done. diff --git a/test/scaladoc/run/t6626.scala b/test/scaladoc/run/t6626.scala new file mode 100644 index 0000000000..6c61c605d6 --- /dev/null +++ b/test/scaladoc/run/t6626.scala @@ -0,0 +1,42 @@ +import scala.tools.nsc.doc.base._ +import scala.tools.nsc.doc.base.comment._ +import scala.tools.nsc.doc.model._ +import scala.tools.partest.ScaladocModelTest + +object Test extends ScaladocModelTest { + + override def code = """ + +package org.foo + +class MyException extends Exception + +class MyOtherException extends Exception + +object Foo { + /** + * Test exception linking + * + * @throws org.foo.MyException linked with a fully-qualified name + * @throws MyOtherException linked with a relative name + * @throws SomeUnknownException not linked at all (but with some text) + * @throws IOException + */ + def test(): Unit = ??? +} + """ + + def scaladocSettings = "" + + def testModel(rootPackage: Package) = { + // get the quick access implicit defs in scope (_package(s), _class(es), _trait(s), object(s) _method(s), _value(s)) + import access._ + + val a = rootPackage._package("org")._package("foo")._object("Foo")._method("test") + val throws = a.comment.get.throws + val allbodies = Body(throws.values.flatMap(_.blocks).toSeq) + + val links = countLinksInBody(allbodies, _.link.isInstanceOf[LinkToTpl[_]]) + assert(links == 2, links + " == 2 (links to MyException and MyOtherException)") + } +} |