-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Analyzer: it is an error if a type argument is a generic function type #33343
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 firmly believe that good advice is a huge part of good error messages. I'd like help brainstorming a simple "correction" message to use in the implementation. Part of that principle is that bad suggestions are bad. So maybe here I should not try to offer any suggestions at all. Regardless, here's what I have so far. For using a generic function as a bound, here's what I have: "Try making the free variable in the function type part of the larger declaration signature" If that's not clear don't let my explanation convince you otherwise. However, I'll describe what I mean by that in case anyone has further suggestions etc.
This is obviously not a catch-all suggestion. For disabling parameterization with a generic function type, I have (yikes) "Try resorting to dynamic programming if you need to have generic function types in your consuming code." Trying to think through some circumstance which is maybe a guideline for what else to suggest, I imagine:
In this case it seems like the only solution will involve casting. Reification is prone to go wrong in any workarounds. Therefore suggesting "dynamic programming" seems like essentially the only option, especially given that "dynamic programming" is on a sort of scale that potentially includes:
Anyways, feedback welcome. Either in terms of user-facing advice being adequate, lacking, convoluted, or wrong, etc. |
I didn't read the paper on why generic function types as bounds or parameters create problems. So forgive me for asking rather than researching... What do those problems mean for this case:
the generic function type is being used as a bound indirectly, but the bound is not a generic function type. Should this be illegal, and should the informal spec be updated to account for this? |
I'm also assuming that this the second part of this (if a type argument is a generic function type that's a compile time error) should be part of the inference engine? |
Just saw this test case:
well that's good to have my answer regarding inference! |
Does not handle the other half of #33343, rejecting generic function types as type arguments. This revealed a secondary minor issue which was easy enough to fix. Type arguments were not resolved within bounds: class C<T extends S Function<S>(S)> {} this would report 'undefined class S' for the return and parameter types `S`. I almost split this into a separate CL, but, these two CLs are tied together inherently by the tests case. Easy to solve at once. Bug: 33343 Change-Id: Ib34a04d90be08d8d6c6f21a9d485a452017585ba Reviewed-on: https://dart-review.googlesource.com/61103 Commit-Queue: Mike Fairhurst <mfairhurst@google.com> Reviewed-by: Paul Berry <paulberry@google.com>
There is a seeming parse error in typedefs, and an open question on the issue (33343) about what to do when a generic function type is inferred. Otherwise this seems ready to go. Bug: 33343 Change-Id: I10d2ea9b6ca26ed2c6ff6b24ffe5008fc4797ef2 Reviewed-on: https://dart-review.googlesource.com/61109 Commit-Queue: Mike Fairhurst <mfairhurst@google.com> Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Aside from the inference case, this is fixed in https://dart-review.googlesource.com/c/sdk/+/61109 and https://dart-review.googlesource.com/c/sdk/+/61103. I'll open a new bug for the inference side and put it in 2.1. |
The analyzer is missing the following errors from https://github.com/dart-lang/sdk/blob/master/docs/language/informal/generic-function-type-alias.md :
The text was updated successfully, but these errors were encountered: