From 86ae2f95ce33ef22f9c9ad40d6a966fbef7d352f Mon Sep 17 00:00:00 2001 From: Som Snytt Date: Thu, 7 Apr 2016 12:32:40 -0700 Subject: SI-9740 Repl import fix -Yrepl-class-based Under `-Yrepl-class-based`, templating must follow the same scoping as under traditional object-based. The new test shows a typical case where two values of the same simple name must be imported in different scopes. --- src/repl/scala/tools/nsc/interpreter/Imports.scala | 35 +++++++------ src/repl/scala/tools/nsc/interpreter/package.scala | 9 ++-- test/files/jvm/interpreter.check | 2 +- test/files/run/repl-classbased.check | 23 +++++++++ test/files/run/repl-classbased.scala | 22 ++++++++ test/files/run/repl-javap-app.check | 60 ---------------------- test/files/run/repl-javap-app.scala | 15 +++--- test/files/run/t7319.check | 6 +-- 8 files changed, 80 insertions(+), 92 deletions(-) create mode 100644 test/files/run/repl-classbased.check create mode 100644 test/files/run/repl-classbased.scala 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 } -:22: warning: match may not be exhaustive. +: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)) -:16: error: no type parameters for method convert: (builder: F[_ <: F[_]])Int exist so that it can be applied to arguments (Some[Int]) +: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)) ^ -:16: error: type mismatch; +:15: error: type mismatch; found : Some[Int] required: F[_ <: F[_]] convert(Some[Int](0)) ^ scala> Range(1,2).toArray: Seq[_] -:15: error: polymorphic expression cannot be instantiated to expected type; +:14: error: polymorphic expression cannot be instantiated to expected type; found : [B >: Int]Array[B] required: Seq[_] Range(1,2).toArray: Seq[_] -- cgit v1.2.3 From 83864872d7b642520fdf522fd300151d8bc22da4 Mon Sep 17 00:00:00 2001 From: Jason Zaugg Date: Tue, 10 May 2016 15:07:45 +1000 Subject: Eliminate major sources of daily noise in SBT build. - Intercept incorrect "binary conflict" warning issued by SBT. Fixes https://github.com/scala/scala-dev/issues/100 - Bump to a new version of pantsbuild/jarjar to fix an incompatibility with Java 8 parameter names in class files, which we run into on the 2.12.x branch. See: https://github.com/pantsbuild/jarjar/pull/19 - Disable info level logging for dependency resolve/download. --- build.sbt | 10 +++++++--- project/Quiet.scala | 33 +++++++++++++++++++++++++++++++++ project/plugins.sbt | 2 +- 3 files changed, 41 insertions(+), 4 deletions(-) create mode 100644 project/Quiet.scala diff --git a/build.sbt b/build.sbt index 5b9036deb4..e2cf40dbbc 100644 --- a/build.sbt +++ b/build.sbt @@ -210,7 +210,9 @@ lazy val commonSettings = clearSourceAndResourceDirectories ++ publishSettings + // Don't log process output (e.g. of forked `compiler/runMain ...Main`), just pass it // directly to stdout - outputStrategy in run := Some(StdoutOutput) + outputStrategy in run := Some(StdoutOutput), + Quiet.silenceScalaBinaryVersionWarning, + Quiet.silenceIvyUpdateInfoLogging ) /** Extra post-processing for the published POM files. These are needed to create POMs that @@ -475,6 +477,7 @@ lazy val replJlineEmbedded = Project("repl-jline-embedded", file(".") / "target" }), publishArtifact := false, connectInput in run := true + ) .dependsOn(replJline) @@ -677,8 +680,9 @@ lazy val root = (project in file(".")) publishArtifact := false, publish := {}, publishLocal := {}, - commands ++= ScriptCommands.all - ) + commands ++= ScriptCommands.all, + Quiet.silenceIvyUpdateInfoLogging +) .aggregate(library, forkjoin, reflect, compiler, interactive, repl, replJline, replJlineEmbedded, scaladoc, scalap, actors, partestExtras, junit, libraryAll, scalaDist).settings( sources in Compile := Seq.empty, diff --git a/project/Quiet.scala b/project/Quiet.scala new file mode 100644 index 0000000000..de30ebe6ab --- /dev/null +++ b/project/Quiet.scala @@ -0,0 +1,33 @@ +import sbt._ +import Keys._ + +object Quiet { + // Workaround SBT issue described: + // + // https://github.com/scala/scala-dev/issues/100 + def silenceScalaBinaryVersionWarning = ivyConfiguration := { + ivyConfiguration.value match { + case c: InlineIvyConfiguration => + val delegate = c.log + val logger = new Logger { + override def trace(t: => Throwable): Unit = delegate.trace(t) + override def log(level: sbt.Level.Value, message: => String): Unit = { + level match { + case sbt.Level.Warn => + val message0 = message + val newLevel = if (message.contains("differs from Scala binary version in project")) + delegate.log(sbt.Level.Debug, message) + else + delegate.log(level, message) + case _ => delegate.log(level, message) + } + } + override def success(message: => String): Unit = delegate.success(message) + } + new InlineIvyConfiguration(c.paths, c.resolvers, c.otherResolvers, c.moduleConfigurations, c.localOnly, c.lock, c.checksums, c.resolutionCacheDir, c.updateOptions, logger) + case x => x + } + } + + def silenceIvyUpdateInfoLogging = logLevel in update := Level.Warn +} diff --git a/project/plugins.sbt b/project/plugins.sbt index 2d91c2306b..46203565b4 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1,6 +1,6 @@ libraryDependencies += "org.apache.commons" % "commons-lang3" % "3.3.2" -libraryDependencies += "org.pantsbuild" % "jarjar" % "1.6.0" +libraryDependencies += "org.pantsbuild" % "jarjar" % "1.6.3" libraryDependencies += "biz.aQute" % "bndlib" % "1.50.0" -- cgit v1.2.3 From 71a5bdaf57f90b46a6bed8af28deebb1174318c7 Mon Sep 17 00:00:00 2001 From: Adriaan Moors Date: Fri, 18 Mar 2016 14:55:23 -0700 Subject: [backport] sbt build targets build/ It avoids confusion with existing test/partest scripts that test the compiler in build/, while sbt it targeting build-sbt/. --- build.sbt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/build.sbt b/build.sbt index e2cf40dbbc..82d23fed90 100644 --- a/build.sbt +++ b/build.sbt @@ -4,8 +4,8 @@ * What you see below is very much work-in-progress. The following features are implemented: * - Compiling all classses for the compiler and library ("compile" in the respective subprojects) * - Running JUnit tests ("test") and partest ("test/it:test") - * - Creating build-sbt/quick with all compiled classes and launcher scripts ("dist/mkQuick") - * - Creating build-sbt/pack with all JARs and launcher scripts ("dist/mkPack") + * - Creating build/quick with all compiled classes and launcher scripts ("dist/mkQuick") + * - Creating build/pack with all JARs and launcher scripts ("dist/mkPack") * - Building all scaladoc sets ("doc") * - Publishing ("publishDists" and standard sbt tasks like "publish" and "publishLocal") * @@ -771,8 +771,8 @@ def configureAsForkOfJavaProject(project: Project): Project = { lazy val buildDirectory = settingKey[File]("The directory where all build products go. By default ./build") lazy val mkBin = taskKey[Seq[File]]("Generate shell script (bash or Windows batch).") -lazy val mkQuick = taskKey[Unit]("Generate a full build, including scripts, in build-sbt/quick") -lazy val mkPack = taskKey[Unit]("Generate a full build, including scripts, in build-sbt/pack") +lazy val mkQuick = taskKey[Unit]("Generate a full build, including scripts, in build/quick") +lazy val mkPack = taskKey[Unit]("Generate a full build, including scripts, in build/pack") // Defining these settings is somewhat redundant as we also redefine settings that depend on them. // However, IntelliJ's project import works better when these are set correctly. @@ -831,7 +831,7 @@ def generateServiceProviderResources(services: (String, String)*): Setting[_] = } }.taskValue -buildDirectory in ThisBuild := (baseDirectory in ThisBuild).value / "build-sbt" +buildDirectory in ThisBuild := (baseDirectory in ThisBuild).value / "build" // Add tab completion to partest commands += Command("partest")(_ => PartestUtil.partestParser((baseDirectory in ThisBuild).value, (baseDirectory in ThisBuild).value / "test")) { (state, parsed) => -- cgit v1.2.3