Skip to content

Null safety promotion breaks when using local functions #45094

Closed
@Kavantix

Description

@Kavantix

Example code that is incorrectly analyzed:

void main() {
  String? test;
  void t() {
    test = null;
  }
  if (test != null) {
    test += ''; // error test can be null
  }
}

This is the same on all dart versions that support nnbd

I already read here that this might be by design but it is quite annoying and at least the error could be better (took me a while to figure out it was the local function that was breaking it).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions