Skip to content

Multiarg infix is not supported in op= rewrite #14418

Open
@som-snytt

Description

@som-snytt

Compiler version

3.1.0

Minimized code

case class C(c: Int) {
  def +(i: Int, j: Int): C = new C(c + i*j)
}

object Test extends App {
  println {
    var x = new C(42)
    x = x + (3, 9)
    x
  }
  println {
    var x = new C(42)
    x.+=(3, 9)
    x
  }
  println {
    var x = new C(42)
    x += (3, 9)
    x
  }
}

Output

-- [E008] Not Found Error: multi.scala:19:6 -----------------------------------------------------------------------------------------------------
19 |    x += (3, 9)
   |    ^^^^
   |    value += is not a member of C - did you mean C.!=?
1 error found

Expectation

If the compiler accepts multiarg infix (and maybe it should not), it should accept multiarg assignment syntax.

Scala 2 -Xlint says

multi.scala:3: warning: multiarg infix syntax looks like a tuple and will be deprecated
  def +(i: Int, j: Int): C = new C(c + i*j)
      ^
multi.scala:9: warning: multiarg infix syntax looks like a tuple and will be deprecated
    x = x + (3, 9)
          ^

and fails to warn for assignment syntax.

Reported on discord:

just started learning Scala (3)... i'm a bit confused why this works [snip] but this does not

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions