Skip to content
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

Merged
merged 4 commits into from
Nov 6, 2024

Conversation

natebosch
Copy link
Member

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.

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.
Copy link
Member

@munificent munificent left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!

@dart-github-bot
Copy link
Collaborator

dart-github-bot commented Oct 23, 2024

Visit the preview URL for this PR (updated for commit 24a1e24):

https://dart-dev--pr6165-infer-local-function-return-yprn4c68.web.app

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
Copy link
Member

@lrhn lrhn Oct 24, 2024

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.)

@MaryaBelanger MaryaBelanger self-assigned this Oct 29, 2024
Copy link
Contributor

@MaryaBelanger MaryaBelanger left a 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!

@natebosch
Copy link
Member Author

@MaryaBelanger - I don't have authorization to merge in this repo. Can you merge for me?

@lrhn
Copy link
Member

lrhn commented Nov 6, 2024

Me neither. @munificent?

Copy link
Member

@parlough parlough left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this update!

@parlough parlough merged commit 19ee51e into dart-lang:main Nov 6, 2024
10 checks passed
@natebosch natebosch deleted the infer-local-function-return branch November 6, 2024 17:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants