Skip to content

[Wildcard Variables][spec] Late, wildcarded variables #3798

@eernstg

Description

@eernstg

We could make it an error, or we could lint it, but an initializing expression in a late variable declaration should presumably be recognized as dead code if the variable is wildcarded (that is, it is local and has the name _):

int f() {
  print('Work really hard on finding that int!');
  return 42; // got'yer
}

void main() {
  late int _ = f();
  late final int _ = f();
  // ... no matter what, we will not find that int ...
}

Similarly, a wildcarded late variable with no initializing expression can not be evaluated, and it can not have a new value assigned. So the variable itself would be "dead memory". Error? Lint? OK?

void main() {
  late int _;
  late final int _;
  // ... that memory is wasted ...
}

Perhaps we should just say that it is an error for a late variable to be wildcarded.

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requestedwildcard-variablesThe wildcard-variables feature

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions