summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--build.sbt78
-rw-r--r--project/Osgi.scala1
-rw-r--r--src/repl/scala/tools/nsc/interpreter/Imports.scala35
-rw-r--r--src/repl/scala/tools/nsc/interpreter/package.scala9
-rw-r--r--test/files/jvm/interpreter.check2
-rw-r--r--test/files/run/repl-classbased.check23
-rw-r--r--test/files/run/repl-classbased.scala22
-rw-r--r--test/files/run/repl-javap-app.check60
-rw-r--r--test/files/run/repl-javap-app.scala15
-rw-r--r--test/files/run/t7319.check6
10 files changed, 133 insertions, 118 deletions
diff --git a/build.sbt b/build.sbt
index 82d23fed90..984ac0e91c 100644
--- a/build.sbt
+++ b/build.sbt
@@ -88,7 +88,7 @@ lazy val publishSettings : Seq[Setting[_]] = Seq(
val mappings = artifacts.toSeq.map { case (a, f) =>
val typeSuffix = a.`type` match {
case "pom" => "-pom.xml"
- case "bundle" | "jar" => ".jar"
+ case "jar" => ".jar"
case "doc" => "-docs.jar"
case tpe => s"-$tpe.${a.extension}"
}
@@ -103,6 +103,8 @@ lazy val publishSettings : Seq[Setting[_]] = Seq(
if (file.exists) List(Credentials(file))
else Nil
},
+ // Add a "default" Ivy configuration because sbt expects the Scala distribution to have one:
+ ivyConfigurations += Configuration("default", "Default", true, List(Configurations.Runtime), true),
publishMavenStyle := true
)
@@ -242,8 +244,8 @@ def fixPom(extra: (String, scala.xml.Node)*): Setting[_] = {
) ++ extra) }
}
-/** Remove unwanted dependencies from the POM. */
-def removePomDependencies(deps: (String, String)*): Setting[_] = {
+/** Remove unwanted dependencies from the POM and ivy.xml. */
+def removePomDependencies(deps: (String, String)*): Seq[Setting[_]] = Seq(
pomPostProcess := { n =>
val n2 = pomPostProcess.value.apply(n)
import scala.xml._
@@ -258,14 +260,40 @@ def removePomDependencies(deps: (String, String)*): Setting[_] = {
case n => Seq(n)
}
})).transform(Seq(n2)).head
+ },
+ deliverLocal := {
+ import scala.xml._
+ import scala.xml.transform._
+ val f = deliverLocal.value
+ val e = (new RuleTransformer(new RewriteRule {
+ override def transform(node: Node) = node match {
+ case e: Elem if e.label == "dependency" && {
+ val org = e.attribute("org").getOrElse("").toString
+ val name = e.attribute("name").getOrElse("").toString
+ deps.exists { case (g, a) =>
+ org == g && (name == a || name == (a + "_" + scalaBinaryVersion.value))
+ }
+ } => Seq.empty
+ case n => Seq(n)
+ }
+ })).transform(Seq(XML.loadFile(f))).head
+ XML.save(f.getAbsolutePath, e, xmlDecl = true)
+ f
}
-}
+)
val disableDocs = Seq[Setting[_]](
sources in (Compile, doc) := Seq.empty,
publishArtifact in (Compile, packageDoc) := false
)
+val disablePublishing = Seq[Setting[_]](
+ publishArtifact := false,
+ // The above is enough for Maven repos but it doesn't prevent publishing of ivy.xml files
+ publish := {},
+ publishLocal := {}
+)
+
lazy val setJarLocation: Setting[_] =
artifactPath in packageBin in Compile := {
// two lines below are copied over from sbt's sources:
@@ -327,10 +355,10 @@ lazy val library = configureAsSubproject(project)
"/project/name" -> <name>Scala Library</name>,
"/project/description" -> <description>Standard library for the Scala Programming Language</description>,
"/project/packaging" -> <packaging>jar</packaging>
- ),
- // Remove the dependency on "forkjoin" from the POM because it is included in the JAR:
- removePomDependencies(("org.scala-lang", "forkjoin"))
+ )
)
+ // Remove the dependency on "forkjoin" from the POM because it is included in the JAR:
+ .settings(removePomDependencies(("org.scala-lang", "forkjoin")): _*)
.settings(filterDocSources("*.scala" -- (regexFileFilter(".*/runtime/.*\\$\\.scala") ||
regexFileFilter(".*/runtime/ScalaRunTime\\.scala") ||
regexFileFilter(".*/runtime/StringAdd\\.scala"))): _*)
@@ -408,43 +436,44 @@ lazy val compiler = configureAsSubproject(project)
"/project/description" -> <description>Compiler for the Scala Programming Language</description>,
"/project/packaging" -> <packaging>jar</packaging>
),
- apiURL := None,
- removePomDependencies(
- ("org.apache.ant", "ant"),
- ("org.scala-lang.modules", "scala-asm")
- )
+ apiURL := None
)
+ .settings(removePomDependencies(
+ ("org.apache.ant", "ant"),
+ ("org.scala-lang.modules", "scala-asm")
+ ): _*)
.dependsOn(library, reflect)
lazy val interactive = configureAsSubproject(project)
.settings(disableDocs: _*)
+ .settings(disablePublishing: _*)
.settings(
name := "scala-compiler-interactive",
- description := "Scala Interactive Compiler",
- publishArtifact := false
+ description := "Scala Interactive Compiler"
)
.dependsOn(compiler)
lazy val repl = configureAsSubproject(project)
.settings(disableDocs: _*)
+ .settings(disablePublishing: _*)
.settings(
connectInput in run := true,
- publishArtifact := false,
run <<= (run in Compile).partialInput(" -usejavacp") // Automatically add this so that `repl/run` works without additional arguments.
)
.dependsOn(compiler, interactive)
lazy val replJline = configureAsSubproject(Project("repl-jline", file(".") / "src" / "repl-jline"))
.settings(disableDocs: _*)
+ .settings(disablePublishing: _*)
.settings(
libraryDependencies += jlineDep,
- name := "scala-repl-jline",
- publishArtifact := false
+ name := "scala-repl-jline"
)
.dependsOn(repl)
lazy val replJlineEmbedded = Project("repl-jline-embedded", file(".") / "target" / "repl-jline-embedded-src-dummy")
.settings(scalaSubprojectSettings: _*)
+ .settings(disablePublishing: _*)
.settings(
name := "scala-repl-jline-embedded",
// There is nothing to compile for this project. Instead we use the compile task to create
@@ -475,7 +504,6 @@ lazy val replJlineEmbedded = Project("repl-jline-embedded", file(".") / "target"
val outdir = (classDirectory in Compile).value
JarJar(inputs, outdir, config)
}),
- publishArtifact := false,
connectInput in run := true
)
@@ -483,11 +511,11 @@ lazy val replJlineEmbedded = Project("repl-jline-embedded", file(".") / "target"
lazy val scaladoc = configureAsSubproject(project)
.settings(disableDocs: _*)
+ .settings(disablePublishing: _*)
.settings(
name := "scala-compiler-doc",
description := "Scala Documentation Generator",
libraryDependencies ++= Seq(scalaXmlDep, scalaParserCombinatorsDep, partestDep),
- publishArtifact := false,
includeFilter in unmanagedResources in Compile := "*.html" | "*.css" | "*.gif" | "*.png" | "*.js" | "*.txt"
)
.dependsOn(compiler)
@@ -529,10 +557,10 @@ lazy val partestExtras = configureAsSubproject(Project("partest-extras", file(".
.dependsOn(replJlineEmbedded)
.settings(clearSourceAndResourceDirectories: _*)
.settings(disableDocs: _*)
+ .settings(disablePublishing: _*)
.settings(
name := "scala-partest-extras",
description := "Scala Compiler Testing Tool (compiler-specific extras)",
- publishArtifact := false,
libraryDependencies += partestDep,
unmanagedSourceDirectories in Compile := List(baseDirectory.value)
)
@@ -542,8 +570,8 @@ lazy val junit = project.in(file("test") / "junit")
.settings(clearSourceAndResourceDirectories: _*)
.settings(commonSettings: _*)
.settings(disableDocs: _*)
+ .settings(disablePublishing: _*)
.settings(
- publishArtifact := false,
fork in Test := true,
libraryDependencies ++= Seq(junitDep, junitIntefaceDep),
testOptions += Tests.Argument(TestFrameworks.JUnit, "-a", "-v"),
@@ -575,9 +603,9 @@ lazy val test = project
.configs(IntegrationTest)
.settings(commonSettings: _*)
.settings(disableDocs: _*)
+ .settings(disablePublishing: _*)
.settings(Defaults.itSettings: _*)
.settings(
- publishArtifact := false,
libraryDependencies ++= Seq(asmDep, partestDep, scalaXmlDep, scalacheckDep),
unmanagedBase in IntegrationTest := baseDirectory.value / "files" / "lib",
unmanagedJars in IntegrationTest <+= (unmanagedBase) (j => Attributed.blank(j)) map(identity),
@@ -604,8 +632,8 @@ lazy val test = project
lazy val manual = configureAsSubproject(project)
.settings(disableDocs: _*)
+ .settings(disablePublishing: _*)
.settings(
- publishArtifact := false,
libraryDependencies ++= Seq(scalaXmlDep, antDep),
classDirectory in Compile := (target in Compile).value / "classes"
)
@@ -675,9 +703,9 @@ lazy val scalaDist = Project("scala-dist", file(".") / "target" / "scala-dist-di
lazy val root = (project in file("."))
.settings(disableDocs: _*)
+ .settings(disablePublishing: _*)
.settings(generateBuildCharacterFileSettings: _*)
.settings(
- publishArtifact := false,
publish := {},
publishLocal := {},
commands ++= ScriptCommands.all,
@@ -760,8 +788,8 @@ def configureAsForkOfJavaProject(project: Project): Project = {
(project in base)
.settings(commonSettings: _*)
.settings(disableDocs: _*)
+ .settings(disablePublishing: _*)
.settings(
- publishArtifact := false,
sourceDirectory in Compile := baseDirectory.value,
javaSource in Compile := (sourceDirectory in Compile).value,
sources in Compile in doc := Seq.empty,
diff --git a/project/Osgi.scala b/project/Osgi.scala
index ed961d1c27..4456c94190 100644
--- a/project/Osgi.scala
+++ b/project/Osgi.scala
@@ -39,7 +39,6 @@ object Osgi {
},
packagedArtifact in (Compile, packageBin) <<= (artifact in (Compile, packageBin), bundle).identityMap,
// Also create OSGi source bundles:
- artifact in (Compile, packageBin) ~= (_.copy(`type` = "bundle")),
packageOptions in (Compile, packageSrc) += Package.ManifestAttributes(
"Bundle-Name" -> (description.value + " Sources"),
"Bundle-SymbolicName" -> (bundleSymbolicName.value + ".source"),
diff --git a/src/repl/scala/tools/nsc/interpreter/Imports.scala b/src/repl/scala/tools/nsc/interpreter/Imports.scala
index f04e2e808c..71a5e9f00a 100644
--- a/src/repl/scala/tools/nsc/interpreter/Imports.scala
+++ b/src/repl/scala/tools/nsc/interpreter/Imports.scala
@@ -127,7 +127,11 @@ trait Imports {
case rh :: rest if !keepHandler(rh.handler) => select(rest, wanted)
case rh :: rest =>
import rh.handler._
- val newWanted = wanted ++ referencedNames -- definedNames -- importedNames
+ val augment = rh match {
+ case ReqAndHandler(_, _: ImportHandler) => referencedNames // for "import a.b", add "a" to names to be resolved
+ case _ => Nil
+ }
+ val newWanted = wanted ++ augment -- definedNames -- importedNames
rh :: select(rest, newWanted)
}
}
@@ -161,6 +165,8 @@ trait Imports {
val tempValLines = mutable.Set[Int]()
for (ReqAndHandler(req, handler) <- reqsToUse) {
val objName = req.lineRep.readPathInstance
+ if (isReplTrace)
+ code.append(ss"// $objName definedNames ${handler.definedNames}, curImps $currentImps\n")
handler match {
case h: ImportHandler if checkHeader(h) =>
header.clear()
@@ -175,21 +181,20 @@ trait Imports {
currentImps ++= x.importedNames
case x if isClassBased =>
- for (imv <- x.definedNames) {
- if (!currentImps.contains(imv)) {
- x match {
- case _: ClassHandler =>
- code.append("import " + objName + req.accessPath + ".`" + imv + "`\n")
- case _ =>
- val valName = req.lineRep.packageName + req.lineRep.readName
- if (!tempValLines.contains(req.lineRep.lineId)) {
- code.append(s"val $valName: ${objName}.type = $objName\n")
- tempValLines += req.lineRep.lineId
- }
- code.append(s"import $valName${req.accessPath}.`$imv`;\n")
- }
- currentImps += imv
+ for (sym <- x.definedSymbols) {
+ maybeWrap(sym.name)
+ x match {
+ case _: ClassHandler =>
+ code.append(s"import ${objName}${req.accessPath}.`${sym.name}`\n")
+ case _ =>
+ val valName = s"${req.lineRep.packageName}${req.lineRep.readName}"
+ if (!tempValLines.contains(req.lineRep.lineId)) {
+ code.append(s"val $valName: ${objName}.type = $objName\n")
+ tempValLines += req.lineRep.lineId
+ }
+ code.append(s"import ${valName}${req.accessPath}.`${sym.name}`\n")
}
+ currentImps += sym.name
}
// For other requests, import each defined name.
// import them explicitly instead of with _, so that
diff --git a/src/repl/scala/tools/nsc/interpreter/package.scala b/src/repl/scala/tools/nsc/interpreter/package.scala
index 56f1e65376..7934d819b4 100644
--- a/src/repl/scala/tools/nsc/interpreter/package.scala
+++ b/src/repl/scala/tools/nsc/interpreter/package.scala
@@ -198,13 +198,14 @@ package object interpreter extends ReplConfig with ReplStrings {
}
}
- /* debug assist
+ /* An s-interpolator that uses `stringOf(arg)` instead of `String.valueOf(arg)`. */
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 */
+ }
+ /* Try (body) lastly (more) */
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) _)
+ 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/test/files/jvm/interpreter.check b/test/files/jvm/interpreter.check
index ce3c8062d7..9a2162a906 100644
--- a/test/files/jvm/interpreter.check
+++ b/test/files/jvm/interpreter.check
@@ -353,7 +353,7 @@ defined class Term
scala> def f(e: Exp) = e match { // non-exhaustive warning here
case _:Fact => 3
}
-<console>:22: warning: match may not be exhaustive.
+<console>:18: warning: match may not be exhaustive.
It would fail on the following inputs: Exp(), Term()
def f(e: Exp) = e match { // non-exhaustive warning here
^
diff --git a/test/files/run/repl-classbased.check b/test/files/run/repl-classbased.check
new file mode 100644
index 0000000000..e11fc170e5
--- /dev/null
+++ b/test/files/run/repl-classbased.check
@@ -0,0 +1,23 @@
+
+scala> case class K(s: String)
+defined class K
+
+scala> class C { implicit val k: K = K("OK?"); override def toString = s"C($k)" }
+defined class C
+
+scala> val c = new C
+c: C = C(K(OK?))
+
+scala> import c.k
+import c.k
+
+scala> implicitly[K]
+res0: K = K(OK?)
+
+scala> val k = 42
+k: Int = 42
+
+scala> k // was K(OK?)
+res1: Int = 42
+
+scala> :quit
diff --git a/test/files/run/repl-classbased.scala b/test/files/run/repl-classbased.scala
new file mode 100644
index 0000000000..595e123159
--- /dev/null
+++ b/test/files/run/repl-classbased.scala
@@ -0,0 +1,22 @@
+
+import scala.tools.partest.ReplTest
+import scala.tools.nsc.Settings
+
+//SI-9740
+object Test extends ReplTest {
+ override def transformSettings(s: Settings): Settings = {
+ s.Yreplclassbased.value = true
+ s
+ }
+
+ def code =
+ """
+case class K(s: String)
+class C { implicit val k: K = K("OK?"); override def toString = s"C($k)" }
+val c = new C
+import c.k
+implicitly[K]
+val k = 42
+k // was K(OK?)
+ """
+}
diff --git a/test/files/run/repl-javap-app.check b/test/files/run/repl-javap-app.check
index bace9534da..e69de29bb2 100644
--- a/test/files/run/repl-javap-app.check
+++ b/test/files/run/repl-javap-app.check
@@ -1,60 +0,0 @@
-#partest java6
-Welcome to Scala
-Type in expressions for evaluation. Or try :help.
-
-scala> :javap -app MyApp$
-public final void delayedEndpoint$MyApp$1();
- Code:
- Stack=2, Locals=1, Args_size=1
- 0: getstatic #XX; //Field scala/Console$.MODULE$:Lscala/Console$;
- 3: ldc #XX; //String Hello, delayed world.
- 5: invokevirtual #XX; //Method scala/Console$.println:(Ljava/lang/Object;)V
- 8: return
- LocalVariableTable:
- Start Length Slot Name Signature
- 0 9 0 this LMyApp$;
-
-scala> :quit
-#partest java7
-Welcome to Scala
-Type in expressions for evaluation. Or try :help.
-
-scala> :javap -app MyApp$
- public final void delayedEndpoint$MyApp$1();
- flags: ACC_PUBLIC, ACC_FINAL
- Code:
- stack=2, locals=1, args_size=1
- 0: getstatic #XX // Field scala/Console$.MODULE$:Lscala/Console$;
- 3: ldc #XX // String Hello, delayed world.
- 5: invokevirtual #XX // Method scala/Console$.println:(Ljava/lang/Object;)V
- 8: return
- LocalVariableTable:
- Start Length Slot Name Signature
- 0 9 0 this LMyApp$;
- LineNumberTable:
- line 5: 0
-}
-
-scala> :quit
-#partest java8
-Welcome to Scala
-Type in expressions for evaluation. Or try :help.
-
-scala> :javap -app MyApp$
- public final void delayedEndpoint$MyApp$1();
- descriptor: ()V
- flags: ACC_PUBLIC, ACC_FINAL
- Code:
- stack=2, locals=1, args_size=1
- 0: getstatic #XX // Field scala/Console$.MODULE$:Lscala/Console$;
- 3: ldc #XX // String Hello, delayed world.
- 5: invokevirtual #XX // Method scala/Console$.println:(Ljava/lang/Object;)V
- 8: return
- LocalVariableTable:
- Start Length Slot Name Signature
- 0 9 0 this LMyApp$;
- LineNumberTable:
- line 5: 0
-}
-
-scala> :quit
diff --git a/test/files/run/repl-javap-app.scala b/test/files/run/repl-javap-app.scala
index ad6076c2d5..f7e3baa2a1 100644
--- a/test/files/run/repl-javap-app.scala
+++ b/test/files/run/repl-javap-app.scala
@@ -8,14 +8,11 @@ object MyApp extends App {
object Test extends ReplTest {
def code = ":javap -app MyApp$"
- override def welcoming = true
-
- // The constant pool indices are not the same for GenASM / GenBCode, so
- // replacing the exact numbers by XX.
- lazy val hasConstantPoolRef = """(.*)(#\d\d)(.*)""".r
-
- override def normalize(s: String) = s match {
- case hasConstantPoolRef(start, ref, end) => start + "#XX" + end
- case _ => super.normalize(s)
+ override def show() = {
+ val coded = "Code:"
+ val strung = "String Hello, delayed world."
+ val lines = eval().toList
+ assert (lines.count(s => s.endsWith(coded)) == 1)
+ assert (lines.count(s => s.endsWith(strung)) == 1)
}
}
diff --git a/test/files/run/t7319.check b/test/files/run/t7319.check
index 4d8429e8f2..31923e7119 100644
--- a/test/files/run/t7319.check
+++ b/test/files/run/t7319.check
@@ -15,21 +15,21 @@ warning: there was one feature warning; re-run with -feature for details
convert: [F[X <: F[X]]](builder: F[_ <: F[_]])Int
scala> convert(Some[Int](0))
-<console>:16: error: no type parameters for method convert: (builder: F[_ <: F[_]])Int exist so that it can be applied to arguments (Some[Int])
+<console>:15: error: no type parameters for method convert: (builder: F[_ <: F[_]])Int exist so that it can be applied to arguments (Some[Int])
--- because ---
argument expression's type is not compatible with formal parameter type;
found : Some[Int]
required: ?F[_$1] forSome { type _$1 <: ?F[_$2] forSome { type _$2 } }
convert(Some[Int](0))
^
-<console>:16: error: type mismatch;
+<console>:15: error: type mismatch;
found : Some[Int]
required: F[_ <: F[_]]
convert(Some[Int](0))
^
scala> Range(1,2).toArray: Seq[_]
-<console>:15: error: polymorphic expression cannot be instantiated to expected type;
+<console>:14: error: polymorphic expression cannot be instantiated to expected type;
found : [B >: Int]Array[B]
required: Seq[_]
Range(1,2).toArray: Seq[_]