Back to Scala3

E028: Illegal Literal

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

3.8.41.2 KB
Original Source

E028: Illegal Literal

This error is emitted when the parser encounters an invalid literal value that doesn't conform to Scala's literal syntax rules.

The compiler message states: "Illegal literal"

Available literals in Scala can be divided into several groups:

  • Integer literals: 0, 21, 0xFFFFFFFF, -42L
  • Floating Point Literals: 0.0, 1e30f, 3.14159f, 1.0e-100, .1
  • Boolean Literals: true, false
  • Character Literals: 'a', '\u0041', '\n'
  • String Literals: "Hello, World!"
  • null

This error is triggered during parsing when a literal token is expected but the scanner encounters something that cannot be interpreted as any valid literal type.

Note: This error code is active in the compiler and is triggered in the parser's literal and negativeLiteral methods. The exact conditions to reproduce this error with source code require further investigation, as the scanner typically produces different errors for malformed input.

<!-- 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>