Skip to content

Add tests for trailing comma parsing #14742

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions tests/neg/t11900.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
-- Error: tests/neg/t11900.scala:44:16 ---------------------------------------------------------------------------------
44 | a => a + 1, // error: weird comma
| ^
| end of statement expected but ',' found
-- Error: tests/neg/t11900.scala:48:16 ---------------------------------------------------------------------------------
48 | println("a"), // error: weird comma
| ^
| end of statement expected but ',' found
-- Error: tests/neg/t11900.scala:52:16 ---------------------------------------------------------------------------------
52 | println("b"), // error: weird comma
| ^
| end of statement expected but ',' found
-- [E032] Syntax Error: tests/neg/t11900.scala:64:8 --------------------------------------------------------------------
64 | _*, // error
| ^
| pattern expected
|
| longer explanation available when compiling with `-explain`
79 changes: 79 additions & 0 deletions tests/neg/t11900.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test pulled over from scala/scala#8780.

trait t11900 {
// cf pos/trailing-commas
//
import scala.collection.{
immutable,
mutable,
}

def h[A,
]: List[A] = Nil

def u(
x: Int,
y: Int,
)(using List[Int],
Set[Int],
)(using l: List[Int],
s : Set[Int],
): Int = 1

def g = List(
1,
2,
3,
)

def star =
List(1, 2, 3, 4, 5) match {
case List(
1,
2,
3,
) => false
case List(
1,
2,
_*,
) => true
}

def f =
List(1, 2, 3).map {
a => a + 1, // error: weird comma
}

class A() {
println("a"), // error: weird comma
}

def b() = {
println("b"), // error: weird comma
}

def starcrossed =
List(1, 2, 3, 4, 5) match {
case List(
1,
2,
3,
) => false
case List(
1,
_*, // error
2,
) => true
}

def p(p: (Int,
String,
)
): Unit

def q: (Int,
String,
)

val z = 42
}
24 changes: 24 additions & 0 deletions tests/neg/trailingCommas.scala
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,27 @@ object `package` {
case class Foo(foo: Any)
case class Bar(foo: Any)
}

// Unparenthesized lists
trait Deriv1[T]
object Deriv1 {
def derived[T]: Deriv1[T] = new Deriv1[T] {}
}

trait Deriv2[T]
object Deriv2 {
def derived[T]: Deriv2[T] = new Deriv2[T] {}
}

class Derives1 derives Deriv1, Deriv2,
object End // error: an identifier expected, but 'object' found

class Derives2 derives Deriv1,
Deriv2,
object End2 // error: an identifier expected, but 'object' found

val a,
b,
c,
= (1, 2, 3) // error
val x, y, z, = (1, 2, 3) // error
19 changes: 19 additions & 0 deletions tests/pos/comma-separated.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
trait Bar[T]
object Bar {
def derived[T]: Bar[T] = new Bar[T] {}
}

trait Baz[T]
object Baz {
def derived[T]: Baz[T] = new Baz[T] {}
}

class Foo derives Bar, Baz

class Foo2 derives Bar,
Baz

val x, y, z = (1, 2, 3)
val a,
b,
c = (1, 2, 3)