Skip to content
This repository has been archived by the owner on Nov 20, 2024. It is now read-only.

nnbd migration #2452

Merged
merged 17 commits into from
Feb 12, 2021
Merged

nnbd migration #2452

merged 17 commits into from
Feb 12, 2021

Conversation

pq
Copy link
Member

@pq pq commented Feb 12, 2021

First cut at migration using the migration tool.

As discussed, I'd like to land this (if green) and iterate on improvements.

See: dart-lang/sdk#58322

@google-cla google-cla bot added the cla: yes label Feb 12, 2021
@pq pq marked this pull request as draft February 12, 2021 21:48
@pq pq changed the title nnbd (tool) migration nnbd migration Feb 12, 2021
@coveralls
Copy link

coveralls commented Feb 12, 2021

Coverage Status

Coverage decreased (-0.03%) to 96.599% when pulling cbeb372 on nnbd_auto_migration into 4f06a0e on master.

Copy link
Member

@bwilkerson bwilkerson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I thought you were ready for a review, but I've had to refresh several times since I started, and now I have no idea what I have and haven't looked at.

It probably doesn't matter, though, because there's way too much to do a decent review, so I'll just have to trust that you'll clean it up after you commit it. I made a couple of specific requests near the beginning, but in general here's a list of the kinds of issues I saw that I think should be cleaned up:

  1. Every use of the null check operator (!) should be removed. There are lots of different ways to do that depending on the context, every single one should be removed, or there should be a comment explaining why it isn't possible to get rid of it.

  2. Every question mark that can be removed should be. There are lots of places where there are nullable types that I think we can get rid of. One common pattern before was to check for null argument values in every method, but the code is much cleaner in a null safe world if we check at every call site.

  3. Every local variable that was created in order to hold a casted value should be removed.

@@ -268,7 +268,7 @@ bool _checkForSimpleSetter(MethodDeclaration setter, Expression expression) {
if (expression is! AssignmentExpression) {
return false;
}
final assignment = expression as AssignmentExpression;
final assignment = expression;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This assignment is unlikely to be necessary now.

@@ -14,15 +14,15 @@ import 'util/score_utils.dart';
// Number of times to perform linting to get stable benchmarks.
const benchmarkRuns = 10;

String getLineContents(int lineNumber, AnalysisError error) {
String getLineContents(int? lineNumber, AnalysisError error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lineNumber should not be nullable.

@@ -14,15 +14,15 @@ import 'util/score_utils.dart';
// Number of times to perform linting to get stable benchmarks.
const benchmarkRuns = 10;

String getLineContents(int lineNumber, AnalysisError error) {
String getLineContents(int? lineNumber, AnalysisError error) {
final path = error.source.fullName;
final file = File(path);
String failureDetails;
if (!file.existsSync()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It isn't part of the migration, but there's no value in testing whether the file exists. Just read the content and catch the exception if the file doesn't exist.

final bool machineOutput;
final bool quiet;
final bool? machineOutput;
final bool? quiet;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bool? is a strong signal that there's a bug in the code. Consider making these non-nullable and clean up the code.

@@ -322,10 +322,10 @@ class SimpleFormatter implements ReportFormatter {

class _Stat implements Comparable<_Stat> {
final String name;
final int elapsed;
final int? elapsed;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be non-nullable.

@@ -93,14 +93,14 @@ class _Visitor extends SimpleAstVisitor<void> {
_checkNodeOnNextLine(node.body, node.rightParenthesis.end);
}

void _checkNodeOnNextLine(AstNode node, int controlEnd) {
void _checkNodeOnNextLine(AstNode? node, int controlEnd) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

node should be non-nullable.

@@ -82,7 +82,7 @@ class _Visitor extends SimpleAstVisitor<void> {
return;
}

final classElement = parentElement as ClassElement;
final classElement = parentElement;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This variable is unnecessary now.

_visitFunctionBody(node.body);
}
}

void _visitFunctionBody(FunctionBody node) {
void _visitFunctionBody(FunctionBody? node) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

node should be non-nullable. The analyzer APIs have been updated to disallow any function from having a null body. The compiler won't catch the change when you update to the next version of analyzer.

pubspec.yaml Outdated Show resolved Hide resolved
@pq pq marked this pull request as ready for review February 12, 2021 23:35
@pq
Copy link
Member Author

pq commented Feb 12, 2021

As described in dart-lang/sdk#58322, landing this as-is with tidying to follow.

@pq pq merged commit fd0a11f into master Feb 12, 2021
@pq pq deleted the nnbd_auto_migration branch February 12, 2021 23:48
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants