-
Notifications
You must be signed in to change notification settings - Fork 218
Could Matcher be changed to be typed as Matcher<T>? #2352
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
Comments
I would also like to see something like this. In strong mode you cannot override the types of params in methods. Having something like this would be great. To be able to use the class StringMatcher<T extends String> extends Matcher<T> {
@override
bool matches(T item, Map matchState) {
// Use a String method
if (item.contains('whatever') return true;
}
} Vs. class StringMatcher extends Matcher {
@override
bool matches(dynamic _item, Map matchState) {
item = _item as String;
// Use a String method
if (item.contains('whatever') return true;
}
} |
@jacehensley-wf FWIW, I've been using this pattern for now: @override
bool matches(item, _) {
if (item is String) {
return item.contains('whatever');
}
return false;
} Still not preferable since you get runtime errors, not static errors. |
@jacehensley-wf you can now override parameters when you add the |
Hmm, I thought I tried that. I'll try it again. Yeah I am still getting this error:
When doing this: bool matches(@checked String className, Map matchState) I'm on Dart 1.19.1 using Atom if that matters. |
You might need the latest Dart stable or even development branch. |
Thanks, I'll try it out on those versions. Update: Works as expected on Dart 1.20.1! |
I like this idea a lot, especially since strong mode provides a lot more benefits for having nice types everywhere. However, in order to make this useful, we'd need to integrate it into
|
Cool. Stalking those issues :) |
@nex3 I think there is still value in adding a generic parameter to |
Just some update:
|
@nex3 any more thoughts on this? |
Neither of the blocking issues are fixed, so... no? |
I believe this is also blocked on dart-lang/sdk/issues/25490, since it requires that type information flow between arguments of |
Closing this as not planned. This appears to rely on language features we are unlikely to get anytime soon, and we're instead delivering the benefit this would have brought in a new package with a different design. https://pub.dev/packages/checks |
Specifically, this allows strongly-typed assurances when creating specialized matchers:
I don't think this is a breaking change, unless we specifically want to allow something like:
Added after the fact by @nex3
Blocking issues (see comments for details):
The text was updated successfully, but these errors were encountered: