-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Analyzer: Support generalized void #30177
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
This CL introduces support for the syntactic extensions in the analyzer, but does not yet check for usages of values of static type |
The above-mentioned change was landed on July 27th as 9336e19. This issue will be closed when the static checks have been implemented as well. |
@eernstg Does the informal spec (https://github.com/dart-lang/sdk/blob/master/docs/language/informal/generalized-void.md) include descriptions of all of the places where there ought to be an error? |
(I'm pretty sure I answered this question several days ago, but I can't find the answer anywhere, so here we go again ;-). Yes, the informal spec of generalized void is intended to contain a specification of all contexts where it is an error to evaluate an expression of type void. However, it's specified in a negated manner, as a list of cases where it's OK, and all other contexts are then the ones where an error should occur (because those other situations are the vast majority). The whitelist can be found in the informal spec by searching for The only other error is concerned with overriding; search for Note that there will be more errors in the future, when we introduce the notion of 'voidness preservation'. E.g., with voidness preservation we will almost certainly (it is not yet fully specified) have errors in the following situations:
The general idea is that we will prevent some indirect patterns where voidness is "forgotten". But this is in the future, so it's currently only required to raise errors in the cases which are listed in the document. |
Given that this was reopened with the intention of supporting dart 2, that seems to indicate to me based on the informal spec that what we actually want to implement now is "voidness preservation." Some other changes:
Also this:
Crucially, it looks like we're missing this:
and an anwer to whether return statements will still be allowed |
Ah, I see that I misunderstood. This ticket was never closed and reopened. I misread this:
I suppose that means, though, that we have two tasks here...to support generalized void checks at all, and then to support dart-2.0 generalized void checks. |
The voidness preservation is not part of this. In order of priorities:
The first two I think are required to unblock #31869 |
Right, I added support to the legacy front end of the analyzer for the generalized void syntax (cf. 1) in July, and For subtyping (cf. 2), (cf. 4) |
Thanks for the info everyone. I think I have everything I need! That said, I'll be taking a quick break on this today to get ready for dartconf. Hopefully its not an all-day break, but, so far the stuff that was supposed to be quick and easy there hasn't been! |
Please note the issues described in #31883: It explains why |
@leafpetersen feel free to take this on if you have time; if you do then just let me know. I'll do the same, if my dartconf work wraps up quickly. Like you said, should be not much more work than adding void to _isTop(). Haven't verified though. And I'll fininsh up the GLB of the top types now so that both of us would have that working once we get to this. |
I also ran the quick test of supporting _isTop to include void. I'm seeing 6 failures in the dart analyzer test cases, which is really not many, so it should be easy to tackle this overall unless, say, the language tests have more failures or something. |
I also noticed some discrepancies between the internal spec and the language test:
and the spec:
I'm assuming we should go with err on returning void values for now, that the language test here is what we want to go with rather than the informal spec. |
@MichaelRFairhurst Good catch! This CL makes corrections to the test such that all the existing return statements are compile-time errors as specified (because the return types of This particular exception was controversial, but we have it because of the breakage that would be introduced by prohibiting return-void-in-void-function, which has been expressible and allowed also in Dart 1. Also, it has been argued that it is convenient to be able to write write Edit: Just saw 'I'm assuming we should go..': No, we should adjust the test to follow the feature spec, the return-void-in-void-function exception should not be made an error, especially not temporarily. |
Note that the resulting |
Thanks Erik for the quick clarification! |
But yeah, I'm likely shaking up the nest for no reason. The implementation of void here is great and I love the simplicity. Little quirks are expected in any complex system. For solutions not related to the void typesystem.......I suppose that if we knew the variance of |
Seems reasonable ... except that We want We don't particularaly want a |
In this comment I mentioned that I had created a CL that allows conditional expressions to contain branches of type void (so we can have Proposals for an extended version of the same idea have come up since then, such that we would generally allow data flow where the value of an expression of type void is allowed to flow to a sink of type void (that is, be assigned to a variable of type void, passed as an actual argument where the corresponding statically known formal parameter has type void, returned in a void function). Here's a CL for that: https://dart-review.googlesource.com/c/sdk/+/38060. As mentioned in that CL, it subsumes the above-mentioned CL about conditionals, and we would land at most one of them. |
some remaining todos:
|
@leafpetersen @eernstg @devoncarew I think this is done enough for dart2/the purpose of this ticket. WDYT? Much of the rest is spec work, and the void return case which could probably be its own ticket, from what I can tell. |
Yup, would love to split the remaining work out into a new issue, for work post the alpha2 / march 1st timeline. |
The main issue will be flutter. Anything remaining will have to be run through their breaking change process, which means breakage will have to be fairly limited and well-justified. |
That would belong to #30597 (which lists all the relevant feature spec CLs, including the ones mentioned here), and it should be possible to handle this issue independently. For the record, I've added a comment on #30597 noting that some discussions here are relevant to said CLs. |
There are still failing tests around this, re-opening. |
void_type_function_types_test/none does not parse. Small repro which shows the incorrect parse error: typedef G2 = void Function([void]); |
Also failing: |
Also failing: |
This is the analyzer specific issue for #30176, which has the details.
The text was updated successfully, but these errors were encountered: