-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Will need runtime check to cast to type (WebElement) -> dynamic #25018
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
As best I can see from the example, neither of those should produce a warning. I can't actually get the error to reproduce with some small test examples using analyzer version 1.14.0-dev.1.0. Do you have a small reproduction case? If not, can you tell me any more about the code? What's the return type of the function, and what is the return type of the call to findElements? If you declare the lambda as a local function instead (to give it an explicit type) do you still get the error? |
I tried to create a simple project to reproduce it. |
I just saw, that I forgot to add the |
Thanks, that's very helpful! I think this is a name confusion. It looks to me like you are defining a class named WebElement in that test file, and then trying to use that in a context that is expecting a wd.WebElement . If I change the anonymous callback in your example to have wd.WebElement as the argument type then the error goes away. @bwilkerson The error message here is very confusing, and for once I don't think it's strong mode's fault. :) Even with the regular analyzer this is the error message I see: warning] The argument type '(WebElement) → Future' cannot be assigned to the parameter type '(WebElement) → dynamic' (/Users/leafp/tmp/repo/bug_repo-master/sdk25018/test/e03_editing_test.dart, line 31, col 17) It would be awesome if we could disambiguate the two WebElement names in the error message. Related to #23492 |
Sorry, I made a mistake when I tried to build the repo case.
class WebElement implements wd.WebElement {
Future<String> text;
noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
} but with this change I don't get any warning. |
Ah - in that case, this is a strong mode error, and it's correct (but it's confusing because of the lack of name disambiguation). In strong mode, function types are contra-variant on their arguments. For You either need to make the lambda take a wd.WebElement and cast it to WebElement (if you're sure that all of the elements are WebElements), or else you need to refine the type of the iterable over which you are mapping (which probably requires generic methods to do properly). |
Thanks a lot! |
I agree, some kind of disambiguation would be great and if it is only some random code as prefix that differs, to indicate the types are different. I use quite the same code in 5 locations but only in this one I typed the Thanks again for your support. |
No worries, thanks for trying things out. I'll close this bug: @bwilkerson is there an existing bug that covers the name disambiguation, or should I open one? |
I'm not aware of any issue. I know that we do have code to perform the disambiguation (ErrorReporter.reportTypeErrorForNode), so it must just not be getting used in these cases. |
Submitted #25036 for the name disambiguation. |
I don't get this warning here
strong-mode is enabled
I think either the first shouldn't produce a warning or the second should.
If the warning is correct, is a typedef the only way to silence this?
The text was updated successfully, but these errors were encountered: