Open davidmorgan opened 2 months ago
Should we have a lint "don't use operator== on extension types"? If so it should presumably also catch them being used in
Set
s or asMap
keys.
Makes sense! .. but we might add another requirement: Warn against using operator ==
==
for the representation object differs from the desired behavior of ==
for the extension type.For example, we might easily encounter situations where the representation object uses the operator ==
from Object
(at least in the statically known type, and "as far as we know" in subtypes as well), and the same kind of equality is a good match for the extension type.
Perhaps the lint could detect metadata like @equatable extension type ....
? Or perhaps it's better to assume that ==
is OK by default, and then have @noEqualsEquals extension type ....
on extension types where it isn't OK?
Since the JSON types are extension types over
Map
,operator==
will mostly not compare by value and will fail.In https://github.com/dart-lang/macros/pull/60 I add an
equals
method that does work.This is surprising and likely to trip people up.
Brainstorming:
Should we have a lint "don't use operator== on extension types"? If so it should presumably also catch them being used in
Set
s or asMap
keys.Another thing we could do, since we usually control the underlying types, would be to make those implementations (e.g.
_TypedMap
,_GrowableMap
) have deep equality / hash code. But that would be confusing if people use thefromJson
contructors with standard maps.