E226: Type Parameter Shadows Type
This warning is emitted when a type parameter shadows a type already in scope.
Shadowing can make code harder to read and can hide a type you intended to reference. This warning helps catch those cases early.
This warning is enabled with the -Wshadow:type-parameter-shadow compiler flag.
Example
class Outer:
trait D
def parse[D](in: D) = in
Warning
-- [E226] Naming Warning: example.scala:3:12 -----------------------------------
3 | def parse[D](in: D) = in
| ^
| Type parameter D for method parse shadows the type defined by trait D
|-----------------------------------------------------------------------------
| Explanation (enabled by `-explain`)
|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| A type parameter shadows another type that is already in scope.
| This can lead to confusion and potential errors.
| Consider renaming the type parameter to avoid the shadowing.
-----------------------------------------------------------------------------
Solution
Rename the type parameter so it no longer shadows the existing type:
class Outer:
trait D
def parse[D2](in: D2) = in
In this article