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
:
class C<T> {
void m<T>() {}
}
Common fixes
#Rename one of the type parameters:
class C<T> {
void m<S>() {}
}
Unless stated otherwise, the documentation on this site reflects Dart 3.9.2. Page last updated on 2025-9-1. View source or report an issue.