Skip to content

consider making "Enumerations must contain at least one case" a warning #16375

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

Open
unkarjedy opened this issue Nov 18, 2022 · 5 comments
Open

Comments

@unkarjedy
Copy link
Contributor

unkarjedy commented Nov 18, 2022

In IntelliJ Scala Plugin there is an action which creates a new Class/Object/File/Enum:

When you create class/object/file it creates a tiny template which is compilable.
However in Scala 3 enum can't have zero cases.
So the template for Scala 3 enum produces code with error "Enumerations must contain at least one case"

It's not an issue with Java enum because Java supports enum with zero items.

I wonder is there a reason to make it an error?
I could write a sealed class MyEnum without any inheritors and the code would perfectly compile.
Maybe it makes sense to remove the error?
Or at least make it a warning?

(also see SCL-20747)

@bishabosha
Copy link
Member

bishabosha commented Nov 18, 2022

I don't think there's any technical reason not to, I can trace the original check being added to #5015, so potentially there may be a repl issue.
(I did a quick check and enum Foo is not accepted as a complete statement by the repl)

this would not require a formal grammar change either.

Edit: One potential problem is that previously all enums have a scala.deriving.Mirror defined for them, this would mean some enums have no mirror.

@odersky
Copy link
Contributor

odersky commented Nov 18, 2022

I'm not against allowing empty enums.

@unkarjedy
Copy link
Contributor Author

Would it be safe to include in the next minor release or even patch update?

@odersky
Copy link
Contributor

odersky commented Jun 30, 2023

I think there are a number of issues to work out:

  • Parsing enum Foo as enum Foo {}, this was the essence of Empty enum bodies are accepted #5015, which got fixed in a different way.

  • Removing the error message

  • Fixing all code that depends on enumCases being non-empty. For instance, I see this in Desugar.scala

    enumCases.last.pushAttachment(DesugarEnums.DefinesEnumLookupMethods, ())

@bishabosha
Copy link
Member

bishabosha commented Jun 30, 2023

There is also the decision of if we will synthesize sum mirrors with no cases: #11764, which I think was previously decided no because code in community build assumes there will be at least one case (I guess libraries could release minor update to support zero-cases)

This can still be orthogonal to if enum will compile with zero cases

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants