Explanation is kind of unexpected: print has a parameter named x. Using x = ... uses the named argument, therefore print(x="Hello World") is the same as print("Hello World").

See Scala Predef docs or Predef.scala source:

object Predef /*....*/ {

  def print(x: Any) = Console.print(x)


Note: this was already discussed in Scala Internal mailing list:

Scala currently tries to be smart about treating "x = e" as a named argument or an assignment ... This can be surprising to the user ....

Proposal: we deprecate assignments in argument lists

There also exists an issue SI-8206 for this, the change was probably implemented in issue 426 for Scala 2.13.

Your code will still compile after deprecation, with the same meaning. The change will be no one (at least no one sufficiently familiar with the language specs / implementation) should expect it to be interpreted as assignment any more.

Related Query

More Query from same tag