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) {}
除非另有说明,文档之所提及适用于 Dart 3.7.3 版本,本页面最后更新时间: 2025-05-08。 查看文档源码 或者 报告页面问题。