Skip to content

Allow refinements in enums #6959

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

Closed
anatoliykmetyuk opened this issue Jul 29, 2019 · 2 comments
Closed

Allow refinements in enums #6959

anatoliykmetyuk opened this issue Jul 29, 2019 · 2 comments

Comments

@anatoliykmetyuk
Copy link
Contributor

enum DbRequest {
  case SqlReq(table: String, where: String)
  case MongoReq(jsonBody: String)
}; import DbRequest._

enum DbDriver {
  type Request <: DbRequest

  case mongo extends DbDriver { type Request = MongoAddr }
  case myslq extends DbDriver { type Request = MySQLAddr }
}

Gives:

[error] -- Error: /Users/anatolii/Projects/dotty/ecosystem/mainmethods/src/main/scala/Main.scala:9:30
[error] 9 |  case mongo extends DbDriver { type Request = MongoAddr }
[error]   |                              ^
[error]   |                              end of statement expected
[error] -- [E040] Syntax Error: /Users/anatolii/Projects/dotty/ecosystem/mainmethods/src/main/scala/Main.scala:9:32
[error] 9 |  case mongo extends DbDriver { type Request = MongoAddr }
[error]   |                                ^^^^
[error]   |                                ';' expected, but 'type' found
[error] -- [E079] Syntax Error: /Users/anatolii/Projects/dotty/ecosystem/mainmethods/src/main/scala/Main.scala:10:2
[error] 10 |  case myslq extends DbDriver { type Request = MySQLAddr }
[error]    |  ^^^^
[error]    |  Only case class or case object allowed
[error] three errors found
@allanrenucci
Copy link
Contributor

Enum cases used to be able to have a body. This was changed in #4003:

I had a lingering unease that the rules for enums were too complex, and the syntax too cumbersome. I now think I have found a way to simplify things considerably. The key was to take away one capability: that cases can have bodies which can define members.

@anatoliykmetyuk
Copy link
Contributor Author

Ok, this seems to be a complicated point

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

2 participants