Skip to content

prefer_typing_uninitialized_variables and omit_local_variable_types are NOT incompatible! #58129

Closed
dart-archive/linter
#2019
@kevmoo

Description

@kevmoo

This is a not-uncommon combination!

omit_local_variable_types should apply when the type can be inferred from an assignment – which is most of the time.

But in the case below, it cannot be inferred – so the type should be provided!

int bob() {
  int thing;
  if (true) {
    thing = 1;
  } else {
    thing = 2;
  }
  return thing;
}

RE #58111

Came from dart-archive/linter@a5b1a8b

Just started seeing this warning in the SDK as of 7eaafa0

Metadata

Metadata

Assignees

Labels

devexp-linterIssues with the analyzer's support for the linter packagelegacy-area-analyzerUse area-devexp instead.type-bugIncorrect behavior (everything from a crash to more subtle misbehavior)

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions