E019: 누락된 반환 타입
E019: 누락된 반환 타입 (Missing Return Type)
이 에러는 추상 메서드 선언에서 반환 타입(return type)이 빠졌을 때 발생해요. 추상 선언은 명시적인 반환 타입을 가져야 해요. 본문이 없으면 컴파일러가 메서드의 타입을 추론할 수 없으므로, 명시적으로 지정해야 하기 때문이에요.
본문
Example
trait Foo:
def bar
Error
-- [E019] Syntax Error: example.scala:2:9 --------------------------------------
2 | def bar
| ^
| Missing return type
|-----------------------------------------------------------------------------
| Explanation (enabled by `-explain`)
|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| An abstract declaration must have a return type. For example:
|
| trait Shape:
| def area: Double // abstract declaration returning a Double
-----------------------------------------------------------------------------
Solution
// Add an explicit return type
trait Foo:
def bar: Unit
// Or provide an implementation (then type can be inferred)
trait Foo:
def bar = println("hello")
// For methods with parameters
trait Calculator:
def add(a: Int, b: Int): Int
def multiply(a: Int, b: Int): Int
더 알아보기
- 추상 멤버와 타입 추론에 대한 자세한 내용은 "Abstract Members" 관련 문서를 참고하세요.