Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VM doesn't always throw when expanding a list after adding an element #42502

Closed
leafpetersen opened this issue Jun 25, 2020 · 1 comment
Closed
Assignees
Labels
area-vm Use area-vm for VM related issues, including code coverage, FFI, and the AOT and JIT backends. NNBD Issues related to NNBD Release

Comments

@leafpetersen
Copy link
Member

Calling the List.length setter to expand the size of a list with non-nullable type should throw an error in null safe code. The VM sometimes fails to throw this exception if it follows a call to List.add. The code below shows this: the first call to the length setter throws, but after a call to List.add, subsequent calls do not throw, and null can be observed as the contents of a non-nullable list.

cc @nshahan @alexmarkov

void throws(void Function() f) {
  try {
    f();
  } catch (e, s) {
    return;
  }
  throw "Expected to throw";
}

void main() {
  List<int> x = [];
  throws(() => x.length = x.length + 1);
  print(x.length);
  x.add(222);
  print(x.length);
  x.length = 2;
  print(x.length);
  x.length = x.length + 1;
  print(x.length);
  for (int i = 0; i < x.length; i++) {
    print(x[i]);
  }
}
@leafpetersen leafpetersen added area-vm Use area-vm for VM related issues, including code coverage, FFI, and the AOT and JIT backends. NNBD Issues related to NNBD Release labels Jun 25, 2020
@leafpetersen
Copy link
Member Author

Note that there are a some incorrectly migrated Dart 2 language tests which are passing only because of this failure, and will begin to fail once this issue is fixed. cc @munificent . Feel free to approve these failures and file an issue for @munificent and myself to triage and fix them (the fix depends somewhat on the resolution of this issue).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-vm Use area-vm for VM related issues, including code coverage, FFI, and the AOT and JIT backends. NNBD Issues related to NNBD Release
Projects
None yet
Development

No branches or pull requests

2 participants