E228: Illegal Identifier

Besides syntactic rules for identifiers, the language specification adds:

The ‘$’ character is reserved for compiler-synthesized identifiers. User programs should not define identifiers that contain ‘$’ characters.

A warning is emitted for definitions with a name that contains a ‘$’ character.

No warning is emitted for usages of such a definition.


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

Occasionally, it is necessary to introduce an identifier that breaks this rule, usually to preserve binary compatibility.

That name can be wrapped in backquotes to suppress the warning:

var next = 42
def `next$access$1` = next