void_ checks
Assignment to a variable of type 'void'.
Description
#
The analyzer produces this diagnostic when a value is assigned to a
variable of type
void
.
It isn't possible to access the value of such a variable, so the assignment has no value.
Example
#
The following code produces this diagnostic because the field
value
has
the type
void
, but a value is being assigned to it:
class A<T> {
T? value;
}
void f(A<void> a) {
a.value = 1;
}
The following code produces this diagnostic because the type of the
parameter
p
in the method
m
is
void
, but a value is being assigned
to it in the invocation:
class A<T> {
void m(T p) { }
}
void f(A<void> a) {
a.m(1);
}
Common fixes
#If the type of the variable is incorrect, then change the type of the variable:
class A<T> {
T? value;
}
void f(A<int> a) {
a.value = 1;
}
If the type of the variable is correct, then remove the assignment:
class A<T> {
T? value;
}
void f(A<void> a) {}
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.