Skip to content

Analyzer ignores type arguments of constants in constant equality checks. #54356

Closed
@lrhn

Description

@lrhn

Example:

void main() {
  const il = <int>[2, 3];
  const nl = <num>[2, 3];
  const v1 = (il == nl) ? (1 ~/ 0) : 0; // Analyzer error
  const v2 = identical(il, nl) ? (1 ~/ 0) : 0;
  
  const iz = <int>{2, 3};
  const nz = <num>{2, 3};
  const v3 = (iz == nz) ? (1 ~/ 0) : 0; // Analyzer error
  const v4 = identical(iz, nz) ? (1 ~/ 0) : 0;
  
  const im = <int, int>{2: 0, 3: 0};
  const nm = <num, int>{2: 0, 3: 0};
  const v5 = (im == nm) ? (1 ~/ 0) : 0; // Analyzer error
  const v6 = identical(im, nm) ? (1 ~/ 0) : 0;

  const ic = C<int>(1);
  const nc = C<num>(1);
  const v7 = (ic == nc) ? (1 ~/ 0) : 0; // Analyzer error
  const v8 = identical(ic, nc) ? (1 ~/ 0) : 0;
}

class C<T> {
  final T v;
  const C(this.v);
}

Here the analyzer considers the constant values equal if they have the same state, but they are not identical, and the types in question do not override Object.operator==, so equality for those objects is identity.

In every example here, the == check should give false.

CFE has no issue.

Metadata

Metadata

Assignees

Labels

P2A bug or feature request we're likely to work onanalyzer-constantsdart-model-analyzer-specIssues with the analyzer's implementation of the language speclegacy-area-analyzerUse area-devexp instead.type-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