-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Map literal type arguments sometimes aren't inferred with --no-implicit-dynamic #31013
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
Ran into this recently. It seems to be related to the arguments being the |
@stereotype441 Will this be covered by the inference back-porting that you're working on? |
@bwilkerson it's not directly covered by my inference back-porting work, but since it's an inference bug, I'm happy to take a look. I've added it to my list and I'll try to get to it in the next week. |
On second thought, isn't this the intended behavior? The idea of |
As far as I know, you're right about the intent for But then the question becomes whether it's useful to warn users in all cases, such as when we're inferring |
I think we need to revisit this flag (and related ones, like /cc @leafpetersen @vsmenon @jmesserly @bwilkerson Would you be supportive of opening some meta issues ("post Dart2: Revisit --no-implicit-casts & --no-implicit-dynamic"), and then closing all issues related to this flag today as WAI? We should make it clear these flags are best effort, and not currently "production" supported as we push towards Dart 2/strong-mode. |
I agree with Brian (propagating an explicit dynamic doesn't feel the same as inferring a dynamic from lack of information), and I would not actually think that this was an "implicit dynamic" if I wrote the code myself. |
Yes, this isn't an inference bug. I think the general consensus is that the behavior of this flag should change as suggested above, but this isn't on the critical path right now. |
tl;dr Keep flagging this implicit dynamism; There's an inherent ambiguity in a declaration like Zooming in on the details, we can see that the top type is
It's not at all obvious to me that the perceived needs of the client and the concrete needs felt by the developer who is writing the body will coincide. For instance, it may well be convenient for the developer who writes the body to be able to call arbitrary methods on the values retrieved from the However, we can use the variance of each occurrence of a top type to determine whether it's significant for the client respectively for an associated body which top type it is. I've suggested that we should erase all top types to In a more general setting, covariant locations are significant for the client, and contravariant locations are significant for an associated body. We've already seen that the choice among top types in the simplest contravariant location (the type of a formal parameter) is obviously significant for the body. For covariant locations, (1) it matters a lot for the client whether the return type of a function which is being invoked is
In this example, the single occurrence of So my recommendation would be to keep flagging this kind of "implicit dynamic" for now, and then later on use variance based top type erasure to help developers route these effects only along the paths where they make sense. |
Bump. We're playing with --no-implicit-dynamic, and hitting this in several places, e.g. Intl.plural:
|
Judging from the comments on Feb 4-5, it sounds like the language team doesn't have a consensus on what the expected behavior should be. @leafpetersen, @eernstg, @lrhn, can you make a recommendation on how we should proceed? |
I think my take is that |
That makes sense. I agree. We're trying to figure out of we can pursue using It's an effort question then, re: |
I think that the changes that you would probably want to make to |
any plans to fix this? |
I've had the privilege of introducing a few JS devs to Dart, and this is such a sticking point. I wanted |
Wow this is still open? |
Sorry this has fallen below the radar. The The replacement is an analysis_options.yaml option: |
Thank you! |
@srawlins the error persists with the
Are there any linter rules I should remove? |
|
If I analyze the following code with
--no-implicit-dynamic
:I get this error:
I'd expect the map's type arguments to be inferred from the values I used, or maybe to be inferred as
dynamic
since I'm passing it tofn()
; either way, I don't expect an error.The text was updated successfully, but these errors were encountered: