E093: Extend Final Class

This error is emitted when attempting to extend a class that is marked as final.

A class marked with the final keyword cannot be extended by any other class. This is used to prevent inheritance when the class design doesn't support or intend for subclassing.


Example

final class Parent

class Child extends Parent

Error

-- [E093] Syntax Error: example.scala:3:6 --------------------------------------
3 |class Child extends Parent
  |      ^
  |      class Child cannot extend final class Parent
  |-----------------------------------------------------------------------------
  | Explanation (enabled by `-explain`)
  |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  | A class marked with the final keyword cannot be extended
   -----------------------------------------------------------------------------

Solution

// Remove final from the parent if inheritance is intended
class Parent

class Child extends Parent
// Or use composition instead of inheritance
final class Parent:
  def greet: String = "Hello"

class Child:
  private val parent = new Parent
  def greet: String = parent.greet