E229: Indentation Does Not Reflect Nesting — 들여쓰기가 중첩 구조와 안 맞아요
E229: Indentation Does Not Reflect Nesting — 들여쓰기가 중첩 구조와 안 맞아요
들여쓰기가 문법적 중첩(nesting)을 반영하지 않으면 이 경고가 발생해요. 읽는 사람을 헷갈리게 하고, 작성자가 잘못 이해하고 썼다는 신호일 수 있어요. 새 스코프를 선언하려던 줄이 실제로는 그렇게 동작하지 않을 때 발생하는데, 예를 들어 콜론이 이름의 일부가 돼버린 경우가 있어요.
본문
Example
class SomeClass // no colon, so this is an empty class declaration
def y = 1 // this is a standalone, top-level definition!
콜론이 없으니 class SomeClass는 빈 클래스 선언이고, def y = 1은 들여쓰기와 달리 최상위 정의가 됩니다.
Error
-- [E229] Syntax Warning: example.scala:2:2 ------------------------------------
2 | def y = 1 // this is a standalone, top-level definition!
| ^
| Line is indented too far to the right, or a '{' or ':' is missing
|-----------------------------------------------------------------------------
| Explanation (enabled by `-explain`)
|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| Indentation that does not reflect syntactic nesting may be due to a typo such as missing punctuation.
-----------------------------------------------------------------------------
Solution
class SomeClass
// If the declaration is intentionally at the top level, indent it as such
def y = 1