Skip to content

The analyzer should have a "Related Types" analysis #32319

@johnniwinther

Description

@johnniwinther

The analyzer should include a Related Types analysis to flag errors like

m1(int i, String s) => i == s; // Trivially false unless i == s == null
m2(int i, Iterable<String> list) => list.contains(i); // Trivially false unless i == null
m3(int i, Map<String, int> map) => map[i]; // Trivially null unless i == null

A first implementation of the analysis could be hardwired to platform classes similarly to the EC bugs and GC bugs in FindBugs.

Determining which classes are unrelated should take built-in "final" classes like int and String into account, but also (with a lower severity) use the 'closed world' of all known classes to catch errors like:

class A {}
class B {}
m4(A a, Iterable<B> list) => list.contains(a); // Trivially false unless a == null

@stereotype441

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-packageIssues related to package:analyzertype-enhancementA request for a change that isn't a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions