Skip to content

Detect impossible equalities #26311

Closed
Closed
@ochafik

Description

@ochafik

Strong-mode could / should prevent accidental heterogeneous (in)equalities "when it can":

var x = "1";
if (x == 2) print("Hey");
//  ^
// [error]: A 'String' instance can never be equal to a 'num'.

Of course, this is only possible (accurate) for classes that can't be implemented by user classes (String, num, etc):

class Foo {}
class Bar {}
class FooBar implements Foo, Bar {}

Foo foo = ...;
Bar bar = ...;
if (foo == bar) // Foo and Bar aren't related, yet this can be true because of FooBar

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-languageDart language related items (some items might be better tracked at github.com/dart-lang/language).

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions