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

Side by Side Diff: pkg/analyzer/test/generated/resolver_test.dart

Issue 1555603002: Fix downwards inference for async and generator functions. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Address comments Created 4 years, 11 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 unified diff | Download patch
« no previous file with comments | « pkg/analyzer/lib/src/generated/resolver.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library analyzer.test.generated.resolver_test; 5 library analyzer.test.generated.resolver_test;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 8
9 import 'package:analyzer/dart/element/element.dart'; 9 import 'package:analyzer/dart/element/element.dart';
10 import 'package:analyzer/dart/element/type.dart'; 10 import 'package:analyzer/dart/element/type.dart';
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 futureElement.constructors = <ConstructorElement>[futureConstructor]; 194 futureElement.constructors = <ConstructorElement>[futureConstructor];
195 // Future then(onValue(T value), { Function onError }); 195 // Future then(onValue(T value), { Function onError });
196 TypeDefiningElement futureThenR = DynamicElementImpl.instance; 196 TypeDefiningElement futureThenR = DynamicElementImpl.instance;
197 if (context.analysisOptions.strongMode) { 197 if (context.analysisOptions.strongMode) {
198 futureThenR = ElementFactory.typeParameterWithType('R'); 198 futureThenR = ElementFactory.typeParameterWithType('R');
199 } 199 }
200 FunctionElementImpl thenOnValue = ElementFactory.functionElement3( 200 FunctionElementImpl thenOnValue = ElementFactory.functionElement3(
201 'onValue', futureThenR, [futureElement.typeParameters[0]], null); 201 'onValue', futureThenR, [futureElement.typeParameters[0]], null);
202 202
203 DartType futureRType = futureElement.type.substitute4([futureThenR.type]); 203 DartType futureRType = futureElement.type.substitute4([futureThenR.type]);
204 MethodElementImpl thenMethod = ElementFactory.methodElementWithParameters( 204 MethodElementImpl thenMethod = ElementFactory
205 futureElement, "then", futureRType, [ 205 .methodElementWithParameters(futureElement, "then", futureRType, [
206 ElementFactory.requiredParameter2("onValue", thenOnValue.type), 206 ElementFactory.requiredParameter2("onValue", thenOnValue.type),
207 ElementFactory.namedParameter2("onError", provider.functionType) 207 ElementFactory.namedParameter2("onError", provider.functionType)
208 ]); 208 ]);
209 if (!futureThenR.type.isDynamic) { 209 if (!futureThenR.type.isDynamic) {
210 thenMethod.typeParameters = [futureThenR]; 210 thenMethod.typeParameters = [futureThenR];
211 } 211 }
212 thenOnValue.enclosingElement = thenMethod; 212 thenOnValue.enclosingElement = thenMethod;
213 thenOnValue.type = new FunctionTypeImpl(thenOnValue); 213 thenOnValue.type = new FunctionTypeImpl(thenOnValue);
214 (thenMethod.parameters[0] as ParameterElementImpl).type = thenOnValue.type; 214 (thenMethod.parameters[0] as ParameterElementImpl).type = thenOnValue.type;
215 thenMethod.type = new FunctionTypeImpl(thenMethod); 215 thenMethod.type = new FunctionTypeImpl(thenMethod);
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 ElementFactory.getterElement("context2D", false, context2dElement.type) 284 ElementFactory.getterElement("context2D", false, context2dElement.type)
285 ]; 285 ];
286 canvasElement.fields = canvasElement.accessors 286 canvasElement.fields = canvasElement.accessors
287 .map((PropertyAccessorElement accessor) => accessor.variable) 287 .map((PropertyAccessorElement accessor) => accessor.variable)
288 .toList(); 288 .toList();
289 ClassElementImpl documentElement = 289 ClassElementImpl documentElement =
290 ElementFactory.classElement("Document", elementType); 290 ElementFactory.classElement("Document", elementType);
291 ClassElementImpl htmlDocumentElement = 291 ClassElementImpl htmlDocumentElement =
292 ElementFactory.classElement("HtmlDocument", documentElement.type); 292 ElementFactory.classElement("HtmlDocument", documentElement.type);
293 htmlDocumentElement.methods = <MethodElement>[ 293 htmlDocumentElement.methods = <MethodElement>[
294 ElementFactory.methodElement( 294 ElementFactory
295 "query", elementType, <DartType>[provider.stringType]) 295 .methodElement("query", elementType, <DartType>[provider.stringType])
296 ]; 296 ];
297 htmlUnit.types = <ClassElement>[ 297 htmlUnit.types = <ClassElement>[
298 ElementFactory.classElement("AnchorElement", elementType), 298 ElementFactory.classElement("AnchorElement", elementType),
299 ElementFactory.classElement("BodyElement", elementType), 299 ElementFactory.classElement("BodyElement", elementType),
300 ElementFactory.classElement("ButtonElement", elementType), 300 ElementFactory.classElement("ButtonElement", elementType),
301 canvasElement, 301 canvasElement,
302 contextElement, 302 contextElement,
303 context2dElement, 303 context2dElement,
304 ElementFactory.classElement("DivElement", elementType), 304 ElementFactory.classElement("DivElement", elementType),
305 documentElement, 305 documentElement,
306 elementElement, 306 elementElement,
307 htmlDocumentElement, 307 htmlDocumentElement,
308 ElementFactory.classElement("InputElement", elementType), 308 ElementFactory.classElement("InputElement", elementType),
309 ElementFactory.classElement("SelectElement", elementType) 309 ElementFactory.classElement("SelectElement", elementType)
310 ]; 310 ];
311 htmlUnit.functions = <FunctionElement>[ 311 htmlUnit.functions = <FunctionElement>[
312 ElementFactory.functionElement3("query", elementElement, 312 ElementFactory.functionElement3("query", elementElement,
313 <ClassElement>[provider.stringType.element], ClassElement.EMPTY_LIST) 313 <ClassElement>[provider.stringType.element], ClassElement.EMPTY_LIST)
314 ]; 314 ];
315 TopLevelVariableElementImpl document = ElementFactory 315 TopLevelVariableElementImpl document =
316 .topLevelVariableElement3( 316 ElementFactory.topLevelVariableElement3(
317 "document", false, true, htmlDocumentElement.type); 317 "document", false, true, htmlDocumentElement.type);
318 htmlUnit.topLevelVariables = <TopLevelVariableElement>[document]; 318 htmlUnit.topLevelVariables = <TopLevelVariableElement>[document];
319 htmlUnit.accessors = <PropertyAccessorElement>[document.getter]; 319 htmlUnit.accessors = <PropertyAccessorElement>[document.getter];
320 LibraryElementImpl htmlLibrary = new LibraryElementImpl.forNode( 320 LibraryElementImpl htmlLibrary = new LibraryElementImpl.forNode(
321 coreContext, AstFactory.libraryIdentifier2(["dart", "dom", "html"])); 321 coreContext, AstFactory.libraryIdentifier2(["dart", "dom", "html"]));
322 htmlLibrary.definingCompilationUnit = htmlUnit; 322 htmlLibrary.definingCompilationUnit = htmlUnit;
323 // 323 //
324 // dart:math 324 // dart:math
325 // 325 //
326 CompilationUnitElementImpl mathUnit = 326 CompilationUnitElementImpl mathUnit =
(...skipping 4819 matching lines...) Expand 10 before | Expand all | Expand 10 after
5146 5146
5147 void test_getMapOfMembersInheritedFromInterfaces_implicitExtends() { 5147 void test_getMapOfMembersInheritedFromInterfaces_implicitExtends() {
5148 // class A {} 5148 // class A {}
5149 ClassElementImpl classA = ElementFactory.classElement2("A"); 5149 ClassElementImpl classA = ElementFactory.classElement2("A");
5150 MemberMap mapA = 5150 MemberMap mapA =
5151 _inheritanceManager.getMapOfMembersInheritedFromInterfaces(classA); 5151 _inheritanceManager.getMapOfMembersInheritedFromInterfaces(classA);
5152 expect(mapA.size, _numOfMembersInObject); 5152 expect(mapA.size, _numOfMembersInObject);
5153 _assertNoErrors(classA); 5153 _assertNoErrors(classA);
5154 } 5154 }
5155 5155
5156 void test_getMapOfMembersInheritedFromInterfaces_inconsistentMethodInheritance _getter_method() { 5156 void
5157 test_getMapOfMembersInheritedFromInterfaces_inconsistentMethodInheritance_ getter_method() {
5157 // class I1 { int m(); } 5158 // class I1 { int m(); }
5158 // class I2 { int get m; } 5159 // class I2 { int get m; }
5159 // class A implements I2, I1 {} 5160 // class A implements I2, I1 {}
5160 ClassElementImpl classI1 = ElementFactory.classElement2("I1"); 5161 ClassElementImpl classI1 = ElementFactory.classElement2("I1");
5161 String methodName = "m"; 5162 String methodName = "m";
5162 MethodElement methodM = 5163 MethodElement methodM =
5163 ElementFactory.methodElement(methodName, _typeProvider.intType); 5164 ElementFactory.methodElement(methodName, _typeProvider.intType);
5164 classI1.methods = <MethodElement>[methodM]; 5165 classI1.methods = <MethodElement>[methodM];
5165 ClassElementImpl classI2 = ElementFactory.classElement2("I2"); 5166 ClassElementImpl classI2 = ElementFactory.classElement2("I2");
5166 PropertyAccessorElement getter = 5167 PropertyAccessorElement getter =
5167 ElementFactory.getterElement(methodName, false, _typeProvider.intType); 5168 ElementFactory.getterElement(methodName, false, _typeProvider.intType);
5168 classI2.accessors = <PropertyAccessorElement>[getter]; 5169 classI2.accessors = <PropertyAccessorElement>[getter];
5169 ClassElementImpl classA = ElementFactory.classElement2("A"); 5170 ClassElementImpl classA = ElementFactory.classElement2("A");
5170 classA.interfaces = <InterfaceType>[classI2.type, classI1.type]; 5171 classA.interfaces = <InterfaceType>[classI2.type, classI1.type];
5171 MemberMap mapA = 5172 MemberMap mapA =
5172 _inheritanceManager.getMapOfMembersInheritedFromInterfaces(classA); 5173 _inheritanceManager.getMapOfMembersInheritedFromInterfaces(classA);
5173 expect(mapA.size, _numOfMembersInObject); 5174 expect(mapA.size, _numOfMembersInObject);
5174 expect(mapA.get(methodName), isNull); 5175 expect(mapA.get(methodName), isNull);
5175 _assertErrors(classA, 5176 _assertErrors(classA,
5176 [StaticWarningCode.INCONSISTENT_METHOD_INHERITANCE_GETTER_AND_METHOD]); 5177 [StaticWarningCode.INCONSISTENT_METHOD_INHERITANCE_GETTER_AND_METHOD]);
5177 } 5178 }
5178 5179
5179 void test_getMapOfMembersInheritedFromInterfaces_inconsistentMethodInheritance _int_str() { 5180 void
5181 test_getMapOfMembersInheritedFromInterfaces_inconsistentMethodInheritance_ int_str() {
5180 // class I1 { int m(); } 5182 // class I1 { int m(); }
5181 // class I2 { String m(); } 5183 // class I2 { String m(); }
5182 // class A implements I1, I2 {} 5184 // class A implements I1, I2 {}
5183 ClassElementImpl classI1 = ElementFactory.classElement2("I1"); 5185 ClassElementImpl classI1 = ElementFactory.classElement2("I1");
5184 String methodName = "m"; 5186 String methodName = "m";
5185 MethodElement methodM1 = 5187 MethodElement methodM1 =
5186 ElementFactory.methodElement(methodName, null, [_typeProvider.intType]); 5188 ElementFactory.methodElement(methodName, null, [_typeProvider.intType]);
5187 classI1.methods = <MethodElement>[methodM1]; 5189 classI1.methods = <MethodElement>[methodM1];
5188 ClassElementImpl classI2 = ElementFactory.classElement2("I2"); 5190 ClassElementImpl classI2 = ElementFactory.classElement2("I2");
5189 MethodElement methodM2 = ElementFactory.methodElement( 5191 MethodElement methodM2 = ElementFactory
5190 methodName, null, [_typeProvider.stringType]); 5192 .methodElement(methodName, null, [_typeProvider.stringType]);
5191 classI2.methods = <MethodElement>[methodM2]; 5193 classI2.methods = <MethodElement>[methodM2];
5192 ClassElementImpl classA = ElementFactory.classElement2("A"); 5194 ClassElementImpl classA = ElementFactory.classElement2("A");
5193 classA.interfaces = <InterfaceType>[classI1.type, classI2.type]; 5195 classA.interfaces = <InterfaceType>[classI1.type, classI2.type];
5194 MemberMap mapA = 5196 MemberMap mapA =
5195 _inheritanceManager.getMapOfMembersInheritedFromInterfaces(classA); 5197 _inheritanceManager.getMapOfMembersInheritedFromInterfaces(classA);
5196 expect(mapA.size, _numOfMembersInObject); 5198 expect(mapA.size, _numOfMembersInObject);
5197 expect(mapA.get(methodName), isNull); 5199 expect(mapA.get(methodName), isNull);
5198 _assertErrors( 5200 _assertErrors(
5199 classA, [StaticTypeWarningCode.INCONSISTENT_METHOD_INHERITANCE]); 5201 classA, [StaticTypeWarningCode.INCONSISTENT_METHOD_INHERITANCE]);
5200 } 5202 }
5201 5203
5202 void test_getMapOfMembersInheritedFromInterfaces_inconsistentMethodInheritance _method_getter() { 5204 void
5205 test_getMapOfMembersInheritedFromInterfaces_inconsistentMethodInheritance_ method_getter() {
5203 // class I1 { int m(); } 5206 // class I1 { int m(); }
5204 // class I2 { int get m; } 5207 // class I2 { int get m; }
5205 // class A implements I1, I2 {} 5208 // class A implements I1, I2 {}
5206 ClassElementImpl classI1 = ElementFactory.classElement2("I1"); 5209 ClassElementImpl classI1 = ElementFactory.classElement2("I1");
5207 String methodName = "m"; 5210 String methodName = "m";
5208 MethodElement methodM = 5211 MethodElement methodM =
5209 ElementFactory.methodElement(methodName, _typeProvider.intType); 5212 ElementFactory.methodElement(methodName, _typeProvider.intType);
5210 classI1.methods = <MethodElement>[methodM]; 5213 classI1.methods = <MethodElement>[methodM];
5211 ClassElementImpl classI2 = ElementFactory.classElement2("I2"); 5214 ClassElementImpl classI2 = ElementFactory.classElement2("I2");
5212 PropertyAccessorElement getter = 5215 PropertyAccessorElement getter =
5213 ElementFactory.getterElement(methodName, false, _typeProvider.intType); 5216 ElementFactory.getterElement(methodName, false, _typeProvider.intType);
5214 classI2.accessors = <PropertyAccessorElement>[getter]; 5217 classI2.accessors = <PropertyAccessorElement>[getter];
5215 ClassElementImpl classA = ElementFactory.classElement2("A"); 5218 ClassElementImpl classA = ElementFactory.classElement2("A");
5216 classA.interfaces = <InterfaceType>[classI1.type, classI2.type]; 5219 classA.interfaces = <InterfaceType>[classI1.type, classI2.type];
5217 MemberMap mapA = 5220 MemberMap mapA =
5218 _inheritanceManager.getMapOfMembersInheritedFromInterfaces(classA); 5221 _inheritanceManager.getMapOfMembersInheritedFromInterfaces(classA);
5219 expect(mapA.size, _numOfMembersInObject); 5222 expect(mapA.size, _numOfMembersInObject);
5220 expect(mapA.get(methodName), isNull); 5223 expect(mapA.get(methodName), isNull);
5221 _assertErrors(classA, 5224 _assertErrors(classA,
5222 [StaticWarningCode.INCONSISTENT_METHOD_INHERITANCE_GETTER_AND_METHOD]); 5225 [StaticWarningCode.INCONSISTENT_METHOD_INHERITANCE_GETTER_AND_METHOD]);
5223 } 5226 }
5224 5227
5225 void test_getMapOfMembersInheritedFromInterfaces_inconsistentMethodInheritance _numOfRequiredParams() { 5228 void
5229 test_getMapOfMembersInheritedFromInterfaces_inconsistentMethodInheritance_ numOfRequiredParams() {
5226 // class I1 { dynamic m(int, [int]); } 5230 // class I1 { dynamic m(int, [int]); }
5227 // class I2 { dynamic m(int, int, int); } 5231 // class I2 { dynamic m(int, int, int); }
5228 // class A implements I1, I2 {} 5232 // class A implements I1, I2 {}
5229 ClassElementImpl classI1 = ElementFactory.classElement2("I1"); 5233 ClassElementImpl classI1 = ElementFactory.classElement2("I1");
5230 String methodName = "m"; 5234 String methodName = "m";
5231 MethodElementImpl methodM1 = 5235 MethodElementImpl methodM1 =
5232 ElementFactory.methodElement(methodName, _typeProvider.dynamicType); 5236 ElementFactory.methodElement(methodName, _typeProvider.dynamicType);
5233 ParameterElementImpl parameter1 = 5237 ParameterElementImpl parameter1 =
5234 new ParameterElementImpl.forNode(AstFactory.identifier3("a1")); 5238 new ParameterElementImpl.forNode(AstFactory.identifier3("a1"));
5235 parameter1.type = _typeProvider.intType; 5239 parameter1.type = _typeProvider.intType;
(...skipping 28 matching lines...) Expand all
5264 ClassElementImpl classA = ElementFactory.classElement2("A"); 5268 ClassElementImpl classA = ElementFactory.classElement2("A");
5265 classA.interfaces = <InterfaceType>[classI1.type, classI2.type]; 5269 classA.interfaces = <InterfaceType>[classI1.type, classI2.type];
5266 MemberMap mapA = 5270 MemberMap mapA =
5267 _inheritanceManager.getMapOfMembersInheritedFromInterfaces(classA); 5271 _inheritanceManager.getMapOfMembersInheritedFromInterfaces(classA);
5268 expect(mapA.size, _numOfMembersInObject); 5272 expect(mapA.size, _numOfMembersInObject);
5269 expect(mapA.get(methodName), isNull); 5273 expect(mapA.get(methodName), isNull);
5270 _assertErrors( 5274 _assertErrors(
5271 classA, [StaticTypeWarningCode.INCONSISTENT_METHOD_INHERITANCE]); 5275 classA, [StaticTypeWarningCode.INCONSISTENT_METHOD_INHERITANCE]);
5272 } 5276 }
5273 5277
5274 void test_getMapOfMembersInheritedFromInterfaces_inconsistentMethodInheritance _str_int() { 5278 void
5279 test_getMapOfMembersInheritedFromInterfaces_inconsistentMethodInheritance_ str_int() {
5275 // class I1 { int m(); } 5280 // class I1 { int m(); }
5276 // class I2 { String m(); } 5281 // class I2 { String m(); }
5277 // class A implements I2, I1 {} 5282 // class A implements I2, I1 {}
5278 ClassElementImpl classI1 = ElementFactory.classElement2("I1"); 5283 ClassElementImpl classI1 = ElementFactory.classElement2("I1");
5279 String methodName = "m"; 5284 String methodName = "m";
5280 MethodElement methodM1 = ElementFactory.methodElement( 5285 MethodElement methodM1 = ElementFactory
5281 methodName, null, [_typeProvider.stringType]); 5286 .methodElement(methodName, null, [_typeProvider.stringType]);
5282 classI1.methods = <MethodElement>[methodM1]; 5287 classI1.methods = <MethodElement>[methodM1];
5283 ClassElementImpl classI2 = ElementFactory.classElement2("I2"); 5288 ClassElementImpl classI2 = ElementFactory.classElement2("I2");
5284 MethodElement methodM2 = 5289 MethodElement methodM2 =
5285 ElementFactory.methodElement(methodName, null, [_typeProvider.intType]); 5290 ElementFactory.methodElement(methodName, null, [_typeProvider.intType]);
5286 classI2.methods = <MethodElement>[methodM2]; 5291 classI2.methods = <MethodElement>[methodM2];
5287 ClassElementImpl classA = ElementFactory.classElement2("A"); 5292 ClassElementImpl classA = ElementFactory.classElement2("A");
5288 classA.interfaces = <InterfaceType>[classI2.type, classI1.type]; 5293 classA.interfaces = <InterfaceType>[classI2.type, classI1.type];
5289 MemberMap mapA = 5294 MemberMap mapA =
5290 _inheritanceManager.getMapOfMembersInheritedFromInterfaces(classA); 5295 _inheritanceManager.getMapOfMembersInheritedFromInterfaces(classA);
5291 expect(mapA.size, _numOfMembersInObject); 5296 expect(mapA.size, _numOfMembersInObject);
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
5373 ClassElementImpl classA = ElementFactory.classElement2("A"); 5378 ClassElementImpl classA = ElementFactory.classElement2("A");
5374 classA.interfaces = <InterfaceType>[classI1.type, classI2.type]; 5379 classA.interfaces = <InterfaceType>[classI1.type, classI2.type];
5375 MemberMap mapA = 5380 MemberMap mapA =
5376 _inheritanceManager.getMapOfMembersInheritedFromInterfaces(classA); 5381 _inheritanceManager.getMapOfMembersInheritedFromInterfaces(classA);
5377 expect(mapA.size, _numOfMembersInObject + 2); 5382 expect(mapA.size, _numOfMembersInObject + 2);
5378 expect(mapA.get(methodName1), same(methodM1)); 5383 expect(mapA.get(methodName1), same(methodM1));
5379 expect(mapA.get(methodName2), same(methodM2)); 5384 expect(mapA.get(methodName2), same(methodM2));
5380 _assertNoErrors(classA); 5385 _assertNoErrors(classA);
5381 } 5386 }
5382 5387
5383 void test_getMapOfMembersInheritedFromInterfaces_union_multipleSubtypes_2_gett ers() { 5388 void
5389 test_getMapOfMembersInheritedFromInterfaces_union_multipleSubtypes_2_gette rs() {
5384 // class I1 { int get g; } 5390 // class I1 { int get g; }
5385 // class I2 { num get g; } 5391 // class I2 { num get g; }
5386 // class A implements I1, I2 {} 5392 // class A implements I1, I2 {}
5387 ClassElementImpl classI1 = ElementFactory.classElement2("I1"); 5393 ClassElementImpl classI1 = ElementFactory.classElement2("I1");
5388 String accessorName = "g"; 5394 String accessorName = "g";
5389 PropertyAccessorElement getter1 = ElementFactory.getterElement( 5395 PropertyAccessorElement getter1 = ElementFactory.getterElement(
5390 accessorName, false, _typeProvider.intType); 5396 accessorName, false, _typeProvider.intType);
5391 classI1.accessors = <PropertyAccessorElement>[getter1]; 5397 classI1.accessors = <PropertyAccessorElement>[getter1];
5392 ClassElementImpl classI2 = ElementFactory.classElement2("I2"); 5398 ClassElementImpl classI2 = ElementFactory.classElement2("I2");
5393 PropertyAccessorElement getter2 = ElementFactory.getterElement( 5399 PropertyAccessorElement getter2 = ElementFactory.getterElement(
5394 accessorName, false, _typeProvider.numType); 5400 accessorName, false, _typeProvider.numType);
5395 classI2.accessors = <PropertyAccessorElement>[getter2]; 5401 classI2.accessors = <PropertyAccessorElement>[getter2];
5396 ClassElementImpl classA = ElementFactory.classElement2("A"); 5402 ClassElementImpl classA = ElementFactory.classElement2("A");
5397 classA.interfaces = <InterfaceType>[classI1.type, classI2.type]; 5403 classA.interfaces = <InterfaceType>[classI1.type, classI2.type];
5398 MemberMap mapA = 5404 MemberMap mapA =
5399 _inheritanceManager.getMapOfMembersInheritedFromInterfaces(classA); 5405 _inheritanceManager.getMapOfMembersInheritedFromInterfaces(classA);
5400 expect(mapA.size, _numOfMembersInObject + 1); 5406 expect(mapA.size, _numOfMembersInObject + 1);
5401 PropertyAccessorElement syntheticAccessor = ElementFactory.getterElement( 5407 PropertyAccessorElement syntheticAccessor = ElementFactory.getterElement(
5402 accessorName, false, _typeProvider.dynamicType); 5408 accessorName, false, _typeProvider.dynamicType);
5403 expect(mapA.get(accessorName).type, syntheticAccessor.type); 5409 expect(mapA.get(accessorName).type, syntheticAccessor.type);
5404 _assertNoErrors(classA); 5410 _assertNoErrors(classA);
5405 } 5411 }
5406 5412
5407 void test_getMapOfMembersInheritedFromInterfaces_union_multipleSubtypes_2_meth ods() { 5413 void
5414 test_getMapOfMembersInheritedFromInterfaces_union_multipleSubtypes_2_metho ds() {
5408 // class I1 { dynamic m(int); } 5415 // class I1 { dynamic m(int); }
5409 // class I2 { dynamic m(num); } 5416 // class I2 { dynamic m(num); }
5410 // class A implements I1, I2 {} 5417 // class A implements I1, I2 {}
5411 ClassElementImpl classI1 = ElementFactory.classElement2("I1"); 5418 ClassElementImpl classI1 = ElementFactory.classElement2("I1");
5412 String methodName = "m"; 5419 String methodName = "m";
5413 MethodElementImpl methodM1 = 5420 MethodElementImpl methodM1 =
5414 ElementFactory.methodElement(methodName, _typeProvider.dynamicType); 5421 ElementFactory.methodElement(methodName, _typeProvider.dynamicType);
5415 ParameterElementImpl parameter1 = 5422 ParameterElementImpl parameter1 =
5416 new ParameterElementImpl.forNode(AstFactory.identifier3("a0")); 5423 new ParameterElementImpl.forNode(AstFactory.identifier3("a0"));
5417 parameter1.type = _typeProvider.intType; 5424 parameter1.type = _typeProvider.intType;
(...skipping 13 matching lines...) Expand all
5431 classA.interfaces = <InterfaceType>[classI1.type, classI2.type]; 5438 classA.interfaces = <InterfaceType>[classI1.type, classI2.type];
5432 MemberMap mapA = 5439 MemberMap mapA =
5433 _inheritanceManager.getMapOfMembersInheritedFromInterfaces(classA); 5440 _inheritanceManager.getMapOfMembersInheritedFromInterfaces(classA);
5434 expect(mapA.size, _numOfMembersInObject + 1); 5441 expect(mapA.size, _numOfMembersInObject + 1);
5435 MethodElement syntheticMethod = ElementFactory.methodElement( 5442 MethodElement syntheticMethod = ElementFactory.methodElement(
5436 methodName, _typeProvider.dynamicType, [_typeProvider.dynamicType]); 5443 methodName, _typeProvider.dynamicType, [_typeProvider.dynamicType]);
5437 expect(mapA.get(methodName).type, syntheticMethod.type); 5444 expect(mapA.get(methodName).type, syntheticMethod.type);
5438 _assertNoErrors(classA); 5445 _assertNoErrors(classA);
5439 } 5446 }
5440 5447
5441 void test_getMapOfMembersInheritedFromInterfaces_union_multipleSubtypes_2_sett ers() { 5448 void
5449 test_getMapOfMembersInheritedFromInterfaces_union_multipleSubtypes_2_sette rs() {
5442 // class I1 { set s(int); } 5450 // class I1 { set s(int); }
5443 // class I2 { set s(num); } 5451 // class I2 { set s(num); }
5444 // class A implements I1, I2 {} 5452 // class A implements I1, I2 {}
5445 ClassElementImpl classI1 = ElementFactory.classElement2("I1"); 5453 ClassElementImpl classI1 = ElementFactory.classElement2("I1");
5446 String accessorName = "s"; 5454 String accessorName = "s";
5447 PropertyAccessorElement setter1 = ElementFactory.setterElement( 5455 PropertyAccessorElement setter1 = ElementFactory.setterElement(
5448 accessorName, false, _typeProvider.intType); 5456 accessorName, false, _typeProvider.intType);
5449 classI1.accessors = <PropertyAccessorElement>[setter1]; 5457 classI1.accessors = <PropertyAccessorElement>[setter1];
5450 ClassElementImpl classI2 = ElementFactory.classElement2("I2"); 5458 ClassElementImpl classI2 = ElementFactory.classElement2("I2");
5451 PropertyAccessorElement setter2 = ElementFactory.setterElement( 5459 PropertyAccessorElement setter2 = ElementFactory.setterElement(
5452 accessorName, false, _typeProvider.numType); 5460 accessorName, false, _typeProvider.numType);
5453 classI2.accessors = <PropertyAccessorElement>[setter2]; 5461 classI2.accessors = <PropertyAccessorElement>[setter2];
5454 ClassElementImpl classA = ElementFactory.classElement2("A"); 5462 ClassElementImpl classA = ElementFactory.classElement2("A");
5455 classA.interfaces = <InterfaceType>[classI1.type, classI2.type]; 5463 classA.interfaces = <InterfaceType>[classI1.type, classI2.type];
5456 MemberMap mapA = 5464 MemberMap mapA =
5457 _inheritanceManager.getMapOfMembersInheritedFromInterfaces(classA); 5465 _inheritanceManager.getMapOfMembersInheritedFromInterfaces(classA);
5458 expect(mapA.size, _numOfMembersInObject + 1); 5466 expect(mapA.size, _numOfMembersInObject + 1);
5459 PropertyAccessorElementImpl syntheticAccessor = ElementFactory 5467 PropertyAccessorElementImpl syntheticAccessor = ElementFactory
5460 .setterElement(accessorName, false, _typeProvider.dynamicType); 5468 .setterElement(accessorName, false, _typeProvider.dynamicType);
5461 syntheticAccessor.returnType = _typeProvider.dynamicType; 5469 syntheticAccessor.returnType = _typeProvider.dynamicType;
5462 expect(mapA.get("$accessorName=").type, syntheticAccessor.type); 5470 expect(mapA.get("$accessorName=").type, syntheticAccessor.type);
5463 _assertNoErrors(classA); 5471 _assertNoErrors(classA);
5464 } 5472 }
5465 5473
5466 void test_getMapOfMembersInheritedFromInterfaces_union_multipleSubtypes_3_gett ers() { 5474 void
5475 test_getMapOfMembersInheritedFromInterfaces_union_multipleSubtypes_3_gette rs() {
5467 // class A {} 5476 // class A {}
5468 // class B extends A {} 5477 // class B extends A {}
5469 // class C extends B {} 5478 // class C extends B {}
5470 // class I1 { A get g; } 5479 // class I1 { A get g; }
5471 // class I2 { B get g; } 5480 // class I2 { B get g; }
5472 // class I3 { C get g; } 5481 // class I3 { C get g; }
5473 // class D implements I1, I2, I3 {} 5482 // class D implements I1, I2, I3 {}
5474 ClassElementImpl classA = ElementFactory.classElement2("A"); 5483 ClassElementImpl classA = ElementFactory.classElement2("A");
5475 ClassElementImpl classB = ElementFactory.classElement("B", classA.type); 5484 ClassElementImpl classB = ElementFactory.classElement("B", classA.type);
5476 ClassElementImpl classC = ElementFactory.classElement("C", classB.type); 5485 ClassElementImpl classC = ElementFactory.classElement("C", classB.type);
(...skipping 18 matching lines...) Expand all
5495 ]; 5504 ];
5496 MemberMap mapD = 5505 MemberMap mapD =
5497 _inheritanceManager.getMapOfMembersInheritedFromInterfaces(classD); 5506 _inheritanceManager.getMapOfMembersInheritedFromInterfaces(classD);
5498 expect(mapD.size, _numOfMembersInObject + 1); 5507 expect(mapD.size, _numOfMembersInObject + 1);
5499 PropertyAccessorElement syntheticAccessor = ElementFactory.getterElement( 5508 PropertyAccessorElement syntheticAccessor = ElementFactory.getterElement(
5500 accessorName, false, _typeProvider.dynamicType); 5509 accessorName, false, _typeProvider.dynamicType);
5501 expect(mapD.get(accessorName).type, syntheticAccessor.type); 5510 expect(mapD.get(accessorName).type, syntheticAccessor.type);
5502 _assertNoErrors(classD); 5511 _assertNoErrors(classD);
5503 } 5512 }
5504 5513
5505 void test_getMapOfMembersInheritedFromInterfaces_union_multipleSubtypes_3_meth ods() { 5514 void
5515 test_getMapOfMembersInheritedFromInterfaces_union_multipleSubtypes_3_metho ds() {
5506 // class A {} 5516 // class A {}
5507 // class B extends A {} 5517 // class B extends A {}
5508 // class C extends B {} 5518 // class C extends B {}
5509 // class I1 { dynamic m(A a); } 5519 // class I1 { dynamic m(A a); }
5510 // class I2 { dynamic m(B b); } 5520 // class I2 { dynamic m(B b); }
5511 // class I3 { dynamic m(C c); } 5521 // class I3 { dynamic m(C c); }
5512 // class D implements I1, I2, I3 {} 5522 // class D implements I1, I2, I3 {}
5513 ClassElementImpl classA = ElementFactory.classElement2("A"); 5523 ClassElementImpl classA = ElementFactory.classElement2("A");
5514 ClassElementImpl classB = ElementFactory.classElement("B", classA.type); 5524 ClassElementImpl classB = ElementFactory.classElement("B", classA.type);
5515 ClassElementImpl classC = ElementFactory.classElement("C", classB.type); 5525 ClassElementImpl classC = ElementFactory.classElement("C", classB.type);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
5549 ]; 5559 ];
5550 MemberMap mapD = 5560 MemberMap mapD =
5551 _inheritanceManager.getMapOfMembersInheritedFromInterfaces(classD); 5561 _inheritanceManager.getMapOfMembersInheritedFromInterfaces(classD);
5552 expect(mapD.size, _numOfMembersInObject + 1); 5562 expect(mapD.size, _numOfMembersInObject + 1);
5553 MethodElement syntheticMethod = ElementFactory.methodElement( 5563 MethodElement syntheticMethod = ElementFactory.methodElement(
5554 methodName, _typeProvider.dynamicType, [_typeProvider.dynamicType]); 5564 methodName, _typeProvider.dynamicType, [_typeProvider.dynamicType]);
5555 expect(mapD.get(methodName).type, syntheticMethod.type); 5565 expect(mapD.get(methodName).type, syntheticMethod.type);
5556 _assertNoErrors(classD); 5566 _assertNoErrors(classD);
5557 } 5567 }
5558 5568
5559 void test_getMapOfMembersInheritedFromInterfaces_union_multipleSubtypes_3_sett ers() { 5569 void
5570 test_getMapOfMembersInheritedFromInterfaces_union_multipleSubtypes_3_sette rs() {
5560 // class A {} 5571 // class A {}
5561 // class B extends A {} 5572 // class B extends A {}
5562 // class C extends B {} 5573 // class C extends B {}
5563 // class I1 { set s(A); } 5574 // class I1 { set s(A); }
5564 // class I2 { set s(B); } 5575 // class I2 { set s(B); }
5565 // class I3 { set s(C); } 5576 // class I3 { set s(C); }
5566 // class D implements I1, I2, I3 {} 5577 // class D implements I1, I2, I3 {}
5567 ClassElementImpl classA = ElementFactory.classElement2("A"); 5578 ClassElementImpl classA = ElementFactory.classElement2("A");
5568 ClassElementImpl classB = ElementFactory.classElement("B", classA.type); 5579 ClassElementImpl classB = ElementFactory.classElement("B", classA.type);
5569 ClassElementImpl classC = ElementFactory.classElement("C", classB.type); 5580 ClassElementImpl classC = ElementFactory.classElement("C", classB.type);
(...skipping 19 matching lines...) Expand all
5589 MemberMap mapD = 5600 MemberMap mapD =
5590 _inheritanceManager.getMapOfMembersInheritedFromInterfaces(classD); 5601 _inheritanceManager.getMapOfMembersInheritedFromInterfaces(classD);
5591 expect(mapD.size, _numOfMembersInObject + 1); 5602 expect(mapD.size, _numOfMembersInObject + 1);
5592 PropertyAccessorElementImpl syntheticAccessor = ElementFactory 5603 PropertyAccessorElementImpl syntheticAccessor = ElementFactory
5593 .setterElement(accessorName, false, _typeProvider.dynamicType); 5604 .setterElement(accessorName, false, _typeProvider.dynamicType);
5594 syntheticAccessor.returnType = _typeProvider.dynamicType; 5605 syntheticAccessor.returnType = _typeProvider.dynamicType;
5595 expect(mapD.get("$accessorName=").type, syntheticAccessor.type); 5606 expect(mapD.get("$accessorName=").type, syntheticAccessor.type);
5596 _assertNoErrors(classD); 5607 _assertNoErrors(classD);
5597 } 5608 }
5598 5609
5599 void test_getMapOfMembersInheritedFromInterfaces_union_oneSubtype_2_methods() { 5610 void
5611 test_getMapOfMembersInheritedFromInterfaces_union_oneSubtype_2_methods() {
5600 // class I1 { int m(); } 5612 // class I1 { int m(); }
5601 // class I2 { int m([int]); } 5613 // class I2 { int m([int]); }
5602 // class A implements I1, I2 {} 5614 // class A implements I1, I2 {}
5603 ClassElementImpl classI1 = ElementFactory.classElement2("I1"); 5615 ClassElementImpl classI1 = ElementFactory.classElement2("I1");
5604 String methodName = "m"; 5616 String methodName = "m";
5605 MethodElement methodM1 = 5617 MethodElement methodM1 =
5606 ElementFactory.methodElement(methodName, _typeProvider.intType); 5618 ElementFactory.methodElement(methodName, _typeProvider.intType);
5607 classI1.methods = <MethodElement>[methodM1]; 5619 classI1.methods = <MethodElement>[methodM1];
5608 ClassElementImpl classI2 = ElementFactory.classElement2("I2"); 5620 ClassElementImpl classI2 = ElementFactory.classElement2("I2");
5609 MethodElementImpl methodM2 = 5621 MethodElementImpl methodM2 =
5610 ElementFactory.methodElement(methodName, _typeProvider.intType); 5622 ElementFactory.methodElement(methodName, _typeProvider.intType);
5611 ParameterElementImpl parameter1 = 5623 ParameterElementImpl parameter1 =
5612 new ParameterElementImpl.forNode(AstFactory.identifier3("a1")); 5624 new ParameterElementImpl.forNode(AstFactory.identifier3("a1"));
5613 parameter1.type = _typeProvider.intType; 5625 parameter1.type = _typeProvider.intType;
5614 parameter1.parameterKind = ParameterKind.POSITIONAL; 5626 parameter1.parameterKind = ParameterKind.POSITIONAL;
5615 methodM2.parameters = <ParameterElement>[parameter1]; 5627 methodM2.parameters = <ParameterElement>[parameter1];
5616 classI2.methods = <MethodElement>[methodM2]; 5628 classI2.methods = <MethodElement>[methodM2];
5617 ClassElementImpl classA = ElementFactory.classElement2("A"); 5629 ClassElementImpl classA = ElementFactory.classElement2("A");
5618 classA.interfaces = <InterfaceType>[classI1.type, classI2.type]; 5630 classA.interfaces = <InterfaceType>[classI1.type, classI2.type];
5619 MemberMap mapA = 5631 MemberMap mapA =
5620 _inheritanceManager.getMapOfMembersInheritedFromInterfaces(classA); 5632 _inheritanceManager.getMapOfMembersInheritedFromInterfaces(classA);
5621 expect(mapA.size, _numOfMembersInObject + 1); 5633 expect(mapA.size, _numOfMembersInObject + 1);
5622 expect(mapA.get(methodName), same(methodM2)); 5634 expect(mapA.get(methodName), same(methodM2));
5623 _assertNoErrors(classA); 5635 _assertNoErrors(classA);
5624 } 5636 }
5625 5637
5626 void test_getMapOfMembersInheritedFromInterfaces_union_oneSubtype_3_methods() { 5638 void
5639 test_getMapOfMembersInheritedFromInterfaces_union_oneSubtype_3_methods() {
5627 // class I1 { int m(); } 5640 // class I1 { int m(); }
5628 // class I2 { int m([int]); } 5641 // class I2 { int m([int]); }
5629 // class I3 { int m([int, int]); } 5642 // class I3 { int m([int, int]); }
5630 // class A implements I1, I2, I3 {} 5643 // class A implements I1, I2, I3 {}
5631 ClassElementImpl classI1 = ElementFactory.classElement2("I1"); 5644 ClassElementImpl classI1 = ElementFactory.classElement2("I1");
5632 String methodName = "m"; 5645 String methodName = "m";
5633 MethodElementImpl methodM1 = 5646 MethodElementImpl methodM1 =
5634 ElementFactory.methodElement(methodName, _typeProvider.intType); 5647 ElementFactory.methodElement(methodName, _typeProvider.intType);
5635 classI1.methods = <MethodElement>[methodM1]; 5648 classI1.methods = <MethodElement>[methodM1];
5636 ClassElementImpl classI2 = ElementFactory.classElement2("I2"); 5649 ClassElementImpl classI2 = ElementFactory.classElement2("I2");
(...skipping 24 matching lines...) Expand all
5661 classI2.type, 5674 classI2.type,
5662 classI3.type 5675 classI3.type
5663 ]; 5676 ];
5664 MemberMap mapA = 5677 MemberMap mapA =
5665 _inheritanceManager.getMapOfMembersInheritedFromInterfaces(classA); 5678 _inheritanceManager.getMapOfMembersInheritedFromInterfaces(classA);
5666 expect(mapA.size, _numOfMembersInObject + 1); 5679 expect(mapA.size, _numOfMembersInObject + 1);
5667 expect(mapA.get(methodName), same(methodM3)); 5680 expect(mapA.get(methodName), same(methodM3));
5668 _assertNoErrors(classA); 5681 _assertNoErrors(classA);
5669 } 5682 }
5670 5683
5671 void test_getMapOfMembersInheritedFromInterfaces_union_oneSubtype_4_methods() { 5684 void
5685 test_getMapOfMembersInheritedFromInterfaces_union_oneSubtype_4_methods() {
5672 // class I1 { int m(); } 5686 // class I1 { int m(); }
5673 // class I2 { int m(); } 5687 // class I2 { int m(); }
5674 // class I3 { int m([int]); } 5688 // class I3 { int m([int]); }
5675 // class I4 { int m([int, int]); } 5689 // class I4 { int m([int, int]); }
5676 // class A implements I1, I2, I3, I4 {} 5690 // class A implements I1, I2, I3, I4 {}
5677 ClassElementImpl classI1 = ElementFactory.classElement2("I1"); 5691 ClassElementImpl classI1 = ElementFactory.classElement2("I1");
5678 String methodName = "m"; 5692 String methodName = "m";
5679 MethodElement methodM1 = 5693 MethodElement methodM1 =
5680 ElementFactory.methodElement(methodName, _typeProvider.intType); 5694 ElementFactory.methodElement(methodName, _typeProvider.intType);
5681 classI1.methods = <MethodElement>[methodM1]; 5695 classI1.methods = <MethodElement>[methodM1];
(...skipping 3681 matching lines...) Expand 10 before | Expand all | Expand 10 after
9363 expect(classes, hasLength(1)); 9377 expect(classes, hasLength(1));
9364 List<ElementAnnotation> annotations = classes[0].metadata; 9378 List<ElementAnnotation> annotations = classes[0].metadata;
9365 expect(annotations, hasLength(1)); 9379 expect(annotations, hasLength(1));
9366 assertNoErrors(source); 9380 assertNoErrors(source);
9367 verify([source]); 9381 verify([source]);
9368 CompilationUnit unit = resolveCompilationUnit(source, library); 9382 CompilationUnit unit = resolveCompilationUnit(source, library);
9369 NodeList<CompilationUnitMember> declarations = unit.declarations; 9383 NodeList<CompilationUnitMember> declarations = unit.declarations;
9370 expect(declarations, hasLength(2)); 9384 expect(declarations, hasLength(2));
9371 Element expectedElement = (declarations[0] as TopLevelVariableDeclaration) 9385 Element expectedElement = (declarations[0] as TopLevelVariableDeclaration)
9372 .variables 9386 .variables
9373 .variables[0].name.staticElement; 9387 .variables[0]
9388 .name
9389 .staticElement;
9374 EngineTestCase.assertInstanceOf((obj) => obj is PropertyInducingElement, 9390 EngineTestCase.assertInstanceOf((obj) => obj is PropertyInducingElement,
9375 PropertyInducingElement, expectedElement); 9391 PropertyInducingElement, expectedElement);
9376 expectedElement = (expectedElement as PropertyInducingElement).getter; 9392 expectedElement = (expectedElement as PropertyInducingElement).getter;
9377 Element actualElement = 9393 Element actualElement =
9378 (declarations[1] as ClassDeclaration).metadata[0].name.staticElement; 9394 (declarations[1] as ClassDeclaration).metadata[0].name.staticElement;
9379 expect(actualElement, same(expectedElement)); 9395 expect(actualElement, same(expectedElement));
9380 } 9396 }
9381 9397
9382 void test_metadata_field() { 9398 void test_metadata_field() {
9383 Source source = addSource(r''' 9399 Source source = addSource(r'''
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
9554 expect(aliases, hasLength(1)); 9570 expect(aliases, hasLength(1));
9555 List<ElementAnnotation> annotations = aliases[0].metadata; 9571 List<ElementAnnotation> annotations = aliases[0].metadata;
9556 expect(annotations, hasLength(1)); 9572 expect(annotations, hasLength(1));
9557 assertNoErrors(source); 9573 assertNoErrors(source);
9558 verify([source]); 9574 verify([source]);
9559 CompilationUnit unit = resolveCompilationUnit(source, library); 9575 CompilationUnit unit = resolveCompilationUnit(source, library);
9560 NodeList<CompilationUnitMember> declarations = unit.declarations; 9576 NodeList<CompilationUnitMember> declarations = unit.declarations;
9561 expect(declarations, hasLength(2)); 9577 expect(declarations, hasLength(2));
9562 Element expectedElement = (declarations[0] as TopLevelVariableDeclaration) 9578 Element expectedElement = (declarations[0] as TopLevelVariableDeclaration)
9563 .variables 9579 .variables
9564 .variables[0].name.staticElement; 9580 .variables[0]
9581 .name
9582 .staticElement;
9565 EngineTestCase.assertInstanceOf((obj) => obj is PropertyInducingElement, 9583 EngineTestCase.assertInstanceOf((obj) => obj is PropertyInducingElement,
9566 PropertyInducingElement, expectedElement); 9584 PropertyInducingElement, expectedElement);
9567 expectedElement = (expectedElement as PropertyInducingElement).getter; 9585 expectedElement = (expectedElement as PropertyInducingElement).getter;
9568 Element actualElement = 9586 Element actualElement =
9569 (declarations[1] as FunctionTypeAlias).metadata[0].name.staticElement; 9587 (declarations[1] as FunctionTypeAlias).metadata[0].name.staticElement;
9570 expect(actualElement, same(expectedElement)); 9588 expect(actualElement, same(expectedElement));
9571 } 9589 }
9572 9590
9573 void test_method_fromMixin() { 9591 void test_method_fromMixin() {
9574 Source source = addSource(r''' 9592 Source source = addSource(r'''
(...skipping 2200 matching lines...) Expand 10 before | Expand all | Expand 10 after
11775 assertErrors(source, [StaticTypeWarningCode.UNDEFINED_OPERATOR]); 11793 assertErrors(source, [StaticTypeWarningCode.UNDEFINED_OPERATOR]);
11776 } 11794 }
11777 } 11795 }
11778 11796
11779 /** 11797 /**
11780 * Strong mode static analyzer downwards inference tests 11798 * Strong mode static analyzer downwards inference tests
11781 */ 11799 */
11782 @reflectiveTest 11800 @reflectiveTest
11783 class StrongModeDownwardsInferenceTest extends ResolverTestCase { 11801 class StrongModeDownwardsInferenceTest extends ResolverTestCase {
11784 TypeAssertions _assertions; 11802 TypeAssertions _assertions;
11785 AsserterBuilder<Element, DartType> _hasElement; 11803
11786 AsserterBuilder<DartType, DartType> _isType; 11804 Asserter<DartType> _isDynamic;
11787 AsserterBuilder2<Asserter<DartType>, Asserter<DartType>, 11805 Asserter<InterfaceType> _isFutureOfDynamic;
11788 DartType> _isFunction2Of; 11806 Asserter<InterfaceType> _isFutureOfInt;
11789 AsserterBuilderBuilder<Asserter<DartType>, List<Asserter<DartType>>,
11790 DartType> _isInstantiationOf;
11791 Asserter<DartType> _isInt; 11807 Asserter<DartType> _isInt;
11792 Asserter<DartType> _isNum; 11808 Asserter<DartType> _isNum;
11793 Asserter<DartType> _isString; 11809 Asserter<DartType> _isString;
11794 Asserter<DartType> _isDynamic; 11810
11811 AsserterBuilder2<Asserter<DartType>, Asserter<DartType>, DartType>
11812 _isFunction2Of;
11813 AsserterBuilder<List<Asserter<DartType>>, InterfaceType> _isFutureOf;
11814 AsserterBuilderBuilder<Asserter<DartType>, List<Asserter<DartType>>, DartType>
11815 _isInstantiationOf;
11795 AsserterBuilder<Asserter<DartType>, InterfaceType> _isListOf; 11816 AsserterBuilder<Asserter<DartType>, InterfaceType> _isListOf;
11796 AsserterBuilder2<Asserter<DartType>, Asserter<DartType>, 11817 AsserterBuilder2<Asserter<DartType>, Asserter<DartType>, InterfaceType>
11797 InterfaceType> _isMapOf; 11818 _isMapOf;
11819 AsserterBuilder<List<Asserter<DartType>>, InterfaceType> _isStreamOf;
11820 AsserterBuilder<DartType, DartType> _isType;
11821
11822 AsserterBuilder<Element, DartType> _hasElement;
11823 AsserterBuilder<DartType, DartType> _sameElement;
11798 11824
11799 @override 11825 @override
11800 void setUp() { 11826 void setUp() {
11801 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); 11827 AnalysisOptionsImpl options = new AnalysisOptionsImpl();
11802 options.strongMode = true; 11828 options.strongMode = true;
11803 resetWithOptions(options); 11829 resetWithOptions(options);
11804 _assertions = new TypeAssertions(typeProvider); 11830 _assertions = new TypeAssertions(typeProvider);
11805 _isType = _assertions.isType; 11831 _isType = _assertions.isType;
11806 _hasElement = _assertions.hasElement; 11832 _hasElement = _assertions.hasElement;
11807 _isInstantiationOf = _assertions.isInstantiationOf; 11833 _isInstantiationOf = _assertions.isInstantiationOf;
11808 _isInt = _assertions.isInt; 11834 _isInt = _assertions.isInt;
11809 _isNum = _assertions.isNum; 11835 _isNum = _assertions.isNum;
11810 _isString = _assertions.isString; 11836 _isString = _assertions.isString;
11811 _isDynamic = _assertions.isDynamic; 11837 _isDynamic = _assertions.isDynamic;
11812 _isListOf = _assertions.isListOf; 11838 _isListOf = _assertions.isListOf;
11813 _isMapOf = _assertions.isMapOf; 11839 _isMapOf = _assertions.isMapOf;
11814 _isFunction2Of = _assertions.isFunction2Of; 11840 _isFunction2Of = _assertions.isFunction2Of;
11841 _sameElement = _assertions.sameElement;
11842 _isFutureOf = _isInstantiationOf(_sameElement(typeProvider.futureType));
11843 _isFutureOfDynamic = _isFutureOf([_isDynamic]);
11844 _isFutureOfInt = _isFutureOf([_isInt]);
11845 _isStreamOf = _isInstantiationOf(_sameElement(typeProvider.streamType));
11846 }
11847
11848 void test_async_method_propagation() {
11849 String code = r'''
11850 import "dart:async";
11851 class A {
11852 Future f0() => new Future.value(3);
11853 Future f1() async => new Future.value(3);
11854 Future f2() async => await new Future.value(3);
11855
11856 Future<int> f3() => new Future.value(3);
11857 Future<int> f4() async => new Future.value(3);
11858 Future<int> f5() async => await new Future.value(3);
11859
11860 Future g0() { return new Future.value(3); }
11861 Future g1() async { return new Future.value(3); }
11862 Future g2() async { return await new Future.value(3); }
11863
11864 Future<int> g3() { return new Future.value(3); }
11865 Future<int> g4() async { return new Future.value(3); }
11866 Future<int> g5() async { return await new Future.value(3); }
11867 }
11868 ''';
11869 CompilationUnit unit = resolveSource(code);
11870
11871 void check(String name, Asserter<InterfaceType> typeTest) {
11872 MethodDeclaration test = AstFinder.getMethodInClass(unit, "A", name);
11873 FunctionBody body = test.body;
11874 Expression returnExp;
11875 if (body is ExpressionFunctionBody) {
11876 returnExp = body.expression;
11877 } else {
11878 ReturnStatement stmt = (body as BlockFunctionBody).block.statements[0];
11879 returnExp = stmt.expression;
11880 }
11881 DartType type = returnExp.staticType;
11882 if (returnExp is AwaitExpression) {
11883 type = returnExp.expression.staticType;
11884 }
11885 typeTest(type);
11886 }
11887
11888 check("f0", _isFutureOfDynamic);
11889 check("f1", _isFutureOfDynamic);
11890 check("f2", _isFutureOfDynamic);
11891
11892 check("f3", _isFutureOfInt);
11893 // This should be int when we handle the implicit Future<T> | T union
11894 // https://github.com/dart-lang/sdk/issues/25322
11895 check("f4", _isFutureOfDynamic);
11896 check("f5", _isFutureOfInt);
11897
11898 check("g0", _isFutureOfDynamic);
11899 check("g1", _isFutureOfDynamic);
11900 check("g2", _isFutureOfDynamic);
11901
11902 check("g3", _isFutureOfInt);
11903 // This should be int when we handle the implicit Future<T> | T union
11904 // https://github.com/dart-lang/sdk/issues/25322
11905 check("g4", _isFutureOfDynamic);
11906 check("g5", _isFutureOfInt);
11907 }
11908
11909 void test_async_propagation() {
11910 String code = r'''
11911 import "dart:async";
11912
11913 Future f0() => new Future.value(3);
11914 Future f1() async => new Future.value(3);
11915 Future f2() async => await new Future.value(3);
11916
11917 Future<int> f3() => new Future.value(3);
11918 Future<int> f4() async => new Future.value(3);
11919 Future<int> f5() async => await new Future.value(3);
11920
11921 Future g0() { return new Future.value(3); }
11922 Future g1() async { return new Future.value(3); }
11923 Future g2() async { return await new Future.value(3); }
11924
11925 Future<int> g3() { return new Future.value(3); }
11926 Future<int> g4() async { return new Future.value(3); }
11927 Future<int> g5() async { return await new Future.value(3); }
11928 ''';
11929 CompilationUnit unit = resolveSource(code);
11930
11931 void check(String name, Asserter<InterfaceType> typeTest) {
11932 FunctionDeclaration test = AstFinder.getTopLevelFunction(unit, name);
11933 FunctionBody body = test.functionExpression.body;
11934 Expression returnExp;
11935 if (body is ExpressionFunctionBody) {
11936 returnExp = body.expression;
11937 } else {
11938 ReturnStatement stmt = (body as BlockFunctionBody).block.statements[0];
11939 returnExp = stmt.expression;
11940 }
11941 DartType type = returnExp.staticType;
11942 if (returnExp is AwaitExpression) {
11943 type = returnExp.expression.staticType;
11944 }
11945 typeTest(type);
11946 }
11947
11948 check("f0", _isFutureOfDynamic);
11949 check("f1", _isFutureOfDynamic);
11950 check("f2", _isFutureOfDynamic);
11951
11952 check("f3", _isFutureOfInt);
11953 // This should be int when we handle the implicit Future<T> | T union
11954 // https://github.com/dart-lang/sdk/issues/25322
11955 check("f4", _isFutureOfDynamic);
11956 check("f5", _isFutureOfInt);
11957
11958 check("g0", _isFutureOfDynamic);
11959 check("g1", _isFutureOfDynamic);
11960 check("g2", _isFutureOfDynamic);
11961
11962 check("g3", _isFutureOfInt);
11963 // This should be int when we handle the implicit Future<T> | T union
11964 // https://github.com/dart-lang/sdk/issues/25322
11965 check("g4", _isFutureOfDynamic);
11966 check("g5", _isFutureOfInt);
11967 }
11968
11969 void test_async_star_method_propagation() {
11970 String code = r'''
11971 import "dart:async";
11972 class A {
11973 Stream g0() async* { yield []; }
11974 Stream g1() async* { yield* new Stream(); }
11975
11976 Stream<List<int>> g2() async* { yield []; }
11977 Stream<List<int>> g3() async* { yield* new Stream(); }
11978 }
11979 ''';
11980 CompilationUnit unit = resolveSource(code);
11981
11982 void check(String name, Asserter<InterfaceType> typeTest) {
11983 MethodDeclaration test = AstFinder.getMethodInClass(unit, "A", name);
11984 BlockFunctionBody body = test.body;
11985 YieldStatement stmt = body.block.statements[0];
11986 Expression exp = stmt.expression;
11987 typeTest(exp.staticType);
11988 }
11989
11990 check("g0", _isListOf(_isDynamic));
11991 check("g1", _isStreamOf([_isDynamic]));
11992
11993 check("g2", _isListOf(_isInt));
11994 check("g3", _isStreamOf([_isListOf(_isInt)]));
11995 }
11996
11997 void test_async_star_propagation() {
11998 String code = r'''
11999 import "dart:async";
12000
12001 Stream g0() async* { yield []; }
12002 Stream g1() async* { yield* new Stream(); }
12003
12004 Stream<List<int>> g2() async* { yield []; }
12005 Stream<List<int>> g3() async* { yield* new Stream(); }
12006 ''';
12007 CompilationUnit unit = resolveSource(code);
12008
12009 void check(String name, Asserter<InterfaceType> typeTest) {
12010 FunctionDeclaration test = AstFinder.getTopLevelFunction(unit, name);
12011 BlockFunctionBody body = test.functionExpression.body;
12012 YieldStatement stmt = body.block.statements[0];
12013 Expression exp = stmt.expression;
12014 typeTest(exp.staticType);
12015 }
12016
12017 check("g0", _isListOf(_isDynamic));
12018 check("g1", _isStreamOf([_isDynamic]));
12019
12020 check("g2", _isListOf(_isInt));
12021 check("g3", _isStreamOf([_isListOf(_isInt)]));
11815 } 12022 }
11816 12023
11817 void test_cascadeExpression() { 12024 void test_cascadeExpression() {
11818 String code = r''' 12025 String code = r'''
11819 class A<T> { 12026 class A<T> {
11820 List<T> map(T a, List<T> mapper(T x)) => mapper(a); 12027 List<T> map(T a, List<T> mapper(T x)) => mapper(a);
11821 } 12028 }
11822 12029
11823 void main () { 12030 void main () {
11824 A<int> a = new A()..map(0, (x) => [x]); 12031 A<int> a = new A()..map(0, (x) => [x]);
(...skipping 919 matching lines...) Expand 10 before | Expand all | Expand 10 after
12744 } 12951 }
12745 '''; 12952 ''';
12746 CompilationUnit unit = resolveSource(code); 12953 CompilationUnit unit = resolveSource(code);
12747 12954
12748 ConstructorDeclaration constructor = 12955 ConstructorDeclaration constructor =
12749 AstFinder.getConstructorInClass(unit, "A", null); 12956 AstFinder.getConstructorInClass(unit, "A", null);
12750 SuperConstructorInvocation invocation = constructor.initializers[0]; 12957 SuperConstructorInvocation invocation = constructor.initializers[0];
12751 Expression exp = invocation.argumentList.arguments[0]; 12958 Expression exp = invocation.argumentList.arguments[0];
12752 _isListOf(_isString)(exp.staticType); 12959 _isListOf(_isString)(exp.staticType);
12753 } 12960 }
12961
12962 void test_sync_star_method_propagation() {
12963 String code = r'''
12964 import "dart:async";
12965 class A {
12966 Iterable f0() sync* { yield []; }
12967 Iterable f1() sync* { yield* new List(); }
12968
12969 Iterable<List<int>> f2() sync* { yield []; }
12970 Iterable<List<int>> f3() sync* { yield* new List(); }
12971 }
12972 ''';
12973 CompilationUnit unit = resolveSource(code);
12974
12975 void check(String name, Asserter<InterfaceType> typeTest) {
12976 MethodDeclaration test = AstFinder.getMethodInClass(unit, "A", name);
12977 BlockFunctionBody body = test.body;
12978 YieldStatement stmt = body.block.statements[0];
12979 Expression exp = stmt.expression;
12980 typeTest(exp.staticType);
12981 }
12982
12983 check("f0", _isListOf(_isDynamic));
12984 check("f1", _isListOf(_isDynamic));
12985
12986 check("f2", _isListOf(_isInt));
12987 check("f3", _isListOf(_isListOf(_isInt)));
12988 }
12989
12990 void test_sync_star_propagation() {
12991 String code = r'''
12992 import "dart:async";
12993
12994 Iterable f0() sync* { yield []; }
12995 Iterable f1() sync* { yield* new List(); }
12996
12997 Iterable<List<int>> f2() sync* { yield []; }
12998 Iterable<List<int>> f3() sync* { yield* new List(); }
12999 ''';
13000 CompilationUnit unit = resolveSource(code);
13001
13002 void check(String name, Asserter<InterfaceType> typeTest) {
13003 FunctionDeclaration test = AstFinder.getTopLevelFunction(unit, name);
13004 BlockFunctionBody body = test.functionExpression.body;
13005 YieldStatement stmt = body.block.statements[0];
13006 Expression exp = stmt.expression;
13007 typeTest(exp.staticType);
13008 }
13009
13010 check("f0", _isListOf(_isDynamic));
13011 check("f1", _isListOf(_isDynamic));
13012
13013 check("f2", _isListOf(_isInt));
13014 check("f3", _isListOf(_isListOf(_isInt)));
13015 }
12754 } 13016 }
12755 13017
12756 /** 13018 /**
12757 * Strong mode static analyzer end to end tests 13019 * Strong mode static analyzer end to end tests
12758 */ 13020 */
12759 @reflectiveTest 13021 @reflectiveTest
12760 class StrongModeStaticTypeAnalyzer2Test extends _StaticTypeAnalyzer2TestShared { 13022 class StrongModeStaticTypeAnalyzer2Test extends _StaticTypeAnalyzer2TestShared {
12761 void setUp() { 13023 void setUp() {
12762 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); 13024 AnalysisOptionsImpl options = new AnalysisOptionsImpl();
12763 options.strongMode = true; 13025 options.strongMode = true;
(...skipping 1254 matching lines...) Expand 10 before | Expand all | Expand 10 after
14018 import 'lib.dart'; 14280 import 'lib.dart';
14019 class B extends A { 14281 class B extends A {
14020 m() { 14282 m() {
14021 return v; // marker 14283 return v; // marker
14022 } 14284 }
14023 }'''; 14285 }''';
14024 _assertTypeOfMarkedExpression( 14286 _assertTypeOfMarkedExpression(
14025 code, typeProvider.dynamicType, typeProvider.intType); 14287 code, typeProvider.dynamicType, typeProvider.intType);
14026 } 14288 }
14027 14289
14028 void test_finalPropertyInducingVariable_classMember_instance_propagatedTarget( ) { 14290 void
14291 test_finalPropertyInducingVariable_classMember_instance_propagatedTarget() {
14029 addNamedSource( 14292 addNamedSource(
14030 "/lib.dart", 14293 "/lib.dart",
14031 r''' 14294 r'''
14032 class A { 14295 class A {
14033 final v = 0; 14296 final v = 0;
14034 }'''); 14297 }''');
14035 String code = r''' 14298 String code = r'''
14036 import 'lib.dart'; 14299 import 'lib.dart';
14037 f(p) { 14300 f(p) {
14038 if (p is A) { 14301 if (p is A) {
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
14237 FormalParameter kParameter = EngineTestCase.findNode( 14500 FormalParameter kParameter = EngineTestCase.findNode(
14238 unit, code, "k, ", (node) => node is SimpleFormalParameter); 14501 unit, code, "k, ", (node) => node is SimpleFormalParameter);
14239 expect(kParameter.identifier.propagatedType, same(intType)); 14502 expect(kParameter.identifier.propagatedType, same(intType));
14240 // v 14503 // v
14241 DartType stringType = typeProvider.stringType; 14504 DartType stringType = typeProvider.stringType;
14242 FormalParameter vParameter = EngineTestCase.findNode( 14505 FormalParameter vParameter = EngineTestCase.findNode(
14243 unit, code, "v)", (node) => node is SimpleFormalParameter); 14506 unit, code, "v)", (node) => node is SimpleFormalParameter);
14244 expect(vParameter.identifier.propagatedType, same(stringType)); 14507 expect(vParameter.identifier.propagatedType, same(stringType));
14245 } 14508 }
14246 14509
14247 void test_functionExpression_asInvocationArgument_functionExpressionInvocation () { 14510 void
14511 test_functionExpression_asInvocationArgument_functionExpressionInvocation( ) {
14248 String code = r''' 14512 String code = r'''
14249 main() { 14513 main() {
14250 (f(String value)) {} ((v) { 14514 (f(String value)) {} ((v) {
14251 v; 14515 v;
14252 }); 14516 });
14253 }'''; 14517 }''';
14254 Source source = addSource(code); 14518 Source source = addSource(code);
14255 LibraryElement library = resolve2(source); 14519 LibraryElement library = resolve2(source);
14256 assertNoErrors(source); 14520 assertNoErrors(source);
14257 verify([source]); 14521 verify([source]);
(...skipping 1857 matching lines...) Expand 10 before | Expand all | Expand 10 after
16115 16379
16116 void _resolveTestUnit(String code) { 16380 void _resolveTestUnit(String code) {
16117 testCode = code; 16381 testCode = code;
16118 testSource = addSource(testCode); 16382 testSource = addSource(testCode);
16119 LibraryElement library = resolve2(testSource); 16383 LibraryElement library = resolve2(testSource);
16120 assertNoErrors(testSource); 16384 assertNoErrors(testSource);
16121 verify([testSource]); 16385 verify([testSource]);
16122 testUnit = resolveCompilationUnit(testSource, library); 16386 testUnit = resolveCompilationUnit(testSource, library);
16123 } 16387 }
16124 } 16388 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/generated/resolver.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698