Skip to content

Remove dependency on package:collection by moving mergeSort into foundation/collections.dart #59521

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

Merged
merged 3 commits into from
Jun 16, 2020

Conversation

gspencergoog
Copy link
Contributor

Description

This removes a dependency from Flutter (package:collection) by copying the implementation of mergeSort into Flutter's foundation/collections.dart.

Also, removed a reference to UnmodifiableSetView from the shortcuts code by just returning a copy instead.

Tests

  • Added tests for mergeSort from collections.

Breaking Change

  • No, no existing tests failed, so this is not a breaking change.

@gspencergoog gspencergoog requested a review from goderbauer June 16, 2020 01:50
@fluttergithubbot fluttergithubbot added the framework flutter/packages/flutter repository. See also f: labels. label Jun 16, 2020
Copy link
Member

@goderbauer goderbauer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with some style nits.

///
/// If [compare] is omitted, this defaults to calling [Comparable.compareTo] on
/// the objects. If any object is not [Comparable], this throws a [TypeError]
/// (`CastError` on some SDK versions).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We control the SDK version for Flutter, which error is it for us?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's an interesting question. When I tried, this, it gave me:

The following _CastError was thrown building Home(dirty):
type 'Foo' is not a subtype of type 'Comparable<dynamic>' in type cast

The interesting thing is that CastError is deprecated in the SDK version we're using, with the reason "Use TypeError instead".

So, it seems that the SDK is throwing a private, deprecated error?

The definition of _CastError is:

class _CastError extends Error implements CastError, TypeError { /* ... */ }

So... I'm not sure what the right answer is. I think I'd rather it be TypeError, but that's not what the user will see, at least for now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure why the SDK's not sending a _TypeError, as that is defined similarly:

class _TypeError extends Error implements TypeError, CastError { /* ... */ }

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we can leave the docs as-is then until its cleaned up in the SDK.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If CastError implements TypeError, then it is a TypeError - the comment is not necessary

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, right. A _CastError is a TypeError, so we should just mention the TypeError in the doc.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But you can't use _CastError in your code anyways. I'd assume if you read the doc you are wondering what error type you're supposed to catch in a try-catch - and that would be a TypeError, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would. That's why this is complicated. Nowhere does the stack trace output say "TypeError", yet that is the type of the error that you need to catch.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I'd like to leave it as just saying TypeError, and remove the parenthetical about CastError since that one is deprecated, and point out that the output may say _CastError.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I updated it to say that. See what you think.

@goderbauer
Copy link
Member

Analyzer seems to be complaining about somethin'

Copy link
Contributor Author

@gspencergoog gspencergoog left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I initially was focused on adding types, etc., to make it match Flutter style, and forgot to address the wrapping.

This should fix all of those.

///
/// If [compare] is omitted, this defaults to calling [Comparable.compareTo] on
/// the objects. If any object is not [Comparable], this throws a [TypeError]
/// (`CastError` on some SDK versions).
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's an interesting question. When I tried, this, it gave me:

The following _CastError was thrown building Home(dirty):
type 'Foo' is not a subtype of type 'Comparable<dynamic>' in type cast

The interesting thing is that CastError is deprecated in the SDK version we're using, with the reason "Use TypeError instead".

So, it seems that the SDK is throwing a private, deprecated error?

The definition of _CastError is:

class _CastError extends Error implements CastError, TypeError { /* ... */ }

So... I'm not sure what the right answer is. I think I'd rather it be TypeError, but that's not what the user will see, at least for now.

///
/// If [compare] is omitted, this defaults to calling [Comparable.compareTo] on
/// the objects. If any object is not [Comparable], this throws a [TypeError]
/// (`CastError` on some SDK versions).
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure why the SDK's not sending a _TypeError, as that is defined similarly:

class _TypeError extends Error implements TypeError, CastError { /* ... */ }

Copy link
Member

@goderbauer goderbauer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@gspencergoog gspencergoog merged commit c5527dc into flutter:master Jun 16, 2020
@gspencergoog gspencergoog deleted the remove_collections branch June 16, 2020 21:41
zljj0818 pushed a commit to zljj0818/flutter that referenced this pull request Jun 22, 2020
…dation/collections.dart (flutter#59521)

This removes a dependency from Flutter (package:collection) by copying the implementation of mergeSort into Flutter's foundation/collections.dart.

Also, removed a reference to UnmodifiableSetView from the shortcuts code by just returning a copy instead.
mingwandroid pushed a commit to mingwandroid/flutter that referenced this pull request Sep 6, 2020
…dation/collections.dart (flutter#59521)

This removes a dependency from Flutter (package:collection) by copying the implementation of mergeSort into Flutter's foundation/collections.dart.

Also, removed a reference to UnmodifiableSetView from the shortcuts code by just returning a copy instead.
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 30, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
framework flutter/packages/flutter repository. See also f: labels.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants