dart-lang / collection

The collection package for Dart contains a number of separate libraries with utility functions and classes that makes working with collections easier.

Home Page:https://pub.dev/packages/collection

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Slice method will Stack Overflow in certain scenarios

hcanyz opened this issue · comments

commented
import 'package:collection/collection.dart';
import 'package:flutter_test/flutter_test.dart';

void main() {
  test("slice1", () {
    final List<int> someList = [1, 2, 3, 4, 5];
    final List<int> result = someList.slice(0, 3); // return [1, 2, 3]
    result.slice(0, 1); // Stack Overflow
  });

  test("slice2", () {
    final List<int> someList = [1, 2, 3, 4, 5];
    final ListSlice<int> result = someList.slice(0, 3); // return [1, 2, 3]
    result.slice(0, 1); // normal return [0]
  });

  test("slice3", () {
    final List<int> someList = [1, 2, 3, 4, 5];
    final result = someList.slice(0, 3); // return [1, 2, 3]
    result.slice(0, 1); // normal return [0]
  });
}

As above, when using List to receive .slice results again .slice will cause Stack Overflow.

The code looks as expected ListExtensions#slice | ListSlice#slice, but I can't restrict my downstream from receiving .slice results with a List . Is there any good way to solve it.