Skip to content

Commit 4bf5a72

Browse files
stereotype441commit-bot@chromium.org
authored andcommitted
Flow analysis: support functions whose bodies are expressions.
Change-Id: I01a66fb2c897e0cabbdfb4b7423cab53291b3adf Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/113947 Reviewed-by: Brian Wilkerson <[email protected]> Reviewed-by: Konstantin Shcheglov <[email protected]> Commit-Queue: Paul Berry <[email protected]>
1 parent b569bf0 commit 4bf5a72

File tree

4 files changed

+17
-4
lines changed

4 files changed

+17
-4
lines changed

pkg/analysis_server/test/services/completion/dart/keyword_contributor_test.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2177,4 +2177,12 @@ class KeywordContributorWithNnbdTest extends KeywordContributorTest {
21772177
super.setupResourceProvider();
21782178
createAnalysisOptionsFile(experiments: [EnableString.non_nullable]);
21792179
}
2180+
2181+
@override
2182+
@failingTest
2183+
test_ifOrForElement_forElement() {
2184+
// TODO(paulberry): this test is failing due to lack of support for flow
2185+
// analysis of "for" elements.
2186+
return super.test_ifOrForElement_forElement();
2187+
}
21802188
}

pkg/analyzer/lib/src/dart/resolver/flow_analysis_visitor.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ class FlowAnalysisHelper {
124124
}
125125
}
126126

127-
void blockFunctionBody_enter(BlockFunctionBody node) {
127+
void functionBody_enter(FunctionBody node) {
128128
_blockFunctionBodyLevel++;
129129

130130
if (_blockFunctionBodyLevel > 1) {
@@ -145,7 +145,7 @@ class FlowAnalysisHelper {
145145
}
146146
}
147147

148-
void blockFunctionBody_exit(BlockFunctionBody node) {
148+
void functionBody_exit(FunctionBody node) {
149149
_blockFunctionBodyLevel--;
150150

151151
if (_blockFunctionBodyLevel > 0) {

pkg/analyzer/lib/src/generated/resolver.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3503,12 +3503,12 @@ class ResolverVisitor extends ScopedVisitor {
35033503
@override
35043504
void visitBlockFunctionBody(BlockFunctionBody node) {
35053505
try {
3506-
_flowAnalysis?.blockFunctionBody_enter(node);
3506+
_flowAnalysis?.functionBody_enter(node);
35073507
inferenceContext.pushReturnContext(node);
35083508
super.visitBlockFunctionBody(node);
35093509
} finally {
35103510
inferenceContext.popReturnContext(node);
3511-
_flowAnalysis?.blockFunctionBody_exit(node);
3511+
_flowAnalysis?.functionBody_exit(node);
35123512
}
35133513
}
35143514

@@ -3788,6 +3788,7 @@ class ResolverVisitor extends ScopedVisitor {
37883788
return;
37893789
}
37903790
try {
3791+
_flowAnalysis?.functionBody_enter(node);
37913792
InferenceContext.setTypeFromNode(node.expression, node);
37923793
inferenceContext.pushReturnContext(node);
37933794
super.visitExpressionFunctionBody(node);
@@ -3801,6 +3802,7 @@ class ResolverVisitor extends ScopedVisitor {
38013802
}
38023803
} finally {
38033804
inferenceContext.popReturnContext(node);
3805+
_flowAnalysis?.functionBody_exit(node);
38043806
}
38053807
}
38063808

pkg/front_end/test/flow_analysis/type_promotion/data/conditional.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,6 @@ void conditional_then(bool b, Object x) {
1616
b ? ((x is num) || (throw 1)) : 0;
1717
x;
1818
}
19+
20+
int conditional_in_expression_function_body(Object o) =>
21+
o is int ? /*int*/ o : 0;

0 commit comments

Comments
 (0)