-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Mockito's "any" incompatible with strong mode analyzer #26036
Comments
maybe adding this comment before the line with the warning // ignore: DOWN_CAST_COMPOSITE |
For context, we generally warn about these because they are places where you might get unexpected results from the cast because of a reified dynamic. For example: dynamic x = [3];
List<String> l = x; This will run fine on the VM (at least until you start using the contents of
// ignore: STRONG_MODE_DOWN_CAST_COMPOSITE
/*=To*/ downcast/*<From, To extends From>*/(From x) => x;
// ignore: STRONG_MODE_DOWN_CAST_COMPOSITE
/*=To*/ cast/*<To>*/(dynamic x) => x;
void test2() {
dynamic d;
List<int> x = downcast/*<dynamic, List<int>>*/(d);
List<int> y = cast/*<List<int>>*/(d);
} |
AFAICT casting won't work, since "any" really isn't an object of the appropriate type. Disabling the error will work, but it's not great to have to disable warnings all over the place, even in tests. Is there any route to a better solution in the future? (Note that in other languages's implementations of Mockito, "any" is a generic method rather than a static constant, which should be possible to replicate in Dart soon.) |
Other than making any into a generic method (which you can do now with the comment based syntax), I don't have any immediate suggestions. Obviously that would be a breaking change in the API. I guess this is a use case for generic getters, which we haven't planned to support so far. I'd have to think about how they would work out. |
cc/ @vsmenon |
This has been fixed via https://github.com/fibulwinter/dart-mockito/pull/26, #26863, and dart-archive/dev_compiler@e5c2aac. Thanks @leafpetersen, @TedSander, @jmesserly, and @dskloetg for lots of work and input! |
There are various contexts in which the analyzer complains about the "any" matcher, e.g. named arguments, function-typed parameters, and certain others, with the error message
Unsound implicit cast from dynamic to <some type>
. Is there a suggested work around for this?cc/ @ochafik
The text was updated successfully, but these errors were encountered: