Lint or deprecate auto-tupling (like Scala 2's -Xlint:adapted-args
)
#19255
Replies: 8 comments 8 replies
-
This would fit in well with the effort being made in Scala 3.4 to begin phasing out legacy language features. One past discussion in this area: https://contributors.scala-lang.org/t/lets-drop-auto-tupling/1799 Another: #4311 The Scala 2 ticket is scala/bug#3583 , where I suggested that we deprecate instead of merely offering a lint. If Scala 3 deprecates, I believe we would follow suit and deprecate in Scala 2 as well under |
Beta Was this translation helpful? Give feedback.
-
@nicolasstucki Did this come up at all when you were doing your inventory recently? |
Beta Was this translation helpful? Give feedback.
-
It's more tricky than just dropping auto-tupling. We'll have to start with this: val buf: ListBuffer[Int] = ???
val buf += (1, 2) This needs to be declared illegal first. The general rule will be that infix operators no longer take vararg arguments. val xs: List[(Int, Int)] = ???
(1, 2) :: xs
xs :+ (1, 2) If we drop auto-tupling, this would no longer work, which would be upsetting. So we have to start with the infix varargs. sc ../new/test.scala -deprecation
-- Deprecation Warning: ../new/test.scala:15:12 --------------------------------
15 |val _ = buf += (1, 2)
| ^^^^^^
|method += in trait Growable is deprecated since 2.13.0: Use `++=` aka `addAll` instead of varargs `+=`; infix operations with an operand of multiple args will be deprecated What we need to do:
It's a long road. We better start quickly. Who can do the first step (deprecation)? |
Beta Was this translation helpful? Give feedback.
-
I also want to clearly state that we should not waste our time linting this, like we did in Scala 2. Doing a lint here is a half-baked solution that creates language dialects. EDIT: Sorry, we do already have a lint in place. It's a language import: /** Where imported, auto-tupling is disabled.
*
* '''Why control the feature?''' Auto-tupling can lead to confusing and
* brittle code in presence of overloads. In particular, surprising overloads
* can be selected, and adding new overloads can change which overload is selected
* in suprising ways.
*
* '''Why allow it?''' Not allowing auto-tupling is difficult to reconcile with
* operators accepting tuples.
*/
@compileTimeOnly("`noAutoTupling` can only be used at compile time in import statements")
object noAutoTupling So, yes, to make progress, and make the import redundant, we have to follow the steps I outlined above. |
Beta Was this translation helpful? Give feedback.
-
The discussion about "will they or won't they?" goes back to 2018 when the API was deprecated: "Scala 3.0 will probably drop support for infix operators with multiple parameters." (szeiger) So it's already been a long road trip. Scala 2's best effort is to lint both, The advantage of a lint is that you get to hear feedback about how it messes with someone's DSL.
... for some definition of "liberating". |
Beta Was this translation helpful? Give feedback.
-
OK, thanks to @odersky for pointing out |
Beta Was this translation helpful? Give feedback.
-
At scala/scala#10857 (comment) I noticed the lint doesn't warn for infix tupling:
I was reviewing the behavior because I wondered why I had a
So in that PR, I demote Not only am I reconciled to the current behavior, I hope it does not change. I don't use "multiarg infix", but somebody does. I would propose that the desired feature is not auto-tupling but auto-untupling: if applying infix tuple doesn't work, only then consider multiarg infix. (The opposite of current priority.) That is in the spirit of parameter untupling: "don't hassle me with arity boilerplate". |
Beta Was this translation helpful? Give feedback.
-
Just wanted to point out that autotupling is currently essential for libraries like @armanbilge's Calico - I guess it'd still be fine if autotupling were to be made illegal, but it'd surely become less convenient. Mayybe the DSL can be reworked to still work without autotupling too... |
Beta Was this translation helpful? Give feedback.
-
Equivalent of Scala 2. E.g.
Some(1,2)
should warn about adapted args.Beta Was this translation helpful? Give feedback.
All reactions