Skip to content

Commit ce76503

Browse files
author
Dart CI
committed
Version 2.12.0-76.0.dev
Merge commit '90ec6f2531a7b8c53326beb582940a50d83e0c93' into 'dev'
2 parents cd7b857 + 90ec6f2 commit ce76503

File tree

36 files changed

+3730
-2990
lines changed

36 files changed

+3730
-2990
lines changed

pkg/_fe_analyzer_shared/lib/src/flow_analysis/flow_analysis.dart

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2949,11 +2949,8 @@ class _FlowAnalysisImpl<Node, Statement extends Node, Expression, Variable,
29492949

29502950
@override
29512951
void ifNullExpression_end() {
2952-
// TODO(paulberry): CFE sometimes calls ifNullExpression_end and
2953-
// nullAwareAccess_end out of order, so as a workaround we cast to the
2954-
// common base class. See https://github.com/dart-lang/sdk/issues/43725.
2955-
_SimpleContext<Variable, Type> context =
2956-
_stack.removeLast() as _SimpleContext<Variable, Type>;
2952+
_IfNullExpressionContext<Variable, Type> context =
2953+
_stack.removeLast() as _IfNullExpressionContext<Variable, Type>;
29572954
_current = _merge(_current, context._previous);
29582955
}
29592956

@@ -3123,11 +3120,8 @@ class _FlowAnalysisImpl<Node, Statement extends Node, Expression, Variable,
31233120

31243121
@override
31253122
void nullAwareAccess_end() {
3126-
// TODO(paulberry): CFE sometimes calls ifNullExpression_end and
3127-
// nullAwareAccess_end out of order, so as a workaround we cast to the
3128-
// common base class. See https://github.com/dart-lang/sdk/issues/43725.
3129-
_SimpleContext<Variable, Type> context =
3130-
_stack.removeLast() as _SimpleContext<Variable, Type>;
3123+
_NullAwareAccessContext<Variable, Type> context =
3124+
_stack.removeLast() as _NullAwareAccessContext<Variable, Type>;
31313125
_current = _merge(_current, context._previous);
31323126
}
31333127

pkg/analysis_server/test/completion_test.dart

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -155,13 +155,9 @@ class String{}class List{}class test <X extends !1String!2> {}''',
155155
class String{}class List{}class DateTime{}typedef T Y<T extends !1>(List input);''',
156156
<String>['1+DateTime', '1+String']);
157157

