Skip to content

Add empty case class params check. Add test. #6982

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
Aug 7, 2019
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
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/ast/Desugar.scala
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ object desugar {
val constrTparams = impliedTparams.map(toDefParam(_, keepAnnotations = false))
val constrVparamss =
if (originalVparamss.isEmpty) { // ensure parameter list is non-empty
if (isCaseClass && originalTparams.isEmpty)
if (isCaseClass)
ctx.error(CaseClassMissingParamList(cdef), namePos)
ListOfNil
} else if (isCaseClass && originalVparamss.head.exists(_.mods.isOneOf(GivenOrImplicit))) {
Expand Down
18 changes: 18 additions & 0 deletions tests/neg/EmptyCaseClassParams.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
-- [E004] Syntax Error: tests/neg/EmptyCaseClassParams.scala:2:13 ------------------------------------------------------
2 | case class A[T] // error
| ^
| A case class must have at least one parameter list

longer explanation available when compiling with `-explain`
-- [E004] Syntax Error: tests/neg/EmptyCaseClassParams.scala:5:13 ------------------------------------------------------
5 | case class B[T] // error
| ^
| A case class must have at least one parameter list

longer explanation available when compiling with `-explain`
-- [E004] Syntax Error: tests/neg/EmptyCaseClassParams.scala:9:9 -------------------------------------------------------
9 | case D[T] extends Foo[T] // error
| ^
| A case class must have at least one parameter list

longer explanation available when compiling with `-explain`
11 changes: 11 additions & 0 deletions tests/neg/EmptyCaseClassParams.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
object EmptyCaseClassParams{
case class A[T] // error

class C
case class B[T] // error
extends C

enum Foo[T]{
case D[T] extends Foo[T] // error
}
}
2 changes: 1 addition & 1 deletion tests/neg/derive-eq.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ enum Lst[T] derives Eql {
case Nil()
}

case class Triple[S, T, U] derives Eql
case class Triple[S, T, U]() derives Eql


object Test extends App {
Expand Down
12 changes: 6 additions & 6 deletions tests/neg/enumsAccess.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ object test1 {
enum E4 {
case C1(x: INT) // error: illegal reference
case C2(x: Int = defaultX) // error: illegal reference
case C3[T <: INT] // error: illegal reference
case C3[T <: INT]() // error: illegal reference
}

object E4 {
Expand All @@ -24,7 +24,7 @@ object test2 {
enum E5 {
case C1(x: INT) // ok
case C2(x: Int = defaultX) // ok
case C3[T <: INT] // ok
case C3[T <: INT]() // ok
}
}

Expand All @@ -39,7 +39,7 @@ object test3 {
enum E5 {
case C1(x: INT) // ok
case C2(x: Int = defaultX)// ok
case C3[T <: INT] // ok
case C3[T <: INT]() // ok
}
}

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

import E5._
Expand Down Expand Up @@ -76,7 +76,7 @@ object test6 {
import E5._
enum E5[T](x: T) {
case C3() extends E5[INT](defaultX) // ok
case C4 extends E5[INT](defaultX) // ok
case C4() extends E5[INT](defaultX) // ok
}

object E5 {
Expand All @@ -90,7 +90,7 @@ object test7 {
trait Arg

enum E(x: Arg) {
case C extends E(this) // error: illegal reference to `this`
case C() extends E(this) // error: illegal reference to `this`
}
object E extends Arg
}
2 changes: 1 addition & 1 deletion tests/neg/parser-stability-19.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
object x0 {
case class x0[] // error // error
case class x0[]() // error // error
def x0( ) ] // error // error
def x0 ( x0:x0 ):x0.type = x1 x0 // error // error
// error
4 changes: 2 additions & 2 deletions tests/neg/typeclass-derivation2.scala
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,10 @@ object TypeLevel {
enum Shape {

/** A sum with alternative types `Alts` */
case Cases[Alts <: Tuple]
case Cases[Alts <: Tuple]()

/** A product type `T` with element types `Elems` */
case Case[T, Elems <: Tuple]
case Case[T, Elems <: Tuple]()
}

/** Every generic derivation starts with a typeclass instance of this type.
Expand Down
2 changes: 1 addition & 1 deletion tests/pos/gadt-GadtStlc.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ object GadtStlc {
// Var[M[W]]
sealed trait Var[A]
object VarW extends Var[W]
case class VarM[A] extends Var[M[A]]
case class VarM[A]() extends Var[M[A]]

// \s.e
sealed trait Abs[S, E]
Expand Down
2 changes: 1 addition & 1 deletion tests/pos/i4176-gadt.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
object i4176 {
sealed trait TNat
case class TZero() extends TNat
case class TSucc[N <: TNat] extends TNat
case class TSucc[N <: TNat]() extends TNat

object TNatSum {
sealed trait TSum[M, N, R]
Expand Down
2 changes: 1 addition & 1 deletion tests/pos/i4316.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
object Test {

case class Bar[A]
case class Bar[A]()

def meth[A](consumer: A => Unit, s: Bar[A]): Unit = {
s match {
Expand Down
2 changes: 1 addition & 1 deletion tests/run/derive-multi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ enum Lst[T] derives A, B {
case Nil()
}

case class Triple[S, T, U] derives A, B
case class Triple[S, T, U]() derives A, B

object Test1 {
import Lst._
Expand Down
4 changes: 2 additions & 2 deletions tests/run/typeclass-derivation2.scala
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,10 @@ object TypeLevel {
enum Shape {

/** A sum with alternative types `Alts` */
case Cases[Alts <: Tuple]
case Cases[Alts <: Tuple]()

/** A product type `T` with element types `Elems` */
case Case[T, Elems <: Tuple]
case Case[T, Elems <: Tuple]()
}

/** Every generic derivation starts with a typeclass instance of this type.
Expand Down
4 changes: 2 additions & 2 deletions tests/run/typeclass-derivation2a.scala
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@ object TypeLevel {
enum Shape {

/** A sum with alternative types `Alts` */
case Cases[Alts <: Tuple]
case Cases[Alts <: Tuple]()

/** A product type `T` with element types `Elems` */
case Case[T, Elems <: Tuple]
case Case[T, Elems <: Tuple]()
}

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