Skip to content

Nullability promotion issue with local variable usages in iterators #51183

Closed
@AlexV525

Description

@AlexV525

This tracker is for issues related to: Analyzer.

When I was developing in flutter_tools, I found a weird promotion with the nullability of a local variable.

image

A simple example for this issue:

void main() {
  final String? test;
  final List<String> testList = [];
  if (1 * 2 == 2) {
    test = 'Yes';
  } else {
    test = null;
  }
  if (test != null) {
    testList.removeWhere((e) => e.contains(test)); // <-- Raises exception.
  }
}

I was wondering at this point why the variable cannot be proofed as non-null.

Metadata

Metadata

Assignees

No one assigned

    Labels

    closed-duplicateClosed in favor of an existing report

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions