Skip to content

Migration incorrectly propagates non-nullability to fields via field formals #38453

@stereotype441

Description

@stereotype441

Consider the following program:

class C {
  int i;                     // (1)
  int j;
  C.one(this.i) : j = i + 1; // (2)
  C.two() : i = null, j = 0; // (3)
}

The migration tool currently considers the field C.i to be non-nullable, so it changes line (3) from i = null to i = null!. This is not a great migration, since clearly the user's intent was for i to be nullable. It would be better to change line (1) from int i; to int? i;.

The reason this is happening is that since the expression i + 1 at (2) unconditionally references i, a hard edge is created from the type of C.one's i parameter to never. And since C.one's i parameter gets its type from the C.i field, this causes the field to be forced to non-null.

What should happen instead is that we should never create hard edges to field formal parameters that have implicit types.

Metadata

Metadata

Assignees

Labels

NNBDIssues related to NNBD Releasearea-migration (deprecated)Deprecated: this label is no longer actively used (was: issues with the `dart migrate` tool).

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions