summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2011-07-03 22:01:46 +0000
committerPaul Phillips <paulp@improving.org>2011-07-03 22:01:46 +0000
commitf34c836cb67ed4c03b03218dff0a048466cbf13f (patch)
tree85762cb8af6fc79b703bb15a0918b32f2f44130a
parent552d7aa113dfda5c33c909b4a7874799a7ff1a3e (diff)
downloadscala-f34c836cb67ed4c03b03218dff0a048466cbf13f.tar.gz
scala-f34c836cb67ed4c03b03218dff0a048466cbf13f.tar.bz2
scala-f34c836cb67ed4c03b03218dff0a048466cbf13f.zip
Looking forward to working positions.
-rw-r--r--src/compiler/scala/tools/nsc/interpreter/IMain.scala15
-rw-r--r--test/files/run/repl-parens.check11
-rw-r--r--test/files/run/repl-parens.scala1
3 files changed, 18 insertions, 9 deletions
diff --git a/src/compiler/scala/tools/nsc/interpreter/IMain.scala b/src/compiler/scala/tools/nsc/interpreter/IMain.scala
index 467805fe36..dd147d7fff 100644
--- a/src/compiler/scala/tools/nsc/interpreter/IMain.scala
+++ b/src/compiler/scala/tools/nsc/interpreter/IMain.scala
@@ -467,15 +467,20 @@ class IMain(val settings: Settings, protected val out: JPrintWriter) extends Imp
else {
// The position of the last tree
val lastpos0 = earliestPosition(trees.last)
- // Oh boy, the parser throws away parens so "(2+2)" is mispositioned.
- // So until we can fix the parser we'll have to go trawling.
- val adjustment = ((content take lastpos0).reverse takeWhile { ch =>
- ch.isWhitespace || ch == '('
- }).length
+ // Oh boy, the parser throws away parens so "(2+2)" is mispositioned,
+ // with increasingly hard to decipher positions as we move on to "() => 5",
+ // (x: Int) => x + 1, and more. So I abandon attempts to finesse and just
+ // look for semicolons and newlines, which I'm sure is also buggy.
+ val (raw1, raw2) = content splitAt lastpos0
+ repldbg("[raw] " + raw1 + " <---> " + raw2)
+
+ val adjustment = (raw1.reverse takeWhile (ch => (ch != ';') && (ch != '\n'))).size
val lastpos = lastpos0 - adjustment
// the source code split at the laboriously determined position.
val (l1, l2) = content splitAt lastpos
+ repldbg("[adj] " + l1 + " <---> " + l2)
+
val prefix = if (l1.trim == "") "" else l1 + ";\n"
// Note to self: val source needs to have this precise structure so that
// error messages print the user-submitted part without the "val res0 = " part.
diff --git a/test/files/run/repl-parens.check b/test/files/run/repl-parens.check
index f41c2e74bd..2f56e5ddd4 100644
--- a/test/files/run/repl-parens.check
+++ b/test/files/run/repl-parens.check
@@ -36,16 +36,19 @@ scala>
scala> 55 ; ((2 + 2)) ; (1, 2, 3)
res10: (Int, Int, Int) = (1,2,3)
+scala> 55 ; (x: Int) => x + 1 ; () => ((5))
+res11: () => Int = <function0>
+
scala>
scala> () => 5
-res11: () => Int = <function0>
+res12: () => Int = <function0>
scala> 55 ; () => 5
-res12: () => Int = <function0>
+res13: () => Int = <function0>
scala> () => { class X ; new X }
-res13: () => java.lang.Object with ScalaObject = <function0>
+res14: () => java.lang.Object with ScalaObject = <function0>
scala>
@@ -53,6 +56,6 @@ scala> def foo(x: Int)(y: Int)(z: Int) = x+y+z
foo: (x: Int)(y: Int)(z: Int)Int
scala> foo(5)(10)(15)+foo(5)(10)(15)
-res14: Int = 60
+res15: Int = 60
scala>
diff --git a/test/files/run/repl-parens.scala b/test/files/run/repl-parens.scala
index 081db3606a..1baa9c37a5 100644
--- a/test/files/run/repl-parens.scala
+++ b/test/files/run/repl-parens.scala
@@ -14,6 +14,7 @@ object Test extends ReplTest {
((((2 + 2)), ((2 + 2)), 2).productIterator ++ Iterator(3) mkString)
55 ; ((2 + 2)) ; (1, 2, 3)
+55 ; (x: Int) => x + 1 ; () => ((5))
() => 5
55 ; () => 5