Skip to content

Type promotion fails on local function call #47358

Closed
@mnordine

Description

@mnordine

I understand the following may be a tricky scenario for the analyzer, but just putting this here in case it can be fixed:

import 'dart:math' show Random;

void main() {
  int? x;
  if (Random().nextBool()) {
    x = 5;
  }
  
  if (x == null) return;
  
  void f() {
    var y = x * 2; // The operator '*' can't be unconditionally invoked because the receiver can be 'null'.
    print(y);
  }
  
  f();
}

f() is never called when x can be null.

This issue probably exists in some form, but I couldn't find 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