Skip to content

Forbid final object #11094

@Blaisorblade

Description

@Blaisorblade

First reported in scala/scala3#4936; both sealed and final are redundant on object, but final object seems pretty common (though it's redundant).

scala> trait A { object A }
defined trait A

scala> trait B extends A { object A }
<console>:12: error: overriding object A in trait A;
 object A cannot override final member
       trait B extends A { object A }
                                  ^

OTOH, final object seems pretty common, and it even appears in the new collections, maybe because it is sometimes used in such pattern (from Dotty) — and final on case classes does make sense.

sealed trait Status
final case class Success(output: String) extends Status
final case class Failure(output: String) extends Status
final case object Timeout extends Status

We're considering changing this in Dotty in scala/scala3#4973, but it'd be good to do the change in 2.14 as well I guess — or (EDIT) at least agree that we want to do it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions