extension_override_without_access
An extension override can only be used to access instance members.
Description
#The analyzer produces this diagnostic when an extension override is found that isn't being used to access one of the members of the extension. The extension override syntax doesn't have any runtime semantics; it only controls which member is selected at compile time.
Example
#The following code produces this diagnostic because E(i)
isn't an expression:
extension E on int {
int get a => 0;
}
void f(int i) {
print(E(i));
}
Common fixes
#If you want to invoke one of the members of the extension, then add the invocation:
extension E on int {
int get a => 0;
}
void f(int i) {
print(E(i).a);
}
If you don't want to invoke a member, then unwrap the argument:
extension E on int {
int get a => 0;
}
void f(int i) {
print(i);
}
Unless stated otherwise, the documentation on this site reflects Dart 3.7.3. Page last updated on 2025-05-08. View source or report an issue.