Adriaan sent in scala/scala#6505, which drops semantic changing -Y flags. This reignited an old debate about auto-tupling. It seems to be that most people who have given some thought about this issue are coming down to drop this feature, instead of supporting it.
- scalac, mind your own tuple business by Paul Phillips
-
seriously, given previous experience (i.e. man hours wasted) I’d rather have
-Ywarn-adapted-args
on by default at error level.
26 Feb 2013 Roland Kuhn -
AGGGHGHGHGHGHGHGHGHGHGHGHGH!
Scala auto-tupling. Why on earth does this “feature” even exist?
4 Feb 2014 Daniel Spiewak -
Yes, let’s all vote to have this removed. I wonder if there’s anyone on planet who ever found it useful.
4 Feb 2014 Rahul Goma Phulore -
Not classifying as a spec bug, because I believe we should instead deprecate this.
SI-3583: Spec doesn’t mention automatic tupling, Adriaan Moors
and on scala/scala#6505 comments are coming in from various users:
I find that auto-tupling hinders readability, and at least for me it ends up being applied accidentally often enough that I prefer to turn it off. The 22-element limit makes it unusable for arity-abstraction so I don’t really buy that argument. So I’m for removing the flag and for removing the feature.
One data point: a very nasty issue (scala-js/scala-js#3154, fix in scala-js/scala-js@9428b68) that could have been avoided if auto-tupling did not exist.
So yup, I’m not a fan of auto-tupling …
Without building consensus around this for both Scala 2.x and Dotty, I don’t think we can move forward, so here it is.
what is auto tupling?
scala> case class W[A](elem: A)(implicit ordering: Ordering[A])
defined class W
scala> W(1, 2, 3, 4)
res0: W[(Int, Int, Int, Int)] = W((1,2,3,4))
In the above example, Scala automatically turns the parameter list 1, 2, 3, 4
into a tuple (1, 2, 3, 4)
even though one might not expect it to happen.
A case that bites you is when a Java library exposes a method with Any
. Using Paul’s example, Joda time 1.6:
libraryDependencies += "joda-time" % "joda-time" % "1.6"
Given this, can you spot the problem here?
scala> import org.joda.time.DateTime
import org.joda.time.DateTime
scala> def time = new DateTime(2010, 5, 7, 0, 0, 0)
time: org.joda.time.DateTime
scala> time
java.lang.IllegalArgumentException: No instant converter found for type: scala.Tuple6
at org.joda.time.convert.ConverterManager.getInstantConverter(ConverterManager.java:165)
at org.joda.time.base.BaseDateTime.<init>(BaseDateTime.java:169)
at org.joda.time.DateTime.<init>(DateTime.java:168)
at .time(<console>:12)
... 36 elided
Joda time 1.6 DateTime has 12 constructors, and among them were:
DateTime(int year, int monthOfYear, int dayOfMonth, int hourOfDay, int minuteOfHour, int secondOfMinute, int millisOfSecond)
DateTime(Object instant)
The first one takes seven parameters, but you passed only six. And Scala turned it into Tuple6. wat? I mean…
This is a DEBACLE!