Skip to content

List.removeLast() throws an inconsistent error #26087

@nex3

Description

@nex3

The native List type, at least on the VM, throws a RangeError if removeLast() is called on an empty list. A list created using ListBase or ListMixin, on the other hand, throws a StateError in the same situation. The following reproduces this:

import 'dart:collection';

class CustomList extends ListBase {
  final List _inner;

  int get length => _inner.length;
  set length(int value) => _inner.length = value;

  CustomList() : _inner = [];

  operator [](int index) => _inner[index];
  operator []=(int index, value) => _inner[index] = value;
}

void main() {
  try {
    new CustomList().removeLast();
  } catch (error) {
    print(error);
  }

  try {
    [].removeLast();
  } catch (error) {
    print(error);
  }
}

I'm using 8922198.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-core-librarySDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries.closed-not-plannedClosed as we don't intend to take action on the reported issuelibrary-coretype-bugIncorrect behavior (everything from a crash to more subtle misbehavior)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions