E067: Only Classes Can Have Declared But Undefined Members

This error is emitted when an abstract member (a declaration without implementation) appears outside of a class or trait context, such as in an object.

Only classes and traits can have abstract members. Objects, being concrete singleton instances, must have all members fully implemented. Variables also need to be initialized to be defined.


Example

object Example:
  def abstractMethod: Int

Error

-- [E067] Syntax Error: example.scala:2:6 --------------------------------------
2 |  def abstractMethod: Int
  |      ^
  |Declaration of method abstractMethod not allowed here: only classes can have declared but undefined members

Solution

// Provide an implementation in objects
object Example:
  def concreteMethod: Int = 42
// Or use a trait or abstract class for abstract members
trait Example:
  def abstractMethod: Int

object ConcreteExample extends Example:
  def abstractMethod: Int = 42