Skip to content

Commit b0a90ae

Browse files
authored
Enable strict-inference (flutter#135043)
Avoids that dynamic accidentally sneaks in, see https://dart.dev/tools/analysis#enabling-additional-type-checks
1 parent 96a4ae9 commit b0a90ae

File tree

27 files changed

+63
-55
lines changed

27 files changed

+63
-55
lines changed

analysis_options.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
analyzer:
1818
language:
1919
strict-casts: true
20+
strict-inference: true
2021
strict-raw-types: true
2122
errors:
2223
# allow self-reference to deprecated members (we do this because otherwise we have

dev/bots/test/analyze-snippet-code-test-dart-ui/ui.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ library dart.ui;
1111
///
1212
/// ```dart
1313
/// class MyStringBuffer {
14-
/// error; // error (missing_const_final_var_or_type, always_specify_types)
14+
/// error; // error (prefer_typing_uninitialized_variables, inference_failure_on_uninitialized_variable, missing_const_final_var_or_type)
1515
///
1616
/// StringBuffer _buffer = StringBuffer(); // error (prefer_final_fields, unused_field)
1717
/// }

dev/bots/test/analyze-snippet-code-test-input/custom_imports_broken.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ String? bar;
1616

1717
/// error: widgets library was not imported (not even implicitly).
1818
/// ```dart
19-
/// print(Widget);
19+
/// print(Widget); // error (undefined_identifier)
2020
/// ```
2121
String? foo;

dev/bots/test/analyze-snippet-code-test-input/known_broken_documentation.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@
131131
/// Widget build(BuildContext context) {
132132
/// final String title;
133133
/// return Opacity(
134-
/// key: globalKey, // error (undefined_identifier, argument_type_not_assignable)
134+
/// key: globalKey, // error (undefined_identifier)
135135
/// opacity: _visible ? 1.0 : 0.0,
136136
/// child: Text(title), // error (read_potentially_unassigned_final)
137137
/// );
@@ -144,13 +144,14 @@
144144
/// ```
145145
///
146146
/// ```dart
147-
/// import 'dart:io'; // error (unused_import)/// final Widget p = Placeholder(); // error (undefined_class, undefined_function)
147+
/// import 'dart:io'; // error (unused_import)
148+
/// final Widget p = Placeholder(); // error (undefined_class, undefined_function)
148149
/// ```
149150
///
150151
/// ```dart
151152
/// // (e.g. in a stateful widget)
152153
/// void initState() { // error (must_call_super, annotate_overrides)
153-
/// widget.toString(); // error (undefined_identifier, return_of_invalid_type)
154+
/// widget.toString();
154155
/// }
155156
/// ```
156157
///

dev/bots/test/analyze_snippet_code_test.dart

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,19 @@ const List<String> expectedMainErrors = <String>[
2121
'dev/bots/test/analyze-snippet-code-test-input/known_broken_documentation.dart:134:14: (top-level declaration) (undefined_identifier)',
2222
'dev/bots/test/analyze-snippet-code-test-input/known_broken_documentation.dart:136:21: (top-level declaration) (read_potentially_unassigned_final)',
2323
'dev/bots/test/analyze-snippet-code-test-input/known_broken_documentation.dart:147:12: (self-contained program) (unused_import)',
24-
'dev/bots/test/analyze-snippet-code-test-input/known_broken_documentation.dart:152:10: (stateful widget) (annotate_overrides)',
25-
'dev/bots/test/analyze-snippet-code-test-input/known_broken_documentation.dart:152:10: (stateful widget) (must_call_super)',
26-
'dev/bots/test/analyze-snippet-code-test-input/known_broken_documentation.dart:160:7: (top-level declaration) (undefined_identifier)',
27-
'dev/bots/test/analyze-snippet-code-test-input/known_broken_documentation.dart:164: Found "```" in code but it did not match RegExp: pattern=^ */// *```dart\$ flags= so something is wrong. Line was: "/// ```"',
24+
'dev/bots/test/analyze-snippet-code-test-input/known_broken_documentation.dart:148:11: (self-contained program) (undefined_class)',
25+
'dev/bots/test/analyze-snippet-code-test-input/known_broken_documentation.dart:148:22: (self-contained program) (undefined_function)',
26+
'dev/bots/test/analyze-snippet-code-test-input/known_broken_documentation.dart:153:10: (stateful widget) (annotate_overrides)',
27+
'dev/bots/test/analyze-snippet-code-test-input/known_broken_documentation.dart:153:10: (stateful widget) (must_call_super)',
28+
'dev/bots/test/analyze-snippet-code-test-input/known_broken_documentation.dart:161:7: (top-level declaration) (undefined_identifier)',
29+
'dev/bots/test/analyze-snippet-code-test-input/known_broken_documentation.dart:165: Found "```" in code but it did not match RegExp: pattern=^ */// *```dart\$ flags= so something is wrong. Line was: "/// ```"',
2830
'dev/bots/test/analyze-snippet-code-test-input/short_but_still_broken.dart:9:12: (statement) (invalid_assignment)',
2931
'dev/bots/test/analyze-snippet-code-test-input/short_but_still_broken.dart:18:4: Empty ```dart block in snippet code.',
3032
];
3133

3234
const List<String> expectedUiErrors = <String>[
3335
'dev/bots/test/analyze-snippet-code-test-dart-ui/ui.dart:14:7: (top-level declaration) (prefer_typing_uninitialized_variables)',
36+
'dev/bots/test/analyze-snippet-code-test-dart-ui/ui.dart:14:7: (top-level declaration) (inference_failure_on_uninitialized_variable)',
3437
'dev/bots/test/analyze-snippet-code-test-dart-ui/ui.dart:14:7: (top-level declaration) (missing_const_final_var_or_type)',
3538
'dev/bots/test/analyze-snippet-code-test-dart-ui/ui.dart:16:20: (top-level declaration) (prefer_final_fields)',
3639
'dev/bots/test/analyze-snippet-code-test-dart-ui/ui.dart:16:20: (top-level declaration) (unused_field)',
@@ -69,7 +72,7 @@ void main() {
6972
final List<String> stderrNoDescriptions = stderrLines.map(removeLintDescriptions).toList();
7073
expect(stderrNoDescriptions, <String>[
7174
...expectedMainErrors,
72-
'Found 16 snippet code errors.',
75+
'Found 18 snippet code errors.',
7376
'See the documentation at the top of dev/bots/analyze_snippet_code.dart for details.',
7477
'', // because we end with a newline, split gives us an extra blank line
7578
]);
@@ -93,7 +96,7 @@ void main() {
9396
expect(stderrNoDescriptions, <String>[
9497
...expectedUiErrors,
9598
...expectedMainErrors,
96-
'Found 20 snippet code errors.',
99+
'Found 23 snippet code errors.',
97100
'See the documentation at the top of dev/bots/analyze_snippet_code.dart for details.',
98101
'', // because we end with a newline, split gives us an extra blank line
99102
]);

dev/conductor/core/test/packages_autoroller_test.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ void main() {
170170
await expectLater(
171171
() async {
172172
final Future<void> rollFuture = autoroller.roll();
173-
await controller.stream.drain();
173+
await controller.stream.drain<Object?>();
174174
await rollFuture;
175175
},
176176
throwsA(isA<Exception>().having(
@@ -214,7 +214,7 @@ void main() {
214214
], stdout: '[{"number": 123}]'),
215215
]);
216216
final Future<void> rollFuture = autoroller.roll();
217-
await controller.stream.drain();
217+
await controller.stream.drain<Object?>();
218218
await rollFuture;
219219
expect(processManager, hasNoRemainingExpectations);
220220
expect(stdio.stdout, contains('flutter-pub-roller-bot already has open tool PRs'));
@@ -312,7 +312,7 @@ void main() {
312312
]),
313313
]);
314314
final Future<void> rollFuture = autoroller.roll();
315-
await controller.stream.drain();
315+
await controller.stream.drain<Object?>();
316316
await rollFuture;
317317
expect(processManager, hasNoRemainingExpectations);
318318
});

