-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Meta issue tracking implementation of generic function type syntax in Dart 1.5 #27527
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
Status update: I have updated the issue description for more context. The following CLs show explorations: https://codereview.chromium.org/2439573003/ |
lgtm with a slight preference for the <- variant. |
status: Prototyping several options, @floitschG is driving. |
Latest proposal: typedef F = void Function(int);
// also works for field or local types:
final int Function(String, bool) myFun = ...;
Here is a CL that experiments with it: https://codereview.chromium.org/2482923002/ Note: we would still allow |
I do not like this latest proposal. The name Function is promoted to some kind of keyword used for parsing. Also, Function is not declared to be generic, therefore, using it to declare a non-generic typedef for a generic function will look like an error. |
It's not a perfect choice, but it has its advantages. Dart already uses It's true that the Personally, I'm not that much concerned about the fact, that Function f; // a function.
Function(int x) f; // a function that takes an int.
double Function(int) f; // a function that takes an int and returns a double. I'm more concerned about the fact that it is longer, and that we intend to interpret one-identifier parameters differently in the new syntax than in parameter types in the old syntax: Just for completeness sake, here are some examples of how the syntax would deal with the different generic arguments (to the typedef or for the function). typedef F = void Function(int); // Function from (int) to void.
typedef F<T> = List<T> Function(); // Template Typedef.
typedef F = List<T> Function<T>(T); // Generic function from T to List<T>. |
I agree that having a special marker for function types has advantages and is easier to read. I only find the already defined "Function" a questionable choice for this marker, especially since the formal argument syntax is modified and not what you would expect after an identifier (i.e. regular function signature syntax). That's the reason I'd prefer a symbol rather than an identifier (or keyword), as in the previous proposals. I agree that "<-" of the previous proposal is a bit hard to read when generic. As a side note, you will also need to specify the syntax for optional arguments (no default values allowed), both positional and named, something like: void Function(int, [int, bool]); // optional positional
void Function(int, {int i, bool b}); // optional named |
Yes. We will have to specify the syntax for the optional arguments. (This is the reason that I/We will think about using something else than Personally, I also tend to avoid using symbols for uncommon functionality. Function types are not extremely rare, but they are not common enough to warrant their own symbol. |
Would it be possible to add a new contextual keyword like
+1. Punctuation is almost always the wrong choice for new syntax unless it represents something almost all users already know, like using |
The backwards-compatible advantage in using We can make |
About omitted parameter lists in the We might decide to introduce syntax for variadic functions at some point, in which case this will become a shorthand for "the most general argument list", but even at that point it seems likely that such a shorthand would be convenient. |
In the informal spec (which will be made public when it has matured a bit) I've proposed a rename of this feature to 'Generalized type aliases' (because a limitation of this mechanism to handle generic function types only is artificial, and presumably counter productive). |
Could we add some tests cases for this so that the implementations can be verified. |
Marking informal spec complete for implementation purposes based on #27970 (comment) |
Moving to 1.22 for implementation. |
Punting to 1.23 per email discussion |
We reverted the syntax for 1.22 and add a deprecation warning for |
Is this still on track for 1.23? |
I can't speak for anyone else, but I am actively working on the analyzer support. |
Any updates? |
I am not sure who you are asking, but the corresponding VM issue has been closed on January 27. |
@leafpetersen see detailed status in the two unchecked items in the top checklist |
For dartdoc, it turns out there's no need to do anything directly for the SDK release and the work that does need to be done isn't blocking any longer. I've dropped the 1.23 label from dart-lang/dartdoc#1321 accordingly, and there are more details there as to why. |
I had misunderstood a key piece of the feature, I recommend blocking this feature on dartdoc now. Dartdoc in the SDK won't crash without the upcoming fix, but it will display the typedef with the generic parameter missing. |
dartfmt support is in flight. |
dartfmt is fixed and in the repo. |
@leafpetersen looks like this one is still missing in changelog.md? |
I left it out, since I wasn't 100% sure that it was landing, but it looks like maybe the dartdoc issue is resolved? If so, I can go ahead and write something up. |
There seems to still be quite a bit of missing functionality still in the analyzer implementation, see discussion at the end here: #27969 . |
Can we go ahead and update changelog.md now? |
Any updates on this? |
@leafpetersen @floitschG can we please finish this for 1.24? |
This is a tracking bug for implementing support for generic function type syntax (generic typedef) in Dart 1.5.
Proposal: https://gist.github.com/eernstg/ffc7bd281974e9018f10f0cb6cfee4aa
The corresponding individual issues will be listed here:
Description
Dart 2 supports generic methods and generic tear-offs (or anonymous functions). This means that a function can request a function that is generic:
It is straightforward to add the syntax to the existing syntax for function types for parameters (as was done in the example). However, we don't have an easy way to do the same for fields or local variables:
We already used the most consistent place for the generic method argument as a template argument to the
typedef
itself. If we could go back in time, we could change it as follows:Given that this would be a breaking change we have considered alternatives and are now exploring new typedef syntax altogether. The idea is to provide syntax that can also be used for locals and fields at the same time.
For example:
This way we would solve 3 issues at the same time:
typedef void F(int)
to be a function that takes an int.While investigating different syntax we found that the following points need consideration:
The text was updated successfully, but these errors were encountered: