E154: Anonymous Instance Cannot Be Empty

This error occurs when an anonymous given instance is defined without implementing a type or providing at least one extension method. Anonymous givens must either implement a specific type or contain extension methods. An empty anonymous given has no practical use and is not allowed.


Example

given {}

Error

-- [E154] Syntax Error: example.scala:1:6 --------------------------------------
1 |given {
  |      ^
  |      anonymous instance must implement a type or have at least one extension method

Solution

trait Printable {
  def print(): Unit
}

// Implement a type
given Printable {
  def print(): Unit = println("hello")
}

Note: This error code is difficult to reproduce with current parser syntax, as the parser typically reports syntax errors before reaching this validation. The behavior described here reflects the intended semantics of the error message.