-
Notifications
You must be signed in to change notification settings - Fork 21
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
Varargs and unapplySeq don't allow mutable Seqs anymore #11040
Comments
I'm hijacking this ticket instead of opening a new one because it is already about what looks to me like the core of the problem. We changed the This is from an email by @julienrf where he sums up the situation and proposes a solution:
I'm not a fan of this solution. I think restricting varargs to immutable Seqs is acceptable. Enforcing immutability is generally a good thing. Passing arrays as varargs in #11024 can be solved in the same way that we are already using when passing arrays to methods that expect a As @retronym pointed out, if you really need to treat a mutable Seq as a vararg, you can write a wrapper that pretends that it is immutable (which is what If we stick with immutable I propose that we sidestep this issue with name-based extractors. Scala has already supported them unofficially for a few versions now and they are implemented and properly specified in Dotty. The error that prompted this ticket actually appears to be a bug in the handling of name-based extractors by the pattern matcher. It already allows
I think we could justify keeping name-based extractors unofficial for another release but using them internally for |
Writing a wrapper should not be left as an exercise for the user for two reasons:
Thus if we're going to go this route, we should write a |
I don't see the merit of "restricting varargs to immutable Seqs". "varargs", as the syntax is suggesting, should be treated as if the collection is already been decomposed to a parameter list. In such sense, it shouldn't matter at all the collection itself is mutable or immutable. It seems dogmatic to me that the decision was made purely based on "Enforcing immutability is generally a good thing" but nothing else. The suggested workarounds, one of which is using "unsafeWrapArray". Would rather confuse the function caller. Why the caller has to do something "unsafe" while the function itself has nothing to depend on immutability? |
If you're interested in exploring the thinking behind these decisions — which is a lot broader and stretches back a lot farther than just Stefan's one comment on this one ticket — I'd suggest asking about it on https://users.scala-lang.org |
scala/scala#6962 (comment)
The text was updated successfully, but these errors were encountered: