E228: Names With Trailing Colon — 이름 끝의 콜론이 헷갈려요

E228: Names With Trailing Colon — 이름 끝의 콜론이 헷갈려요

이름이 연산자 문자와 콜론으로 끝나면 이 경고가 발생해요. 읽는 사람을 헷갈리게 하고 작성자의 의도와 다르게 해석될 수 있거든요. 예를 들어 x_:는 유효한 연산자 이름이지만, "본문이 시작되는 콜론 뒤에 이름 x_를 쓰려던 것"처럼 보일 수 있어요.

출처: Scala 3 Reference

본문

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_:`