Skip to content

Commit b72e453

Browse files
eernstgCommit Queue
authored andcommitted
Make integer literals trivial, except when type is double
Change-Id: I27518d86b389ca455144111c18f18e995ae5ac4d Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/389702 Reviewed-by: Phil Quitslund <[email protected]> Commit-Queue: Erik Ernst <[email protected]>
1 parent 7e18fad commit b72e453

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

pkg/linter/lib/src/util/obvious_types.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,9 @@ extension ExpressionExtensions on Expression {
127127
return true;
128128
case Literal():
129129
// An atomic literal: `Literal` and not `TypedLiteral`.
130-
if (self is IntegerLiteral) {
131-
// An integer literal with type `double` is clearly not trivial,
132-
// but even an `int` integer literal may be considered ambiguous.
130+
if (self is IntegerLiteral &&
131+
(self.staticType?.isDartCoreDouble ?? true)) {
132+
// An integer literal with static type `double` is not trivial.
133133
return false;
134134
}
135135
return true;

pkg/linter/test/rules/omit_obvious_local_variable_types_test.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,11 +227,13 @@ f() {
227227
}
228228

229229
test_literal_int() async {
230-
await assertNoDiagnostics(r'''
230+
await assertDiagnostics(r'''
231231
f() {
232232
int i = 1;
233233
}
234-
''');
234+
''', [
235+
lint(8, 3),
236+
]);
235237
}
236238

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

0 commit comments

Comments
 (0)