E227: Private Shadows Type
This warning is emitted when a private field shadows an inherited field with the same name.
Shadowing inherited fields can make code harder to understand because references in the subclass may no longer refer to the member from the parent type.
This warning is enabled with the -Wshadow:private-shadow compiler flag.
Example
class Parent:
val value = 1
class Child extends Parent:
private val value = 2
Warning
-- [E227] Naming Warning: example.scala:5:2 ------------------------------------
5 | private val value = 2
| ^
| value value shadows field value inherited from class Parent
|-----------------------------------------------------------------------------
| Explanation (enabled by `-explain`)
|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| A private field shadows an inherited field with the same name.
| This can lead to confusion as the inherited field becomes inaccessible.
| Consider renaming the private field to avoid the shadowing.
-----------------------------------------------------------------------------
Solution
Rename the private field so it no longer shadows the inherited one:
class Parent:
val value = 1
class Child extends Parent:
private val localValue = 2
In this article