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

Use immutable Seq for repeated #227

Closed
hseeberger opened this issue Jan 16, 2017 · 5 comments
Closed

Use immutable Seq for repeated #227

hseeberger opened this issue Jan 16, 2017 · 5 comments

Comments

@hseeberger
Copy link

Currently a repeated field of a message gets compiled to a scala.collection.Seq parameter or a case class. Case classes really should be immutable, which can be broken by passing a mutable Seq. Therefore I suggest to use scala.collection.immutable.Seq.

@xuwei-k
Copy link
Contributor

xuwei-k commented Jan 16, 2017

related #218

@thesamet
Copy link
Contributor

This should be an option users can choose once #218 is implemented since making scala.collection.immutable.Seq the default generated type would break users' existing code:

scala> case class Foo(x: collection.immutable.Seq[Int])
defined class Foo

scala> Foo(Seq(3,4,5))
<console>:14: error: type mismatch;
 found   : Seq[Int]
 required: scala.collection.immutable.Seq[Int]
       Foo(Seq(3,4,5))
              ^

@hseeberger
Copy link
Author

Even better if it becomes an option. But for a pre-1.0 software I personally wouldn't be surprised by breaking changes.

thesamet added a commit that referenced this issue Feb 12, 2017
@rogern
Copy link

rogern commented Nov 10, 2022

I wonder, can't this default to immutable.Seq if generated on >=2.13 and collection.Seq on earlier versions?
A tad annoying with false positives in IDE wherever used :)
We will configure it for now though.

@thesamet
Copy link
Contributor

ScalaPB generator code is meant to be used on all supported versions of Scala, incl. Scala 3. Been trying to avoid having language-version logic in the generator, though this is something that can be considered in the future if there's a real advantage. For this one, you can set collection_type as a package-scoped option in your project, and alter PB.protoSources in sbt to include that options file only in a certain Scala versions.

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