Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(19)

Unified Diff: pkg/analyzer/lib/src/generated/static_type_analyzer.dart

Issue 2209293002: fix #26414, infer return types of local functions (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: mark failing ast inference Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « CHANGELOG.md ('k') | pkg/analyzer/test/generated/strong_mode_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/lib/src/generated/static_type_analyzer.dart
diff --git a/pkg/analyzer/lib/src/generated/static_type_analyzer.dart b/pkg/analyzer/lib/src/generated/static_type_analyzer.dart
index f68147180e5529973e12766669e0348cd963a001..fa82560e055276642182e1a99c6336ffe21b0717 100644
--- a/pkg/analyzer/lib/src/generated/static_type_analyzer.dart
+++ b/pkg/analyzer/lib/src/generated/static_type_analyzer.dart
@@ -441,6 +441,10 @@ class StaticTypeAnalyzer extends SimpleAstVisitor<Object> {
if (node.parent is FunctionDeclarationStatement) {
// TypeResolverVisitor sets the return type for top-level functions, so
// we only need to handle local functions.
+ if (_strongMode && node.returnType == null) {
+ _inferLocalFunctionReturnType(node.functionExpression);
+ return null;
+ }
functionElement.returnType =
_computeStaticReturnTypeOfFunctionDeclaration(node);
_recordPropagatedTypeOfFunction(functionElement, function.body);
@@ -486,6 +490,15 @@ class StaticTypeAnalyzer extends SimpleAstVisitor<Object> {
// node.
return null;
}
+ _inferLocalFunctionReturnType(node);
+ return null;
+ }
+
+ /**
+ * Infers the return type of a local function, either a lambda or
+ * (in strong mode) a local function declaration.
+ */
+ void _inferLocalFunctionReturnType(FunctionExpression node) {
bool recordInference = false;
ExecutableElementImpl functionElement =
node.element as ExecutableElementImpl;
@@ -517,7 +530,6 @@ class StaticTypeAnalyzer extends SimpleAstVisitor<Object> {
if (recordInference) {
_resolver.inferenceContext.recordInference(node, functionElement.type);
}
- return null;
}
/**
« no previous file with comments | « CHANGELOG.md ('k') | pkg/analyzer/test/generated/strong_mode_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698