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>() {}
}
Was this page's content helpful?
Thank you for your feedback!
Provide details Thank you for your feedback! Please let us know what we can do to improve.
Provide details Unless stated otherwise, the documentation on this site reflects Dart 3.8.1. Page last updated on 2025-05-08. View source or report an issue.