Skip to content

Migration tool gets distracted by assert functions #42380

Closed
@a14n

Description

@a14n

With the following code:

int get i {
  int result;
  assert(() {
    if (false) {
      result = 1;
    }
    return true;
  }());
  if (result == null) {
    throw Error();
  }
  return result;
}

the migration tool suggests:

int? get i {
  int? result;
  assert(() {
    if (false) {
      result = 1;
    }
    return true;
  }());
  if (result == null) {
    throw Error();
  }
  return result;
}

but the return type of the method should be int instead of int? because of the null gard at the end.

Without assert the migration tool works correctly and suggest:

int  get i {
  int? result;
  // assert(() {
  //   if (false) {
  //     result = 1;
  //   }
  //   return true;
  // }());
  if (result == null) {
    throw Error();
  }
  return result;
}

Metadata

Metadata

Labels

NNBDIssues related to NNBD Releasearea-migration (deprecated)Deprecated: this label is no longer actively used (was: issues with the `dart migrate` tool).nnbd-migration-correctness-exampleConcrete examples of the migration engine producing an incorrect result on a phase 1 package

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions