summaryrefslogtreecommitdiff
path: root/test/files/run/repl-inline.scala
diff options
context:
space:
mode:
authorJason Zaugg <jzaugg@gmail.com>2016-11-18 18:09:28 +1000
committerJason Zaugg <jzaugg@gmail.com>2016-11-28 15:57:31 +1000
commit753e848f3d6ac453871450161292139902669695 (patch)
treee2401d5b2f734a5fd77015f8104382abf120503b /test/files/run/repl-inline.scala
parent690ba800ec04f05c0f5e5e369863ab5b9578d42f (diff)
downloadscala-753e848f3d6ac453871450161292139902669695.tar.gz
scala-753e848f3d6ac453871450161292139902669695.tar.bz2
scala-753e848f3d6ac453871450161292139902669695.zip
SI-8779 Enable inlining of code within a REPL session
The REPL has a long running instance of Global which outputs classfiles by default to a VirtualDirectory. The inliner did not find any of these class files when compiling calls to methods defined in previous runs (ie, previous lines of input.) This commit: - Adds a hook to augment the classpath that the optimizer searches, and uses this in the REPL to add the output directory - Fixes the implementation of `findClassFile` in VirtualDirectory, which doesn't seem to have been used in anger before. I've factored out some common code into a new method on `AbstractFile`. - Fixes a similar problem getSubDir reported by Li Haoyi - Adds missing unit test coverage. This also fixes a bug in REPL autocompletion for types defined in packages >= 2 level deep (with the `:paste -raw` command). I've added a test for this case.
Diffstat (limited to 'test/files/run/repl-inline.scala')
-rw-r--r--test/files/run/repl-inline.scala21
1 files changed, 21 insertions, 0 deletions
diff --git a/test/files/run/repl-inline.scala b/test/files/run/repl-inline.scala
new file mode 100644
index 0000000000..5a5f205ad8
--- /dev/null
+++ b/test/files/run/repl-inline.scala
@@ -0,0 +1,21 @@
+import scala.tools.nsc._
+
+object Test {
+ val testCode = """
+def callerOfCaller = Thread.currentThread.getStackTrace.drop(2).head.getMethodName
+def g = callerOfCaller
+def h = g
+assert(h == "g", h)
+@inline def g = callerOfCaller
+def h = g
+assert(h == "h", h)
+ """
+
+ def main(args: Array[String]) {
+ val settings = new Settings()
+ settings.processArgumentString("-opt:l:classpath")
+ settings.usejavacp.value = true
+ val repl = new interpreter.IMain(settings)
+ testCode.linesIterator.foreach(repl.interpret(_))
+ }
+}