-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Is it an issue need to be resolved? += (("a", 1))
#20066
dongxuwang
started this conversation in
General Discussion
-
For +=
with tuple, why I have to add ()
to wrap the tuple value
import collection.mutable.ArrayBuffer val x: ArrayBuffer[(String, Int)] = ArrayBuffer(("a", 1)) // x += ("b", 2) // this wouldn't work x += (("b", 2))
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 2 comments
-
Apparently, we untuple tuple arguments of infix operations if the function does not consist only of unary alternatives.
trait Buffer1[A]: def += (elem: A): Buffer1[A] val b1: Buffer1[(String, Int)] = ??? b1 += ("a", 1) // Ok trait Buffer2[A]: def += (elem: A): Buffer2[A] def += (elem1: A, elem2: A): Buffer2[A] val b2: Buffer2[(String, Int)] = ??? b2 += ("b", 2) // Error
scala3/compiler/src/dotty/tools/dotc/typer/Applications.scala
Lines 1231 to 1239 in 6bb6b43
/** Should we tuple or untuple the argument before application?
* If auto-tupling is enabled then
*
* - we tuple n-ary arguments where n > 0 if the function consists
* only of unary alternatives
* - we untuple tuple arguments of infix operations if the function
* does not consist only of unary alternatives.
*/
def needsTupledDual(funType: Type, pt: FunProto)(using Context): Boolean =
Beta Was this translation helpful? Give feedback.
All reactions
0 replies
-
Since the alternative Growable#+=
is deprecated, it would be handy if it were ignored for purposes of infix untupling. Hopefully it can be removed someday.
The current nice syntax is x += "b" -> 2
.
Beta Was this translation helpful? Give feedback.
All reactions
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment