summaryrefslogtreecommitdiff
path: root/test/files/pos/trailing-commas.scala
blob: b9401fe49dd9acc5a3638c7865f4dadedd63de76 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
package foo

trait ArgumentExprs1 {
  def f(foo: Int, bar: String)(implicit ev0: Ev0, ev1: Ev1) = 1
  f(
    23,
    "bar",
  )(
    Ev0,
    Ev1,
  )

  // test arg exprs in the presence of varargs
  def g(x: Int, y: Int*) = 1
  g(1,2,
  )
  g(1,List(2, 3): _*,
  )
}

trait ArgumentExprs2 {
  class C(foo: Int, bar: String)(implicit ev0: Ev0, ev1: Ev1)
  new C(
    23,
    "bar",
  )(
    Ev0,
    Ev1,
  )
}

trait Params {
  def f(
    foo: Int,
    bar: String,
  )(implicit
    ev0: Ev0,
    ev1: Ev1,
  )
}

trait ClassParams {
  class C(
    foo: Int,
    bar: String,
  )(implicit
    ev0: Ev0,
    ev1: Ev1,
  )

  // test class params in the precense of varargs
  case class D(i: Int*,
  )
}

trait SimpleExpr1 {
  def f: (Int, String) = (
    23,
    "bar",
  )

  // the Tuple1 value case, the trailing comma is ignored so the type is Int and the value 23
  def g: Int = (
    23,
  )
}

trait TypeArgs {
  class C[A, B]
  def f: C[
    Int,
    String,
  ]
}

trait TypeParamClause {
  class C[
    A,
    B,
  ]
}

trait FunTypeParamClause {
  def f[
    A,
    B,
  ]
}

trait SimpleType {
  def f: (
    Int,
    String,
  )

  // the Tuple1 type case, the trailing comma is ignored so the type is Int and the value 23
  def g: (
    Int,
  ) = 23
}

trait FunctionArgTypes {
  def f: (
    Int,
    String,
  ) => Boolean
}

trait SimplePattern {
  val (
    foo,
    bar,
  ) = null: Any

  // test '@' syntax in patterns
  Some(1) match {
    case Some(x @ 1,
    ) => x
  }

  // test ': _*' syntax in patterns
  List(1, 2, 3) match {
    case List(1, 2, _ @ _*,
    ) => 1
  }

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

trait ImportSelectors {
  import foo.{
    Ev0,
    Ev1,
  }
}

trait Bindings {
  def g(f: (Int, String) => Boolean)

  g((
    foo,
    bar,
  ) => true)
}

// Import, ids, ValDcl, VarDcl, VarDef, PatDef use commas, but not inside paren, bracket or brace,
// so they don't support an optional trailing comma

// test utilities
object `package` {
  sealed trait Ev0; implicit object Ev0 extends Ev0
  sealed trait Ev1; implicit object Ev1 extends Ev1
}