Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
eernstg opened this issue Jul 4, 2024 · 1 comment
Assignees
Labels
analyzer-linter Issues with the analyzer's support for the linter package area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. linter-false-positive P2 A bug or feature request we're likely to work on type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@eernstg
Copy link
Member

eernstg commented Jul 4, 2024

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.

@srawlins srawlins added type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) P2 A bug or feature request we're likely to work on labels Jul 15, 2024
@srawlins srawlins self-assigned this Aug 17, 2024
copybara-service bot referenced this issue Aug 19, 2024
Fixes https://github.com/dart-lang/linter/issues/5010

Cq-Include-Trybots: luci.dart.try:flutter-analyze-try,analyzer-win-release-try,pkg-win-release-try
Change-Id: Id302aceb24bb9a80f0f13b3ec91b7a57c09a7d52
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/381101
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
@eernstg eernstg closed this as completed Aug 20, 2024
@eernstg
Copy link
Member Author

eernstg commented Aug 20, 2024

🎉

@devoncarew devoncarew transferred this issue from dart-lang/linter Nov 15, 2024
@devoncarew devoncarew added analyzer-linter Issues with the analyzer's support for the linter package area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. labels Nov 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analyzer-linter Issues with the analyzer's support for the linter package area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. linter-false-positive P2 A bug or feature request we're likely to work on type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

3 participants