Skip to content

Commit

Permalink
SIP-27 Tweak and test wildstar in REPL
Browse files Browse the repository at this point in the history
  • Loading branch information
dwijnand committed Jan 8, 2017
1 parent c95e6bb commit d55bad8
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/compiler/scala/tools/nsc/ast/parser/Scanners.scala
Original file line number Diff line number Diff line change
Expand Up @@ -392,8 +392,11 @@ trait Scanners extends ScannersCommon {
// then it is a trailing comma and is ignored
val saved = new ScannerData {} copyFrom this
fetchToken()
if (token != RPAREN && token != RBRACKET && token != RBRACE || !afterLineEnd())
this copyFrom saved
if (afterLineEnd() && (token == RPAREN || token == RBRACKET || token == RBRACE)) {
/* skip the trailing comma */
} else if (token == EOF) { // e.g. when the REPL is parsing "val List(x, y, _*,"
/* skip the trailing comma */
} else this copyFrom saved
}

// print("["+this+"]")
Expand Down
4 changes: 4 additions & 0 deletions test/files/pos/trailing-commas.scala
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ trait SimplePattern {
case List(1, 2, _ @ _*,
) => 1
}

// test varargs in patterns
val List(x, y, _*,
) = 42 :: 17 :: Nil
}

trait ImportSelectors {
Expand Down
9 changes: 9 additions & 0 deletions test/files/run/trailing-commas.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

scala> // test varargs in patterns

scala> val List(x, y, _*,
) = 42 :: 17 :: Nil
x: Int = 42
y: Int = 17

scala> :quit
7 changes: 7 additions & 0 deletions test/files/run/trailing-commas.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
object Test extends scala.tools.partest.ReplTest {
def code = """
// test varargs in patterns
val List(x, y, _*,
) = 42 :: 17 :: Nil
"""
}

0 comments on commit d55bad8

Please sign in to comment.