Skip to content
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

Support for sealed traits #67

Closed
PerWiklander opened this issue Dec 26, 2015 · 8 comments
Closed

Support for sealed traits #67

PerWiklander opened this issue Dec 26, 2015 · 8 comments

Comments

@PerWiklander
Copy link

Use case: Exhaustive pattern matching of related domain events.

A file level option like:
option (scalapb.message).sealedTrait = "DomainEvent";

This would cause all messages in the .proto file to be put in the same .scala file along with a
sealed trait DomainEvent {}

@thesamet
Copy link
Contributor

I wonder if it makes sense to automatically have all the messages in the file extend the sealed trait, or individual messages should be opted in via option (scalapb.message).extends

@PerWiklander
Copy link
Author

Consider that it is a sealed trait and all extending messages have to be generated in the same .scala file. It would be confusing if only some of the messages from a .proto end up in the same file and others in separate files.

At least in my use case it would require copy+pasting option (scalapb.message).extends into every message of the file.

@trungfinity
Copy link
Contributor

Do you have any plan to implement this?

thesamet added a commit that referenced this issue Apr 12, 2016
@thesamet
Copy link
Contributor

@PerWiklander
Copy link
Author

In your example the sealed trait in the preamble has methods prefixed with get, getFoo and getBar. Is that required? And does it even work with the generated case class, which I assume would have public vals named foo and bar?

@PerWiklander
Copy link
Author

Or was that just an example? I guess my initial example for this issue doesn't require any defs on the sealed trait, since it's just a grouping trait for pattern matching.

@thesamet
Copy link
Contributor

It's just an example. You can leave the sealed trait empty. There's no
requirement to define anything in it.

On Fri, Apr 15, 2016, 5:26 AM Per Wiklander [email protected]
wrote:

Or was that just an example? I guess my initial example for this issue
doesn't require any defs on the sealed trait, since it's just a grouping
trait for pattern matching.


You are receiving this because you modified the open/close state.

Reply to this email directly or view it on GitHub
#67 (comment)

@ngbinh
Copy link
Contributor

ngbinh commented Apr 15, 2016

thanks! This is great!

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

No branches or pull requests

4 participants