Skip to main content

avoid_shadowing_type_parameters

The type parameter '{0}' shadows a type parameter from the enclosing {1}.

Description

#

The analyzer produces this diagnostic when a type parameter shadows a type parameter from an enclosing declaration.

Shadowing a type parameter with a different type parameter can lead to subtle bugs that are difficult to debug.

Example

#

The following code produces this diagnostic because the type parameter T defined by the method m shadows the type parameter T defined by the class C:

dart
class C<T> {
  void m<T>() {}
}

Common fixes

#

Rename one of the type parameters:

dart
class C<T> {
  void m<S>() {}
}