diff options
author | Jens <DieBauer@users.noreply.github.com> | 2016-05-13 12:56:52 +0200 |
---|---|---|
committer | Lukas Rytz <lukas.rytz@typesafe.com> | 2016-05-13 12:56:52 +0200 |
commit | a33b0853452a625ac93eada7d5f265ed09f8e362 (patch) | |
tree | 7f8afbd7dafecdf839973d9d803a36c780476b28 | |
parent | f66a230f909858bf39ffdb154727157bc7cd54a5 (diff) | |
download | scala-a33b0853452a625ac93eada7d5f265ed09f8e362.tar.gz scala-a33b0853452a625ac93eada7d5f265ed09f8e362.tar.bz2 scala-a33b0853452a625ac93eada7d5f265ed09f8e362.zip |
Add check to scala REPL package to improve feedback about implicits (#5159)
When the repl is started with additional compiler flags that prevent implicits
being in scope (like -Yno-predef) the default message of implicits in scope
using :implicits stays the same.
This additional check will return the same message if predef is indeed in
scope and an adjusted message if Predef is not in scope.
-rw-r--r-- | src/repl/scala/tools/nsc/interpreter/package.scala | 12 | ||||
-rw-r--r-- | test/files/run/repl-implicits-nopredef.check | 5 | ||||
-rw-r--r-- | test/files/run/repl-implicits-nopredef.scala | 10 | ||||
-rw-r--r-- | test/files/run/repl-implicits.check | 5 | ||||
-rw-r--r-- | test/files/run/repl-implicits.scala | 5 |
5 files changed, 33 insertions, 4 deletions
diff --git a/src/repl/scala/tools/nsc/interpreter/package.scala b/src/repl/scala/tools/nsc/interpreter/package.scala index 56f1e65376..7de1dda15f 100644 --- a/src/repl/scala/tools/nsc/interpreter/package.scala +++ b/src/repl/scala/tools/nsc/interpreter/package.scala @@ -88,9 +88,6 @@ package object interpreter extends ReplConfig with ReplStrings { } } - if (filtered.isEmpty) - return "No implicits have been imported other than those in Predef." - filtered foreach { case (source, syms) => p("/* " + syms.size + " implicit members imported from " + source.fullName + " */") @@ -126,7 +123,14 @@ package object interpreter extends ReplConfig with ReplStrings { } p("") } - "" + + if (filtered.nonEmpty) + "" // side-effects above + else if (global.settings.nopredef || global.settings.noimports) + "No implicits have been imported." + else + "No implicits have been imported other than those in Predef." + } def kindCommandInternal(expr: String, verbose: Boolean): Unit = { diff --git a/test/files/run/repl-implicits-nopredef.check b/test/files/run/repl-implicits-nopredef.check new file mode 100644 index 0000000000..a849801bb4 --- /dev/null +++ b/test/files/run/repl-implicits-nopredef.check @@ -0,0 +1,5 @@ + +scala> :implicits +No implicits have been imported. + +scala> :quit
\ No newline at end of file diff --git a/test/files/run/repl-implicits-nopredef.scala b/test/files/run/repl-implicits-nopredef.scala new file mode 100644 index 0000000000..8a451b0c52 --- /dev/null +++ b/test/files/run/repl-implicits-nopredef.scala @@ -0,0 +1,10 @@ +import scala.tools.partest.ReplTest +import scala.tools.nsc.Settings + +object Test extends ReplTest { + override def transformSettings(settings: Settings): Settings = { + settings.nopredef.value = true + settings + } + def code = ":implicits" +} diff --git a/test/files/run/repl-implicits.check b/test/files/run/repl-implicits.check new file mode 100644 index 0000000000..6e80cc8799 --- /dev/null +++ b/test/files/run/repl-implicits.check @@ -0,0 +1,5 @@ + +scala> :implicits +No implicits have been imported other than those in Predef. + +scala> :quit
\ No newline at end of file diff --git a/test/files/run/repl-implicits.scala b/test/files/run/repl-implicits.scala new file mode 100644 index 0000000000..ca8e16e683 --- /dev/null +++ b/test/files/run/repl-implicits.scala @@ -0,0 +1,5 @@ +import scala.tools.partest.ReplTest + +object Test extends ReplTest { + def code = ":implicits" +} |