E116: Missing Companion for Static

This error is emitted when an object contains @static members but does not have a companion class.

Objects with @static members must have a companion class because the static members are placed in the companion class's bytecode.


Example

import scala.annotation.static

object Example:
  @static val count = 0

Error

-- [E116] Syntax Error: example.scala:4:14 -------------------------------------
4 |  @static val count = 0
  |  ^^^^^^^^^^^^^^^^^^^^^
  |  object Example does not have a companion class
  |-----------------------------------------------------------------------------
  | Explanation (enabled by `-explain`)
  |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  | An object that contains @static members must have a companion class.
   -----------------------------------------------------------------------------

Solution

// Add a companion class
import scala.annotation.static

class Example

object Example:
  @static val count = 0
// Or remove @static if you don't need static behavior
object Example:
  val count = 0