Skip to content

Potentially spurious static type computation in the Analyzer #56963

@chloestefantsova

Description

@chloestefantsova

Consider the following code:

extension on int? {
  int? operator+(int? other) {
    if (this != null && other != null) {
      return this! + other;
    } else {
      return null;
    }
  }
}

int test(int? x) {
  return ++x ?? 10;
}

The expected static type of ++x is int?, given the return type of operator+. However, the Analyzer reports the following warning:

warning - qwerty.dart:12:17 - The left operand can't be null, so the right operand is never executed. Try removing the operator and the right operand. - dead_null_aware_expression

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.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