Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upMigrate tests to null-safety #67692
Migrate tests to null-safety #67692
Conversation
|
LGTM |
| @@ -55,7 +53,7 @@ class _TimePickerLauncher extends StatelessWidget { | |||
| } | |||
| } | |||
|
|
|||
| Future<Offset> startPicker( | |||
| Future<Offset?> startPicker( | |||
justinmc
Oct 9, 2020
Contributor
First time I've seen nullable type parameters.
First time I've seen nullable type parameters.
| @@ -419,7 +417,7 @@ void _tests() { | |||
| ); | |||
|
|
|||
| // Ensure we preserve day period as we roll over. | |||
| final dynamic pickerState = tester.state(_timePickerDialog); | |||
| final dynamic pickerState = tester.state(_timePickerDialog); // ignore: unnecessary_nullable_for_final_variable_declarations | |||
justinmc
Oct 9, 2020
Contributor
Why was the ignore needed here? For my own curiosity.
Why was the ignore needed here? For my own curiosity.
shihaohong
Oct 9, 2020
Contributor
I'm curious too, tried looking in the codebase for some explanation but couldn't find one. It seems like it has something to do with using dynamic as a type?
I'm curious too, tried looking in the codebase for some explanation but couldn't find one. It seems like it has something to do with using dynamic as a type?
goderbauer
Oct 9, 2020
Author
Member
NNBD comes with this new lint: https://dart-lang.github.io/linter/lints/unnecessary_nullable_for_final_variable_declarations.html
Basically, if you have a final variable and assign a non-null value to it, the type of that variable should also be non-null. This makes totally sense in normal code. In this case however, we do not have access to the actual type _TimePickerDialogState, which is a private not visible in the test. To still get access to it, the test declares it as dynamic, so we can call any method we want on it and test the internals of the private class. It's a hack, you should never to this in application code.
Unfortunately, dynamic is a nullable type, triggering the warning.
NNBD comes with this new lint: https://dart-lang.github.io/linter/lints/unnecessary_nullable_for_final_variable_declarations.html
Basically, if you have a final variable and assign a non-null value to it, the type of that variable should also be non-null. This makes totally sense in normal code. In this case however, we do not have access to the actual type _TimePickerDialogState, which is a private not visible in the test. To still get access to it, the test declares it as dynamic, so we can call any method we want on it and test the internals of the private class. It's a hack, you should never to this in application code.
Unfortunately, dynamic is a nullable type, triggering the warning.
goderbauer
Oct 9, 2020
Author
Member
I've actually filed dart-lang/linter#2282 with the linter team to see if this lint is appropriate for dynamic variables. It does seem a little odd.
I've actually filed dart-lang/linter#2282 with the linter team to see if this lint is appropriate for dynamic variables. It does seem a little odd.
| @@ -170,50 +168,6 @@ void main() { | |||
| }, | |||
| ); | |||
|
|
|||
| testWidgets('children property cannot be null', (WidgetTester tester) async { | |||
justinmc
Oct 9, 2020
Contributor
Awesome that we can remove whole tests.
Awesome that we can remove whole tests.
|
LGTM |
| @@ -170,50 +168,6 @@ void main() { | |||
| }, | |||
| ); | |||
|
|
|||
| testWidgets('children property cannot be null', (WidgetTester tester) async { | |||
shihaohong
Oct 9, 2020
Contributor
Pretty cool side effect of NNBD
Pretty cool side effect of NNBD
793678d
into
flutter:master
No description provided.