158-
// https://github.com/dart-lang/sdk/issues/33992
159-
buildTests(
160-
'testCommentSnippets029',
161-
'''
158+
buildTests('testCommentSnippets029', '''
162159
interface A<X> default B<X extends !1List!2> {}''',
163-
<String>['1+DateTime', '2+List'],
164-
failingTests: '12');
160+
<String>['1+DateTime', '2+List']);
165161

166162
buildTests('testCommentSnippets030', '''
167163
class Bar<T extends Foo> {const Bar(!1T!2 k);T!3 m(T!4 a, T!5 b){}final T!6 f = null;}''',

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2885,7 +2885,6 @@ main() {
28852885
}
28862886
assertSuggestTopLevelVar('T1', null);
28872887
assertSuggestFunction('F1', null);
2888-
assertNotSuggested('D1');
28892888
assertNotSuggested('T2');
28902889
assertNotSuggested('F2');
28912890
assertNotSuggested('D2');

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

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2977,6 +2977,55 @@ main() {
29772977
assertNotSuggested('Object');
29782978
}
29792979

2980+
Future<void> test_forElement_body() async {
2981+
addTestSource('var x = [for (int i; i < 10; ++i) ^];');
2982+
await computeSuggestions();
2983+
2984+
expect(replacementOffset, completionOffset);
2985+
expect(replacementLength, 0);
2986+
assertSuggestLocalVariable('i', 'int');
2987+
assertNotSuggested('Object');
2988+
}
2989+
2990+
Future<void> test_forElement_condition() async {
2991+
addTestSource('var x = [for (int index = 0; i^)];');
2992+
await computeSuggestions();
2993+
2994+
expect(replacementOffset, completionOffset - 1);
2995+
expect(replacementLength, 1);
2996+
assertSuggestLocalVariable('index', 'int');
2997+
}
2998+
2999+
Future<void> test_forElement_initializer() async {
3000+
addTestSource('var x = [for (^)];');
3001+
await computeSuggestions();
3002+
3003+
expect(replacementOffset, completionOffset);
3004+
expect(replacementLength, 0);
3005+
assertNotSuggested('Object');
3006+
assertNotSuggested('int');
3007+
}
3008+
3009+
Future<void> test_forElement_updaters() async {
3010+
addTestSource('var x = [for (int index = 0; index < 10; i^)];');
3011+
await computeSuggestions();
3012+
3013+
expect(replacementOffset, completionOffset - 1);
3014+
expect(replacementLength, 1);
3015+
assertSuggestLocalVariable('index', 'int');
3016+
}
3017+
3018+
Future<void> test_forElement_updaters_prefix_expression() async {
3019+
addTestSource('''
3020+
var x = [for (int index = 0; index < 10; ++i^)];
3021+
''');
3022+
await computeSuggestions();
3023+
3024+
expect(replacementOffset, completionOffset - 1);
3025+
expect(replacementLength, 1);
3026+
assertSuggestLocalVariable('index', 'int');
3027+
}
3028+
29803029
Future<void> test_FormalParameterList() async {
29813030
// FormalParameterList MethodDeclaration
29823031
addTestSource('''
@@ -3157,6 +3206,17 @@ class B extends A {
31573206
expect(suggestion.hasNamedParameters, false);
31583207
}
31593208

3209+
Future<void> test_functionDeclaration_parameter() async {
3210+
addTestSource('''
3211+
void f<T>(^) {}
3212+
''');
3213+
await computeSuggestions();
3214+
3215+
expect(replacementOffset, completionOffset);
3216+
expect(replacementLength, 0);
3217+
assertSuggestTypeParameter('T');
3218+
}
3219+
31603220
Future<void> test_FunctionDeclaration_returnType_afterComment() async {
31613221
// ClassDeclaration CompilationUnit
31623222
addSource('/home/test/lib/a.dart', '''
@@ -3262,6 +3322,18 @@ void bar() {
32623322
assertSuggest('bar', elemKind: ElementKind.LOCAL_VARIABLE);
32633323
}
32643324

3325+
Future<void> test_functionDeclaration_typeParameterBounds() async {
3326+
addTestSource('''
3327+
void f<T extends C<^>>() {}
3328+
class C<E> {}
3329+
''');
3330+
await computeSuggestions();
3331+
3332+
expect(replacementOffset, completionOffset);
3333+
expect(replacementLength, 0);
3334+
assertSuggestTypeParameter('T');
3335+
}
3336+
32653337
Future<void> test_FunctionExpression_body_function() async {
32663338
// Block BlockFunctionBody FunctionExpression
32673339
addTestSource('''
@@ -3285,6 +3357,17 @@ class R {}
32853357
assertNotSuggested('Object');
32863358
}
32873359

3360+
Future<void> test_functionExpression_parameterList() async {
3361+
addTestSource('''
3362+
var c = <T>(^) {};
3363+
''');
3364+
await computeSuggestions();
3365+
3366+
expect(replacementOffset, completionOffset);
3367+
expect(replacementLength, 0);
3368+
assertSuggestTypeParameter('T');
3369+
}
3370+
32883371
Future<void> test_functionTypeAlias_genericTypeAlias() async {
32893372
addTestSource(r'''
32903373
typedef F = void Function();
@@ -3318,6 +3401,17 @@ main() {
33183401
assertSuggestFunctionTypeAlias('F', 'void');
33193402
}
33203403

3404+
Future<void> test_genericFunctionType_parameterList() async {
3405+
addTestSource('''
3406+
void f(int Function<T>(^) g) {}
3407+
''');
3408+
await computeSuggestions();
3409+
3410+
expect(replacementOffset, completionOffset);
3411+
expect(replacementLength, 0);
3412+
assertSuggestTypeParameter('T');
3413+
}
3414+
33213415
Future<void> test_IfStatement() async {
33223416
// SimpleIdentifier IfStatement
33233417
addTestSource('''
@@ -4598,6 +4692,22 @@ class Z {}
45984692
assertNotSuggested('bool');
45994693
}
46004694

4695+
Future<void> test_methodDeclaration_parameter() async {
4696+
addTestSource('''
4697+
class C<E> {}
4698+
extension E<S> on C<S> {
4699+
void m<T>(^) {}
4700+
}
4701+
''');
4702+
await computeSuggestions();
4703+
4704+
expect(replacementOffset, completionOffset);
4705+
expect(replacementLength, 0);
4706+
assertSuggestTypeParameter('S');
4707+
assertSuggestTypeParameter('T');
4708+
assertNotSuggested('E');
4709+
}
4710+
46014711
Future<void> test_MethodDeclaration_parameters_named() async {
46024712
// Block BlockFunctionBody MethodDeclaration
46034713
addTestSource('''
@@ -4804,6 +4914,22 @@ class B extends A{
48044914
assertSuggest('foo', elemKind: ElementKind.LOCAL_VARIABLE);
48054915
}
48064916

4917+
Future<void> test_methodDeclaration_typeParameterBounds() async {
4918+
addTestSource('''
4919+
class C<E> {}
4920+
extension E<S> on C<S> {
4921+
void m<T extends C<^>>() {}
4922+
}
4923+
''');
4924+
await computeSuggestions();
4925+
4926+
expect(replacementOffset, completionOffset);
4927+
expect(replacementLength, 0);
4928+
assertSuggestTypeParameter('S');
4929+
assertSuggestTypeParameter('T');
4930+
assertNotSuggested('E');
4931+
}
4932+
48074933
Future<void> test_MethodInvocation_no_semicolon() async {
48084934
// MethodInvocation ExpressionStatement Block
48094935
addTestSource('''
@@ -5594,6 +5720,19 @@ class B extends A1 with A2 {
55945720
assertNotSuggested('y2');
55955721
}
55965722

5723+
Future<void> test_stringInterpolation() async {
5724+
addTestSource(r'''
5725+
class C<T> {
5726+
String m() => 'abc $^ xyz';
5727+
}
5728+
''');
5729+
await computeSuggestions();
5730+
5731+
expect(replacementOffset, completionOffset);
5732+
expect(replacementLength, 0);
5733+
assertSuggestTypeParameter('T');
5734+
}
5735+
55975736
Future<void> test_SwitchStatement_c() async {
55985737
// SwitchStatement Block BlockFunctionBody MethodDeclaration
55995738
addTestSource('class A {String g(int x) {switch(x) {c^}}}');

pkg/analyzer/lib/src/dart/ast/ast.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4933,7 +4933,7 @@ class FunctionExpressionImpl extends ExpressionImpl
49334933

49344934
@override
49354935
Iterable<SyntacticEntity> get childEntities =>
4936-
ChildEntities()..add(_parameters)..add(_body);
4936+
ChildEntities()..add(_typeParameters)..add(_parameters)..add(_body);
49374937

49384938
@override
49394939
Token get endToken {

pkg/analyzer_plugin/lib/src/utilities/completion/optype.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -883,9 +883,7 @@ class _OpTypeAstVisitor extends GeneralizingAstVisitor<void> {
883883
if (identical(entity, node.expression)) {
884884
optype.completionLocation = 'InterpolationExpression_expression';
885885
optype.includeReturnValueSuggestions = true;
886-
// Only include type names in a ${ } expression
887-
optype.includeTypeNameSuggestions =
888-
node.leftBracket != null && node.leftBracket.length > 1;
886+
optype.includeTypeNameSuggestions = true;
889887
}
890888
}
891889

pkg/analyzer_plugin/lib/src/utilities/visitors/local_declaration_visitor.dart

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,23 @@ abstract class LocalDeclarationVisitor extends GeneralizingAstVisitor {
108108
visitNode(node);
109109
}
110110

111+
@override
112+
void visitForElement(ForElement node) {
113+
var forLoopParts = node.forLoopParts;
114+
if (forLoopParts is ForEachPartsWithDeclaration) {
115+
var loopVariable = forLoopParts.loopVariable;
116+
declaredLocalVar(loopVariable.identifier, loopVariable.type);
117+
} else if (forLoopParts is ForPartsWithDeclarations) {
118+
var varList = forLoopParts.variables;
119+
if (varList != null) {
120+
varList.variables.forEach((VariableDeclaration varDecl) {
121+
declaredLocalVar(varDecl.name, varList.type);
122+
});
123+
}
124+
}
125+
visitNode(node);
126+
}
127+
111128
@override
112129
void visitForStatement(ForStatement node) {
113130
var forLoopParts = node.forLoopParts;
@@ -133,10 +150,17 @@ abstract class LocalDeclarationVisitor extends GeneralizingAstVisitor {
133150

134151
@override
135152
void visitFunctionExpression(FunctionExpression node) {
153+
_visitTypeParameters(node, node.typeParameters);
136154
_visitParamList(node.parameters);
137155
visitNode(node);
138156
}
139157

158+
@override
159+
void visitGenericFunctionType(GenericFunctionType node) {
160+
_visitTypeParameters(node, node.typeParameters);
161+
visitNode(node);
162+
}
163+
140164
@override
141165
void visitInterpolationExpression(InterpolationExpression node) {
142166
visitNode(node);
@@ -152,6 +176,7 @@ abstract class LocalDeclarationVisitor extends GeneralizingAstVisitor {
152176

153177
@override
154178
void visitMethodDeclaration(MethodDeclaration node) {
179+
_visitTypeParameters(node, node.typeParameters);
155180
_visitParamList(node.parameters);
156181
visitNode(node);
157182
}

pkg/analyzer_plugin/test/src/utilities/completion/optype_test.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1686,7 +1686,8 @@ main() {
16861686
await assertOpType(
16871687
completionLocation: 'InterpolationExpression_expression',
16881688
constructors: true,
1689-
returnValue: true);
1689+
returnValue: true,
1690+
typeNames: true);
16901691
}
16911692

16921693
Future<void> test_interpolationExpression_block() async {

0 commit comments

Comments
 (0)