Skip to content

omit_local_variable_types reports a false positive for a coerced integer literal #57105

@eernstg

Description

@eernstg

Consider the following program:

void main() {
  double d = 1;
}

When omit_local_variable_types is enabled it reports that the type annotation double is unnecessary.

This is wrong because the value of the integer literal at run time is actually an instance of double, and if we change the context type to _ by removing the type annotation (and adding var or final) then its value will be an int, which may cause type errors below the declaration, and which is moreover an observable difference on some platforms at run time.

Metadata

Metadata

Assignees

Labels

P2A bug or feature request we're likely to work ondevexp-linterIssues with the analyzer's support for the linter packagelegacy-area-analyzerUse area-devexp instead.linter-false-positiveIssues related to lint rules that report a problem when it isn't a problem.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