disallowed_type_instantiation_expression
Only a generic type, generic function, generic instance method, or generic constructor can have type arguments.
Description
#The analyzer produces this diagnostic when an expression with a value that is anything other than one of the allowed kinds of values is followed by type arguments. The allowed kinds of values are:
- generic types,
- generic constructors, and
- generic functions, including top-level functions, static and instance members, and local functions.
Example
#The following code produces this diagnostic because i
is a top-level variable, which isn't one of the allowed cases:
dart
int i = 1;
void f() {
print(i<int>);
}
Common fixes
#If the referenced value is correct, then remove the type arguments:
dart
int i = 1;
void f() {
print(i);
}
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.