-
-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
covariant
in operator==
override for improved type safe…
…ty (#180)
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,13 +48,11 @@ macro class Equatable implements ClassDeclarationsMacro, ClassDefinitionMacro { | |
ClassDeclaration clazz, | ||
MemberDeclarationBuilder builder, | ||
) async { | ||
final (object, boolean) = await ( | ||
builder.codeFrom(_dartCore, 'Object'), | ||
builder.codeFrom(_dartCore, 'bool'), | ||
).wait; | ||
final boolean = await builder.codeFrom(_dartCore, 'bool'); | ||
|
||
return builder.declareInType( | ||
DeclarationCode.fromParts( | ||
['external ', boolean, ' operator==(', object, ' other);'], | ||
['external ', boolean, ' operator==(', ' covariant ${clazz.identifier.name}', ' other);'], | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
felangel
Author
Owner
|
||
), | ||
); | ||
} | ||
|
While this seems good on surface, this will create a silent runtime error when object comes from (or to) external library in form of
Object
/dynamic
or more commonlyList<Object>
(for example cache).Such error would be hard to debug, I think its more reasonable that object is not equal to unrelated one than it's possible that
==
will randomly throw an error.