Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit a80df17

Browse files
Fix #6969: Add empty case class params check. Add test. Fix existing tests.
1 parent 36707c7 commit a80df17

13 files changed

+48
-19
lines changed

‎compiler/src/dotty/tools/dotc/ast/Desugar.scala‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ object desugar {
446446
val constrTparams = impliedTparams.map(toDefParam(_, keepAnnotations = false))
447447
val constrVparamss =
448448
if (originalVparamss.isEmpty) { // ensure parameter list is non-empty
449-
if (isCaseClass&& originalTparams.isEmpty)
449+
if (isCaseClass)
450450
ctx.error(CaseClassMissingParamList(cdef), namePos)
451451
ListOfNil
452452
} else if (isCaseClass && originalVparamss.head.exists(_.mods.isOneOf(GivenOrImplicit))) {

‎tests/neg/EmptyCaseClassParams.check‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
-- [E004] Syntax Error: tests/neg/EmptyCaseClassParams.scala:2:13 ------------------------------------------------------
2+
2 | case class A[T] // error
3+
| ^
4+
| A case class must have at least one parameter list
5+
6+
longer explanation available when compiling with `-explain`
7+
-- [E004] Syntax Error: tests/neg/EmptyCaseClassParams.scala:5:13 ------------------------------------------------------
8+
5 | case class B[T] // error
9+
| ^
10+
| A case class must have at least one parameter list
11+
12+
longer explanation available when compiling with `-explain`
13+
-- [E004] Syntax Error: tests/neg/EmptyCaseClassParams.scala:9:9 -------------------------------------------------------
14+
9 | case D[T] extends Foo[T] // error
15+
| ^
16+
| A case class must have at least one parameter list
17+
18+
longer explanation available when compiling with `-explain`

‎tests/neg/EmptyCaseClassParams.scala‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
object EmptyCaseClassParams{
2+
case class A[T] // error
3+
4+
class C
5+
case class B[T] // error
6+
extends C
7+
8+
enum Foo[T]{
9+
case D[T] extends Foo[T] // error
10+
}
11+
}

‎tests/neg/derive-eq.scala‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ enum Lst[T] derives Eql {
99
case Nil()
1010
}
1111

12-
case class Triple[S, T, U] derives Eql
12+
case class Triple[S, T, U]() derives Eql
1313

1414

1515
object Test extends App {

‎tests/neg/enumsAccess.scala‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ object test1 {
55
enum E4 {
66
case C1(x: INT) // error: illegal reference
77
case C2(x: Int = defaultX) // error: illegal reference
8-
case C3[T <: INT] // error: illegal reference
8+
case C3[T <: INT]() // error: illegal reference
99
}
1010

1111
object E4 {
@@ -24,7 +24,7 @@ object test2 {
2424
enum E5 {
2525
case C1(x: INT) // ok
2626
case C2(x: Int = defaultX) // ok
27-
case C3[T <: INT] // ok
27+
case C3[T <: INT]() // ok
2828
}
2929
}
3030

@@ -39,7 +39,7 @@ object test3 {
3939
enum E5 {
4040
case C1(x: INT) // ok
4141
case C2(x: Int = defaultX)// ok
42-
case C3[T <: INT] // ok
42+
case C3[T <: INT]() // ok
4343
}
4444
}
4545

@@ -48,7 +48,7 @@ object test4 {
4848
enum E5 {
4949
case C1(x: INT) // error: illegal reference
5050
case C2(x: Int = defaultX) // error: illegal reference
51-
case C3[T <: INT] // error: illegal reference
51+
case C3[T <: INT]() // error: illegal reference
5252
}
5353

5454
import E5._
@@ -76,7 +76,7 @@ object test6 {
7676
import E5._
7777
enum E5[T](x: T) {
7878
case C3() extends E5[INT](defaultX) // ok
79-
case C4 extends E5[INT](defaultX) // ok
79+
case C4() extends E5[INT](defaultX) // ok
8080
}
8181

8282
object E5 {
@@ -90,7 +90,7 @@ object test7 {
9090
trait Arg
9191

9292
enum E(x: Arg) {
93-
case C extends E(this) // error: illegal reference to `this`
93+
case C() extends E(this) // error: illegal reference to `this`
9494
}
9595
object E extends Arg
9696
}

‎tests/neg/parser-stability-19.scala‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
object x0 {
2-
case class x0[] // error // error
2+
case class x0[]() // error // error
33
def x0( ) ] // error // error
44
def x0 ( x0:x0 ):x0.type = x1 x0 // error // error
55
// error

‎tests/neg/typeclass-derivation2.scala‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,10 @@ object TypeLevel {
101101
enum Shape {
102102

103103
/** A sum with alternative types `Alts` */
104-
case Cases[Alts <: Tuple]
104+
case Cases[Alts <: Tuple]()
105105

106106
/** A product type `T` with element types `Elems` */
107-
case Case[T, Elems <: Tuple]
107+
case Case[T, Elems <: Tuple]()
108108
}
109109

110110
/** Every generic derivation starts with a typeclass instance of this type.

‎tests/pos/gadt-GadtStlc.scala‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ object GadtStlc {
1010
// Var[M[W]]
1111
sealed trait Var[A]
1212
object VarW extends Var[W]
13-
case class VarM[A] extends Var[M[A]]
13+
case class VarM[A]() extends Var[M[A]]
1414

1515
// \s.e
1616
sealed trait Abs[S, E]

‎tests/pos/i4176-gadt.scala‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
object i4176 {
22
sealed trait TNat
33
case class TZero() extends TNat
4-
case class TSucc[N <: TNat] extends TNat
4+
case class TSucc[N <: TNat]() extends TNat
55

66
object TNatSum {
77
sealed trait TSum[M, N, R]

‎tests/pos/i4316.scala‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
object Test {
22

3-
case class Bar[A]
3+
case class Bar[A]()
44

55
def meth[A](consumer: A => Unit, s: Bar[A]): Unit = {
66
s match {

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /