Skip to content

Migration: consider handling compound assignments where the read type is nullable #38676

Closed
@stereotype441

Description

@stereotype441

It's not clear what the migration tool should do if it encounters a compound assignment where the read type is nullable, e.g.:

class C {
  C operator+(C other) { ... }
}
void f(C/*?*/ x, C y) {
  x += y;
}

The only way to properly migrate the expression x += y is to first desugar it to x = x + y and then add the appropriate null check to produce x = x! + y. But this can’t be done in the general case where the LHS assignment might be a property access or an index expression, because duplicating the LHS would change semantics.

In https://dart-review.googlesource.com/c/sdk/+/119525 we simply report the situation as a problem for the user to fix manually. But if this comes up frequently enough we may wish to do something different, for example:

  • Go ahead and desugar the expression in cases where it is semantics preserving, or
  • Go ahead and desugar the expression in all cases, and warn the user if semantics might have changed

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