E100: Missing Empty Argument List
E100: Missing Empty Argument List (빈 인자 목록 누락)
인자 목록이 비어 있는(()) 무인자(nullary) 메서드를, 그 빈 인자 목록 없이 호출했을 때 나오는 에러예요.
본문
Scala 3에서는 적용(application) 문법이 파라미터 문법을 정확히 따라야 해요. 메서드를 ()로 정의했다면 ()로 호출해야 하죠. 다만 Java에서 정의된 메서드나 Java 메서드를 오버라이드하는 메서드에는 이 규칙이 적용되지 않아요.
예시
def next(): Int = 42
val n = next
에러 메시지
-- [E100] Syntax Error: example.scala:3:8 --------------------------------------
3 |val n = next
| ^^^^
| method next must be called with () argument
|-----------------------------------------------------------------------------
| Explanation (enabled by `-explain`)
|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| Previously an empty argument list () was implicitly inserted when calling a nullary method without arguments. E.g.
|
| def next(): T = ...
| |next // is expanded to next()
|
| In Dotty, this idiom is an error. The application syntax has to follow exactly the parameter syntax.
| Excluded from this rule are methods that are defined in Java or that override methods defined in Java.
-----------------------------------------------------------------------------
해결 방법
빈 인자 목록을 넣어 호출하거나, 인자가 필요 없다면 애초에 () 없이 정의하면 돼요.
// Include the empty argument list
def next(): Int = 42
val n = next()
// Or define without () if no arguments are needed
def next: Int = 42
val n = next