Back to Scala3

E203: Deprecated Assignment Syntax

docs/_docs/reference/error-codes/E203.md

3.8.41.4 KB
Original Source

E203: Deprecated Assignment Syntax

This warning occurs when using parentheses around an assignment expression like (x = value). Starting from Scala 3.7, this syntax is interpreted as a named tuple with one element rather than an assignment.

This is a migration warning to help transition code from the old assignment interpretation to the new named tuple semantics.

Example

scala
def example() =
  var age: Int = 28
  (age = 29)

Error

scala
-- [E203] Syntax Migration Warning: example.scala:3:2 --------------------------
3 |  (age = 29)
  |  ^^^^^^^^^^
  |Deprecated syntax: since 3.7 this is interpreted as a named tuple with one element,
  |not as an assignment.
  |
  |To assign a value, use curly braces: `{age = 29}`.
  |This can be rewritten automatically under -rewrite -source 3.6-migration.

Solution

Use curly braces instead of parentheses for assignments:

scala
def example() =
  var age: Int = 28
  { age = 29 }

Alternatively, you can use the automatic rewrite feature by compiling with -rewrite -source 3.6-migration to automatically update the syntax.

<!-- SOURCE-ONLY: Remove the notice below once this page has been manually updated. --> <aside class="warning"> This reference page was created with LLM assistance - the description of the error code may not be accurate or cover all possible scenarios. </aside>