Skip to content

Commit ba5644b

Browse files
stereotype441commit-bot@chromium.org
authored andcommitted
Fix handling of closures containing type promotions in variables with inferred types.
Promotion analysis requires the localVariableInfo data structures to be set; these are set by the VariableResolverVisitor. So we need to ensure that this visitor runs prior to type inference. Change-Id: I579301beb101f32a1965f9eb8f07b1196d232b8e Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/95422 Reviewed-by: Konstantin Shcheglov <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Paul Berry <[email protected]>
1 parent 7a98559 commit ba5644b

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed

pkg/analyzer/lib/src/summary/link.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2542,7 +2542,9 @@ class ExprTypeComputer {
25422542
expression = container.expression;
25432543
if (_linker.getAst != null) {
25442544
expression.accept(_typeResolverVisitor);
2545-
expression.accept(_variableResolverVisitor);
2545+
}
2546+
expression.accept(_variableResolverVisitor);
2547+
if (_linker.getAst != null) {
25462548
expression.accept(_partialResolverVisitor);
25472549
}
25482550
expression.accept(_resolverVisitor);

pkg/analyzer/test/generated/non_error_resolver.dart

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -907,6 +907,19 @@ class E {}''');
907907
expect(classC.documentationComment, isNotNull);
908908
}
909909

910+
test_closure_in_type_inferred_variable_in_other_lib() async {
911+
Source source = addSource('''
912+
import 'other.dart';
913+
var x = y;
914+
''');
915+
addNamedSource('/other.dart', '''
916+
var y = (Object x) => x is int && x.isEven;
917+
''');
918+
await computeAnalysisResult(source);
919+
assertNoErrors(source);
920+
verify([source]);
921+
}
922+
910923
test_concreteClassWithAbstractMember() async {
911924
Source source = addSource(r'''
912925
abstract class A {

pkg/analyzer/test/util/ast_type_matchers.dart

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,14 +111,14 @@ const isFieldDeclaration = const TypeMatcher<FieldDeclaration>();
111111

112112
const isFieldFormalParameter = const TypeMatcher<FieldFormalParameter>();
113113

114-
final Matcher isForEachStatement = predicate(
114+
final isForEachStatement = predicate(
115115
(Object o) => o is ForStatement2 && o.forLoopParts is ForEachParts);
116116

117117
const isFormalParameter = const TypeMatcher<FormalParameter>();
118118

119119
const isFormalParameterList = const TypeMatcher<FormalParameterList>();
120120

121-
final Matcher isForStatement =
121+
final isForStatement =
122122
predicate((Object o) => o is ForStatement2 && o.forLoopParts is ForParts);
123123

124124
const isFunctionBody = const TypeMatcher<FunctionBody>();
@@ -181,8 +181,7 @@ const isListLiteral = const TypeMatcher<ListLiteral>();
181181

182182
const isLiteral = const TypeMatcher<Literal>();
183183

184-
final Matcher isMapLiteral =
185-
predicate((Object o) => o is SetOrMapLiteral && o.isMap);
184+
final isMapLiteral = predicate((Object o) => o is SetOrMapLiteral && o.isMap);
186185

187186
const isMapLiteralEntry = const TypeMatcher<MapLiteralEntry>();
188187

@@ -237,8 +236,7 @@ const isReturnStatement = const TypeMatcher<ReturnStatement>();
237236

238237
const isScriptTag = const TypeMatcher<ScriptTag>();
239238

240-
final Matcher isSetLiteral =
241-
predicate((Object o) => o is SetOrMapLiteral && o.isSet);
239+
final isSetLiteral = predicate((Object o) => o is SetOrMapLiteral && o.isSet);
242240

243241
const isShowCombinator = const TypeMatcher<ShowCombinator>();
244242

0 commit comments

Comments
 (0)