From 04b35f76c1f327e2e1ea3451ee3e5ef1bd7ee91e Mon Sep 17 00:00:00 2001 From: Nate Bosch Date: Wed, 23 Oct 2024 20:15:19 +0000 Subject: [PATCH 1/2] Loosen return type guidelines for local functions 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. --- src/content/effective-dart/design.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/content/effective-dart/design.md b/src/content/effective-dart/design.md index 47f6c6ca31..246cd94fe2 100644 --- a/src/content/effective-dart/design.md +++ b/src/content/effective-dart/design.md @@ -1200,10 +1200,10 @@ makeGreeting(String who) { } ``` -Note that this guideline only applies to *named* function declarations: -top-level functions, methods, and local functions. Anonymous function -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 +expressions infer a return type from their body. In fact, the anonymous function +syntax doesn't even allow a return type annotation. ### DO annotate parameter types on function declarations From 16a78ead8d5ec7df4adbf5cc65b42f1f61ddb58d Mon Sep 17 00:00:00 2001 From: Nate Bosch Date: Tue, 29 Oct 2024 18:29:44 +0000 Subject: [PATCH 2/2] tweak wording --- src/content/effective-dart/design.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/content/effective-dart/design.md b/src/content/effective-dart/design.md index 246cd94fe2..cf5e3d5b94 100644 --- a/src/content/effective-dart/design.md +++ b/src/content/effective-dart/design.md @@ -1201,9 +1201,9 @@ makeGreeting(String who) { ``` Note that this guideline only applies to *non-local* function declarations: -top-level functions, and methods. Local functions and anonymous function -expressions infer a return type from their body. In fact, the anonymous function -syntax doesn't even allow a return type annotation. +top-level, static, and instance methods and getters. Local functions and +anonymous function expressions infer a return type from their body. In fact, the +anonymous function syntax doesn't even allow a return type annotation. ### DO annotate parameter types on function declarations