-
Notifications
You must be signed in to change notification settings - Fork 28.6k
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
Conversation
…dation/collections.dart
There was a problem hiding this 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). |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 { /* ... */ }
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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.
Analyzer seems to be complaining about somethin' |
8cf60c9
to
7f38ada
Compare
There was a problem hiding this 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). |
There was a problem hiding this comment.
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). |
There was a problem hiding this comment.
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 { /* ... */ }
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
7f38ada
to
d7ea869
Compare
…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.
…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.
Description
This removes a dependency from Flutter (
package:collection
) by copying the implementation of mergeSort into Flutter'sfoundation/collections.dart
.Also, removed a reference to
UnmodifiableSetView
from the shortcuts code by just returning a copy instead.Tests
mergeSort
from collections.Breaking Change