Skip to content

Editor warning for using the return value of a void function is hard to understand #8050

@alan-knight

Description

@alan-knight

Consider the following program, which in lines 6 and 7, gives a warning that "expression does not yield a value" for an if statement and the left-hand side of an assignment statement respectively, but does not warn for line 5, which is where the real problem is, that we are assigning the result of a void function to a variable.

main() {
  for (var i = 0; i < 10; i++) {
    for (var each in [1, 2, 3, 4, 5]) {
      var newFoo = foo(i, each);
      if (newFoo != null) {
        newFoo[3] = 4;
      }
    }
  }
}
void foo(x, y) => print("$x, $y");

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions