E204: Deprecated Infix Named Argument Syntax
E204: Deprecated Infix Named Argument Syntax
이 경고는 obj method(x = 1, y = 2)처럼 중위(infix) 메서드 호출에서 이름 있는 인자를 사용할 때 발생해요. Scala 3.7부터 이 문법은 여러 개의 이름 있는 인자가 아니라 단일 이름 있는 튜플 인자를 전달하는 것으로 해석돼요.
본문
이 경고는 기존의 이름 있는 인자 해석에서 새로운 이름 있는 튜플 의미론으로 코드를 전환하도록 도와주는 마이그레이션 경고예요.
예시 (Example)
class C:
def combine(x: Int, y: Int): Int = x + y
def example = new C() `combine` (x = 42, y = 27)
에러 (Error)
-- [E204] Syntax Warning: example.scala:3:34 -----------------------------------
3 | def example = new C() `combine` (x = 42, y = 27)
| ^^^^^^^^^^^^^^^^
|Deprecated syntax: infix named arguments lists are deprecated; since 3.7 it is interpreted as a single named tuple argument.
|To avoid this warning, either remove the argument names or use dotted selection.
|This can be rewritten automatically under -rewrite -source 3.7-migration.
해결 방법 (Solution)
이름 있는 인자를 사용할 때는 중위 표기 대신 점(dotted) 선택 표기를 사용해요.
class C:
def combine(x: Int, y: Int): Int = x + y
def example = new C().combine(x = 42, y = 27)
대안으로, 인자 이름을 제거하고 중위 표기에서 위치 인자를 사용해도 돼요.
class D:
def combine(x: Int, y: Int): Int = x + y
def example = new D() `combine` (42, 27)
-rewrite -source 3.7-migration을 붙여 컴파일하면 자동 재작성 기능으로 문법을 자동으로 갱신할 수도 있어요.