Skip to content

[analyzer] Soundness issue with typing of equality expressions #54083

Open
@eernstg

Description

@eernstg

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3A lower priority bug or feature requestarea-dart-modelFor issues related to conformance to the language spec in the parser, compilers or the CLI analyzer.dart-model-analyzer-specIssues with the analyzer's implementation of the language specsoundnesstype-bugIncorrect behavior (everything from a crash to more subtle misbehavior)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions