Skip to content

Should null-check/assert patterns produce a warning on a constant with a nullable type? #59871

@sgrekhov

Description

@sgrekhov

Analyzer produces a warning in case of use of null-check and null-asser patterns on a constant of nullable type.

const int? one = 1;

main() {
  int x = 1;
  if(x case one?) { // unnecessary_null_check_pattern warning
    print("One");
  }
  if(x case one!) { // unnecessary_null_assert_pattern warning
    print("One");
  }
}

Please confirm if it is really intended.

cc @eernstg

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3A lower priority bug or feature requestarea-devexpFor issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages.devexp-uxtype-questionA question about expected behavior or functionality

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions