E040: Expected Token But Found
This error is emitted when the compiler expects a specific token (like a keyword, symbol, or identifier) but finds a different token instead.
This is a general syntax error that indicates the code structure doesn't match what the parser expected at that position. Common causes include missing punctuation, mismatched brackets, or using a keyword where an identifier is expected.
Example
def example(x: Int y: Int) = x + y
Error
-- [E040] Syntax Error: example.scala:1:20 -------------------------------------
1 |def example(x: Int y: Int) = x + y
| ^
| an identifier expected, but ':' found
Solution
// Add the missing comma between parameters
def example(x: Int, y: Int) = x + y
// Or use separate parameter lists
def example(x: Int)(y: Int) = x + y
In this article