-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix #5495: Disallow lazy enums #7850
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
Conversation
Use the same scheme already used in Parser for avoiding type/term flags mixups also when desugaring enums.
I am exasperated how over-engineered and badly designed the error message architecture is. Error messages used to be simple strings but are now a complete mess. Latest installment: Error message ids are an enum. So if a message is no longer needed, you can drop the enum value, right? Wrong! The error message tests rely on the actual ordinal number printed, so they fail if that number changes.
It's true that it's a bit cumbersome, but it's very useful: it means that error message ids are stable, so if someone hits error number 4274, they can google "scala error 4274" and find content relevant to that particular error no matter what compiler version was used to produce them. |
You may want to add the following test from #5525: abstract enum Foo1 {} // error: only access modifiers allowed
final enum Foo2 {} // error: only access modifiers allowed
sealed enum Foo3 {} // error: only access modifiers allowed
implicit enum Foo4 {} // error: only access modifiers allowed
lazy enum Foo5 {} // error: only access modifiers allowed
erased enum Foo6 {} // error: only access modifiers allowed
override enum Foo7 {} // error: only access modifiers allowed
inline enum Foo8 {} // error: only access modifiers allowed
opaque enum Foo9 {} // error: only access modifiers allowed
enum Foo10 {
abstract case C1() // error: no modifier allowed
final case C2() // error: no modifier allowed
sealed case C3() // error: no modifier allowed
implicit case C4() // error: no modifier allowed
lazy case C5() // error: no modifier allowed
erased case C6() // error: no modifier allowed
override case C7() // error: no modifier allowed
private case C8() // error: no modifier allowed
protected case C9() // error: no modifier allowed
inline case C10() // error: no modifier allowed
opaque case C11() // error: no modifier allowed
}
enum Foo11 {
abstract case C1 // error: no modifier allowed
final case C2 // error: no modifier allowed
sealed case C3 // error: no modifier allowed
implicit case C4 // error: no modifier allowed
lazy case C5 // error: no modifier allowed
erased case C6 // error: no modifier allowed
override case C7 // error: no modifier allowed
private case C8 // error: no modifier allowed
protected case C9 // error: no modifier allowed
inline case C10 // error: no modifier allowed
opaque case C11 // error: no modifier allowed
} |
I get that. But in that case, ErrorMessageIds should not have been defined as enum values. |
Adapted from scala#5525: Check that only access modifiers are legal for enums (both definitions and cases). This is useful as a pre-check, to avoid confusing error messages later.
@allanrenucci I ended up incorporating the key approach of #5525: check that enums only take access flags (btw enum cases also accept accept flags). That makes error reporting more uniform. We still need the defensive addition of flags that issues an error rather than a crashing when term flags and type flags are mixed. |
Use the same scheme already used in Parser for avoiding
type/term flags mixups also when desugaring enums.