Dotty: Forbid case classes without parameter lists?

Created on 30 Jul 2019  路  6Comments  路  Source: lampepfl/dotty

Scalac rejects case classes such as:

@ case class A[T]
(console):1: case classes must have a parameter list; try 'case class A()' or 'case object A'
case class A[T]
               ^

Dotty currently accepts them. This can be confusing in pattern matching: it looks like pattern case A => is matching on instances of class A, but it's actually matching on the companion object.

parser reporting help wanted bug

Most helpful comment

@smarter can I give this a shot? If so, can you please assign it to me as well.

All 6 comments

Yes, we should emit the same error as scalac here.

@smarter can I give this a shot? If so, can you please assign it to me as well.

BTW, you should make sure that enum A { case B[C] } has the same treatment.

@LPTK should this be allowed?

enum A { case B }

@ashwinbhaskar yes, that's just a case _value_. You refer to it and match it as B, so there is no confusion here.

@OlivierBlanvillain can the fix be merged now?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

liufengyun picture liufengyun  路  3Comments

andreaTP picture andreaTP  路  3Comments

fommil picture fommil  路  3Comments

smarter picture smarter  路  3Comments

Blaisorblade picture Blaisorblade  路  3Comments