-
Notifications
You must be signed in to change notification settings - Fork 698
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
Loosen return type guidelines for local functions #6165
base: main
Are you sure you want to change the base?
Conversation
Local named functions do infer a return type in current Dart versions. In our recommendation to annotate the return type of functions change the set of functions the guideline applies to from "named" functions to "non-local" functions, anonymous function expressions are also local to a method body.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch!
Visit the preview URL for this PR (updated for commit 16a78ea): https://dart-dev--pr6165-infer-local-function-return-yprn4c68.web.app |
src/content/effective-dart/design.md
Outdated
expressions infer a return type from their body. In fact, the syntax doesn't | ||
even allow a return type annotation. | ||
Note that this guideline only applies to *non-local* function declarations: | ||
top-level functions, and methods. Local functions and anonymous function |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe "top-level functions, static functions and instance methods".
I don't usually call static functions "methods", although I guess "static method" is commonly used for them. (I think it's a Java way of phrasing it, which began because they don't/didn't have plain functions at all. Dart always had functions, so methods is only something objects have. But sensible people can disagree on that, and usually do.)
Also, "method" doesn't really cover getters. Whether "function" does can be discussed, the spec does use "function" about both methods, getters and setters. (And "method" only about non-getter, non-setter functions.)
Maybe, compromising for brevity,
top-level, static and instance methods and getters. ...
(Not setters, since you should omit their return type.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lgtm, feel free to wait for Parker's review or merge now that you have approval. Thanks!
Local named functions do infer a return type in current Dart versions.
In our recommendation to annotate the return type of functions change
the set of functions the guideline applies to from "named" functions to
"non-local" functions, anonymous function expressions are also local to
a method body.