Skip to content

[NNBD] Type promotion fails for variable uses in anonymous functions #1536

Open
@nex3

Description

@nex3

The following function:

int foo({int? arg}) {
  arg = 0;
  return (() => arg)();
}

Produces this error:

  error • A value of type 'int?' can't be returned from the function 'foo' because it has a return type of 'int'. • test.dart:3:10 • return_of_invalid_type

Despite the fact that arg will clearly always be non-null when it's returned. There's not even a hypothetical risk that arg will be reassigned to null between the function being created and being invoked, since the non-nullable assignment appears before the function is created and no nullable assignments exist anywhere.

Metadata

Metadata

Assignees

No one assigned

    Labels

    flow-analysisDiscussions about possible future improvements to flow analysis

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions