This repository has been archived by the owner on Oct 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 37
Remove dynamic invocation #205
Closed
Closed
Changes from 9 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
d0e1317
Remove dynamic invocation
rrousselGit 2fa0d2e
Update num matchers
rrousselGit 3ce0574
Merge branch 'master' into patch-1
natebosch df9e5af
Enable lint avoid_dynamic_calls
natebosch 7fd4375
Merge branch 'master' into patch-1
natebosch f277c91
Change in type check output
natebosch 7823bb2
Merge branch 'master' into patch-1
natebosch dd59642
Move changelog entry
natebosch b362392
Retain a check against `Function`
natebosch 1fa085a
More places where Function() is too strict
natebosch File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,9 @@ class _Empty extends Matcher { | |
const _Empty(); | ||
|
||
@override | ||
bool matches(Object? item, Map matchState) => (item as dynamic).isEmpty; | ||
bool matches(Object? item, Map matchState) => | ||
// ignore: avoid_dynamic_calls | ||
(item as dynamic).isEmpty; | ||
|
||
@override | ||
Description describe(Description description) => description.add('empty'); | ||
|
@@ -27,7 +29,9 @@ class _NotEmpty extends Matcher { | |
const _NotEmpty(); | ||
|
||
@override | ||
bool matches(Object? item, Map matchState) => (item as dynamic).isNotEmpty; | ||
bool matches(Object? item, Map matchState) => | ||
// ignore: avoid_dynamic_calls | ||
(item as dynamic).isNotEmpty; | ||
|
||
@override | ||
Description describe(Description description) => description.add('non-empty'); | ||
|
@@ -144,11 +148,11 @@ class isInstanceOf<T> extends TypeMatcher<T> { | |
/// a wrapper will have to be created. | ||
const Matcher returnsNormally = _ReturnsNormally(); | ||
|
||
class _ReturnsNormally extends FeatureMatcher<Function> { | ||
class _ReturnsNormally extends FeatureMatcher<Function()> { | ||
const _ReturnsNormally(); | ||
|
||
@override | ||
bool typedMatches(Function f, Map matchState) { | ||
bool typedMatches(Function() f, Map matchState) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is likely a behavior change that we don't have tests for... |
||
try { | ||
f(); | ||
return true; | ||
|
@@ -190,6 +194,7 @@ class _HasLength extends Matcher { | |
@override | ||
bool matches(Object? item, Map matchState) { | ||
try { | ||
// ignore: avoid_dynamic_calls | ||
final length = (item as dynamic).length; | ||
return _matcher.matches(length, matchState); | ||
} catch (e) { | ||
|
@@ -205,6 +210,7 @@ class _HasLength extends Matcher { | |
Description describeMismatch(Object? item, Description mismatchDescription, | ||
Map matchState, bool verbose) { | ||
try { | ||
// ignore: avoid_dynamic_calls | ||
final length = (item as dynamic).length; | ||
return mismatchDescription.add('has length of ').addDescriptionOf(length); | ||
} catch (e) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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's too bad we don't have a better way to suppress these than the ignore. I filed dart-lang/linter#4806
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.
Could this be replaced with
if (item is Iterable) return item.isEmpty; else if (item is String) return item.isEmpty;
?That would technically be breaking if someone defined an unknown object with an
isEmpty
getter. But the fact that it currently works is surprising to me. I thought the implementation relied on pattern match, not dynamic invocationThere 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 supporting an
isEmpty
property on an arbitrary user defined class was an intentional feature and I'm not eager to try to remove it. It's not a design we'd carry forward tochecks
.