Skip to content

Commit

Permalink
Make integer literals trivial, except when type is double
Browse files Browse the repository at this point in the history
Change-Id: I27518d86b389ca455144111c18f18e995ae5ac4d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/389702
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Commit-Queue: Erik Ernst <eernst@google.com>
  • Loading branch information
eernstg authored and Commit Queue committed Oct 14, 2024
1 parent 7e18fad commit b72e453
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
6 changes: 3 additions & 3 deletions pkg/linter/lib/src/util/obvious_types.dart
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,9 @@ extension ExpressionExtensions on Expression {
return true;
case Literal():
// An atomic literal: `Literal` and not `TypedLiteral`.
if (self is IntegerLiteral) {
// An integer literal with type `double` is clearly not trivial,
// but even an `int` integer literal may be considered ambiguous.
if (self is IntegerLiteral &&
(self.staticType?.isDartCoreDouble ?? true)) {
// An integer literal with static type `double` is not trivial.
return false;
}
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,11 +227,13 @@ f() {
}

test_literal_int() async {
await assertNoDiagnostics(r'''
await assertDiagnostics(r'''
f() {
int i = 1;
}
''');
''', [
lint(8, 3),
]);
}

// `Null` is not obvious, the inferred type is `dynamic`.
Expand Down

0 comments on commit b72e453

Please sign in to comment.