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

Iterable#take tolerates null #41743

Closed
trinarytree opened this issue May 2, 2020 · 1 comment
Closed

Iterable#take tolerates null #41743

trinarytree opened this issue May 2, 2020 · 1 comment
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. library-collection type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@trinarytree
Copy link

the following program

void main() {
  print([1, 2].take(null));
}

surprisingly prints (1, 2). i expected it to throw.
nothing about the take docs hint that it wouldn't throw nor what the behavior would be if given a null. the param isn't optional.

in fact, the take docs seem to hint that it would throw - it says that it's implemented as
TakeIterable<E>(this, count) and, poking around dart-sdk/lib/internal/iterable.dart it seems like TakeIterable's constructor is supposed to throw an ArgumentError if it's given a null.

i suspect that the docs are wrong and that Iterable#take is actually implemented as SubListIterable, which accepts a null.

but regardless of how it's implemented, it looks like a bug for Iterable#take to accept a null, especially considering that TakeIterable doesn't tolerate it.

dart --version
Dart VM version: 2.7.2 (Mon Mar 23 22:11:27 2020 +0100) on "macos_x64"

@lrhn lrhn added area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. library-collection type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) labels May 3, 2020
@lrhn
Copy link
Member

lrhn commented May 3, 2020

It shouldn't accept null.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. library-collection type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

2 participants