type_ parameter_ supertype_ of_ its_ bound
'{0}' can't be a supertype of its upper bound.
Description
#
The analyzer produces this diagnostic when the bound of a type parameter
(the type following the
extends
keyword) is either directly or indirectly
the type parameter itself. Stating that the type parameter must be the same
as itself or a subtype of itself or a subtype of itself isn't helpful
because it will always be the same as itself.
Examples
#
The following code produces this diagnostic because the bound of
T
is
T
:
class C<T extends T> {}
The following code produces this diagnostic because the bound of
T1
is
T2
, and the bound of
T2
is
T1
, effectively making the bound of
T1
be
T1
:
class C<T1 extends T2, T2 extends T1> {}
Common fixes
#If the type parameter needs to be a subclass of some type, then replace the bound with the required type:
class C<T extends num> {}
If the type parameter can be any type, then remove the extends
clause:
class C<T> {}
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.