Back to Scala3

E147: Redundant Modifier

docs/_docs/reference/error-codes/E147.md

3.8.41.1 KB
Original Source

E147: Redundant Modifier

This warning occurs when a modifier is applied to a definition where it has no effect because the definition is already implicitly given that property.

Common cases include:

  • Using final on a given definition (givens are already final)
  • Using final on an object member in a final class
  • Using modifiers that are implied by the definition context

Example

scala
object Example {
  final given g: Object()
}

Error

scala
-- [E147] Syntax Warning: example.scala:2:2 ------------------------------------
2 |  final given g: Object()
  |  ^^^^^
  |  Modifier final is redundant for this definition

Solution

scala
object Example {
  // Remove the redundant `final` modifier - givens are implicitly final
  given g: Object()
}
<!-- SOURCE-ONLY: Remove the notice below once this page has been manually updated. --> <aside class="warning"> This reference page was created with LLM assistance - the description of the error code may not be accurate or cover all possible scenarios. </aside>