Open
Description
Consider the following example, based on this comment:
class NeverEqual {
Never operator ==(Object? o) => throw 0;
}
void main() {
NeverEqual? neverEqual = NeverEqual() as dynamic, other;
Object? o = true;
if (o is! int) neverEqual == other; // Incorrect to assume that this throws.
print(o.toRadixString(16)); // Unsound.
}
This shows that it is unsound to assume that the type of an <equalityExpression>
is Never
, even in the case where the corresponding declaration of operator ==
has return type Never
. Equality expressions should always have the type bool
.
However, the analyzer (DartPad based on Dart SDK 3.3.0-16.0.dev) does not report any errors on the line marked 'Unsound', which implies that it considers neverEqual == other
to be an expression that cannot complete normally.