Fixed a repl regression with parentheses handling, reminding me
we really need that honest parser phase which doesn't betray us with parentheses abandonment and dramatic desugarings. I'll promote it from page 14 to page 11. Closes #4661, no review. git-svn-id: http://lampsvn.epfl.ch/svn-repos/scala/scala/trunk@25050 5e8d7ff9-d8ef-0310-90f0-a4852d11357a
This commit is contained in:
parent
c1ef45e737
commit
daadd46d6d
|
@ -440,8 +440,15 @@ class IMain(val settings: Settings, protected val out: PrintWriter) extends Impo
|
|||
trees.last match {
|
||||
case _:Assign => // we don't want to include assignments
|
||||
case _:TermTree | _:Ident | _:Select => // ... but do want other unnamed terms.
|
||||
// The position of the last tree, and the source code split there.
|
||||
val lastpos = earliestPosition(trees.last)
|
||||
// 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 lastpos = {
|
||||
val adjustment = (content take lastpos0).reverse takeWhile (ch => ch.isWhitespace || ch == '(') length;
|
||||
lastpos0 - adjustment
|
||||
}
|
||||
// the source code split at the laboriously determined position.
|
||||
val (l1, l2) = content splitAt lastpos
|
||||
val prefix = if (l1.trim == "") "" else l1 + ";\n"
|
||||
val varName = if (synthetic) freshInternalVarName() else freshUserVarName()
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
Type in expressions to have them evaluated.
|
||||
Type :help for more information.
|
||||
|
||||
scala> (2)
|
||||
res0: Int = 2
|
||||
|
||||
scala> (2 + 2)
|
||||
res1: Int = 4
|
||||
|
||||
scala> ((2 + 2))
|
||||
res2: Int = 4
|
||||
|
||||
scala> (((2 + 2)), ((2 + 2)))
|
||||
res3: (Int, Int) = (4,4)
|
||||
|
||||
scala> (((2 + 2)), ((2 + 2)), 2)
|
||||
res4: (Int, Int, Int) = (4,4,2)
|
||||
|
||||
scala> ((((2 + 2)), ((2 + 2)), 2).productIterator ++ Iterator(3) mkString)
|
||||
res5: String = 4423
|
||||
|
||||
scala>
|
||||
|
||||
scala> 55 ; ((2 + 2)) ; (1, 2, 3)
|
||||
res6: (Int, Int, Int) = (1,2,3)
|
||||
|
||||
scala>
|
|
@ -0,0 +1,14 @@
|
|||
import scala.tools.partest.ReplTest
|
||||
|
||||
object Test extends ReplTest {
|
||||
def code = """
|
||||
(2)
|
||||
(2 + 2)
|
||||
((2 + 2))
|
||||
(((2 + 2)), ((2 + 2)))
|
||||
(((2 + 2)), ((2 + 2)), 2)
|
||||
((((2 + 2)), ((2 + 2)), 2).productIterator ++ Iterator(3) mkString)
|
||||
|
||||
55 ; ((2 + 2)) ; (1, 2, 3)
|
||||
""".trim
|
||||
}
|
Loading…
Reference in New Issue