Open
Description
I would like to have a better warning when writing method that needs to account for all properties.
For example when a class overrides operator== and hashCode of a class.
class A {
int? a;
int? b;
void printAll() {
if (a != null) {
print(a);
}
if (b != null) {
print(b);
}
}
@override
bool operator ==(Object other) {
return other is A && other.a == a && other.b == b;
}
@override
int get hashCode => Object.hashAll([a, b]);
}
it is very easy to forgot to update these method when adding new propperty which cause obscure bugs.
class A {
int? a;
int? b;
int? c;
void printAll() {
if (a != null) {
print(a);
}
if (b!= null) {
print(b);
}
// may forgot to add
if (c!= null) {
print(c);
}
}
@override
bool operator ==(Object other) {
return other is A && other.a == a && other.b == b
// forgot
&& other.c ==c ;
}
@override
int get hashCode => Object.hashAll([a, b, /*forgot*/ c]);
}
I hope we could have a way to get warming about cases like this.