E230: Illegal Identifier — 식별자에 $를 쓰면 안 돼요
E230: Illegal Identifier — 식별자에 $를 쓰면 안 돼요
식별자에 대한 문법 규칙 외에, 언어 명세가 한 가지를 더 추가로 요구합니다. $ 문자는 컴파일러가 만들어내는 식별자를 위해 예약되어 있어요. 사용자 프로그램은 $가 포함된 식별자를 정의하면 안 됩니다.
$가 포함된 이름을 가진 정의에 대해서는 경고가 발생합니다. 그런 정의를 사용하는 경우에는 경고가 나오지 않아요.
본문
Example
var next = 42
def next$access$1 = next // attempt to explicitly define a member for binary compatibility
Error
-- [E230] Syntax Warning: example.scala:2:4 ------------------------------------
2 |def next$access$1 = next // attempt to explicitly define a member for binary compatibility
| ^^^^^^^^^^^^^
|The identifier `next$access$1` should not contain `$`, which is reserved for internal compiler use.
|-----------------------------------------------------------------------------
| Explanation (enabled by `-explain`)
|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| User identifiers may be encoded with embedded `$`, and other compiler artifacts
| may rely on using `$` with specific meanings.
|
| The prohibition against explicit `$` may be ignored by enclosing the identifier in backquotes
| at the definition site.
-----------------------------------------------------------------------------
Solution
가끔은 이 규칙을 어기는 식별자를 도입해야 할 때가 있는데, 보통 바이너리 호환성을 지키기 위해서예요. 그런 이름은 백틱으로 감싸면 경고를 없앨 수 있습니다.
var next = 42
def `next$access$1` = next