Skip to content

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

Merged
merged 5 commits into from
Jan 1, 2020
Merged

Conversation

odersky
Copy link
Contributor

@odersky odersky commented Dec 25, 2019

Use the same scheme already used in Parser for avoiding
type/term flags mixups also when desugaring enums.

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.
@smarter
Copy link
Member

smarter commented Dec 25, 2019

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.

@allanrenucci
Copy link
Contributor

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
}

@odersky
Copy link
Contributor Author

odersky commented Dec 26, 2019

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.

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.
@odersky
Copy link
Contributor Author

odersky commented Dec 26, 2019

@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.

@odersky odersky merged commit 283b095 into scala:master Jan 1, 2020
@odersky odersky deleted the fix-#5495 branch January 1, 2020 21:13
@allanrenucci allanrenucci mentioned this pull request Jan 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants