Skip to content

Commit ecf5b87

Browse files
committed
Check that cases with type parameters also have an extends clause
1 parent 2c3b010 commit ecf5b87

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,11 @@ object desugar {
297297
// This is not watertight, but `extends AnyVal` will be replaced by `inline` later.
298298

299299
val originalTparams =
300-
if (isEnumCase && parents.isEmpty) reconstitutedEnumTypeParams(cdef.pos.startPos)
300+
if (isEnumCase && parents.isEmpty) {
301+
if (constr1.tparams.nonEmpty)
302+
ctx.error(em"case with type parameters needs extends clause", constr1.tparams.head.pos)
303+
reconstitutedEnumTypeParams(cdef.pos.startPos)
304+
}
301305
else constr1.tparams
302306
val originalVparamss = constr1.vparamss
303307
val constrTparams = originalTparams.map(toDefParam)

tests/neg/enums.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
enum List[+T] {
22
case Cons(x: T, xs: List[T])
33
case Nil // error: illegal enum value
4+
case Snoc[U](xs: List[U], x: U) // error: case with type parameters needs extends clause // error // error // error
45
}
56

67
enum class X {

0 commit comments

Comments
 (0)