E228: Names With Trailing Colon
This warning occurs when a name ends with operator characters and a colon, which can confuse readers and may not reflect the writer's intent.
For instance, x_: is a valid operator name, but it may have been intended as x_ followed by a colon to mark the beginning of the body.
Example
object Hello_: // looks like it should have a body, but the colon is part of the name
Error
-- [E228] Syntax Warning: example.scala:1:7 ------------------------------------
1 |object Hello_: // looks like it should have a body, but the colon is part of the name
| ^^^^^^^
| name `Hello_:` should be enclosed in backticks
|-----------------------------------------------------------------------------
| Explanation (enabled by `-explain`)
|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| Names with trailing operator characters may fuse with a subsequent colon if not set off by backquotes or spaces.
-----------------------------------------------------------------------------
Solution
// Use backticks to make the intent explicit
object `Hello_:`
In this article