Tuple adaptation

  val l: List[(Int, Int)] = List((1, 2), (3, 4))
  val p = l.head == ((1, 2))

I don’t understand why the code requires the double parentheses to avoid a tuple adaptation warning since == is a single argument method anyway. What’s ambiguous about l.head == (1, 2) ?

1 Like

IIRC that’s the parser interpreting l.head == (1, 2) as l.head.==(1, 2).

I don’t recall the specific conversations, but I think this behavior may be different in the upcoming Scala 3

1 Like

Seems a little sloppy from the parser, but it makes sense. I vaguely remember reading something about restricting infix calls to single-argument methods (which seems reasonable), but I don’t remember where (maybe Scala 3?)

You’re probably thinking of https://github.com/lampepfl/dotty/pull/4311. (But note that it remains open, and at present Dotty doesn’t warn, even though Scala 2 does.)

1 Like