summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Zaugg <jzaugg@gmail.com>2016-11-23 15:54:03 +1000
committerJason Zaugg <jzaugg@gmail.com>2016-11-28 15:57:54 +1000
commit1b2cd1be9790bf9c14fd68c78f784d6cb4f7c907 (patch)
treefaf895234a20def5d929a6e476f1d9a4a1d4b488
parent753e848f3d6ac453871450161292139902669695 (diff)
downloadscala-1b2cd1be9790bf9c14fd68c78f784d6cb4f7c907.tar.gz
scala-1b2cd1be9790bf9c14fd68c78f784d6cb4f7c907.tar.bz2
scala-1b2cd1be9790bf9c14fd68c78f784d6cb4f7c907.zip
Support inlining under -Yrepl-class-based REPL
By marking the wrapper classes as sealed, the inliner will be able to assume finality of defs introduces in the REPL without requiring the user to mark them as `final`, which is an odd thing to do in single line of REPL input.
-rw-r--r--src/repl/scala/tools/nsc/interpreter/IMain.scala2
-rw-r--r--test/files/run/repl-inline.check5
-rw-r--r--test/files/run/repl-inline.scala18
-rw-r--r--test/files/run/t7747-repl.check6
4 files changed, 21 insertions, 10 deletions
diff --git a/src/repl/scala/tools/nsc/interpreter/IMain.scala b/src/repl/scala/tools/nsc/interpreter/IMain.scala
index 65f2c95f73..99acc34811 100644
--- a/src/repl/scala/tools/nsc/interpreter/IMain.scala
+++ b/src/repl/scala/tools/nsc/interpreter/IMain.scala
@@ -889,7 +889,7 @@ class IMain(initialSettings: Settings, protected val out: JPrintWriter) extends
}
class ClassBasedWrapper extends Wrapper {
- def preambleHeader = "class %s extends _root_.java.io.Serializable { "
+ def preambleHeader = "sealed class %s extends _root_.java.io.Serializable { "
/** Adds an object that instantiates the outer wrapping class. */
def postamble = s"""
diff --git a/test/files/run/repl-inline.check b/test/files/run/repl-inline.check
index 3b29f4d047..db729a67dd 100644
--- a/test/files/run/repl-inline.check
+++ b/test/files/run/repl-inline.check
@@ -4,3 +4,8 @@ g: String
h: String
g: String
h: String
+callerOfCaller: String
+g: String
+h: String
+g: String
+h: String
diff --git a/test/files/run/repl-inline.scala b/test/files/run/repl-inline.scala
index 5a5f205ad8..260ed28a4f 100644
--- a/test/files/run/repl-inline.scala
+++ b/test/files/run/repl-inline.scala
@@ -1,7 +1,8 @@
import scala.tools.nsc._
object Test {
- val testCode = """
+ val testCode =
+ """
def callerOfCaller = Thread.currentThread.getStackTrace.drop(2).head.getMethodName
def g = callerOfCaller
def h = g
@@ -12,10 +13,15 @@ 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(_))
+ def test(f: Settings => Unit): Unit = {
+ val settings = new Settings()
+ settings.processArgumentString("-opt:l:classpath")
+ f(settings)
+ settings.usejavacp.value = true
+ val repl = new interpreter.IMain(settings)
+ testCode.linesIterator.foreach(repl.interpret(_))
+ }
+ test(_ => ())
+ test(_.Yreplclassbased.value = true)
}
}
diff --git a/test/files/run/t7747-repl.check b/test/files/run/t7747-repl.check
index 621a70205e..ab37da5722 100644
--- a/test/files/run/t7747-repl.check
+++ b/test/files/run/t7747-repl.check
@@ -246,12 +246,12 @@ scala> case class Bingo()
defined class Bingo
scala> List(BippyBups(), PuppyPups(), Bingo()) // show
-class $read extends _root_.java.io.Serializable {
+sealed class $read extends _root_.java.io.Serializable {
def <init>() = {
super.<init>;
()
};
- class $iw extends _root_.java.io.Serializable {
+ sealed class $iw extends _root_.java.io.Serializable {
def <init>() = {
super.<init>;
()
@@ -262,7 +262,7 @@ class $read extends _root_.java.io.Serializable {
import $line45.$read.INSTANCE.$iw.$iw.PuppyPups;
import $line46.$read.INSTANCE.$iw.$iw.Bingo;
import $line46.$read.INSTANCE.$iw.$iw.Bingo;
- class $iw extends _root_.java.io.Serializable {
+ sealed class $iw extends _root_.java.io.Serializable {
def <init>() = {
super.<init>;
()