dev/devicelab/bin/tasks/flutter_engine_group_performance.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const String _activityName = 'MainActivity';
1616
const int _numberOfIterations = 10;
1717

1818
Future<void> _withApkInstall(
19-
String apkPath, String bundleName, Function(AndroidDevice) body) async {
19+
String apkPath, String bundleName, Future<void> Function(AndroidDevice) body) async {
2020
final DeviceDiscovery devices = DeviceDiscovery();
2121
final AndroidDevice device = await devices.workingDevice as AndroidDevice;
2222
await device.unlock();

dev/devicelab/lib/framework/runner.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Future<void> runTasks(
4242
List<String>? taskArgs,
4343
bool useEmulator = false,
4444
@visibleForTesting Map<String, String>? isolateParams,
45-
@visibleForTesting Function(String) print = print,
45+
@visibleForTesting void Function(String) print = print,
4646
@visibleForTesting List<String>? logs,
4747
}) async {
4848
for (final String taskName in taskNames) {

dev/integration_tests/ios_platform_view_tests/lib/main.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ class _ZOrderTestPageState extends State<ZOrderTestPage> {
201201
)),
202202
TextButton(
203203
onPressed: () {
204-
showDialog(
204+
showDialog<void>(
205205
context: context,
206206
builder: (BuildContext context) {
207207
return const SizedBox(

examples/api/lib/material/bottom_navigation_bar/bottom_navigation_bar.2.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ class _BottomNavigationBarExampleState extends State<BottomNavigationBarExample>
9191
}
9292

9393
void showModal(BuildContext context) {
94-
showDialog(
94+
showDialog<void>(
9595
context: context,
9696
builder: (BuildContext context) => AlertDialog(
9797
content: const Text('Example Dialog'),

0 commit comments

Comments
 (0)