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

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: 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
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 2202 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 AsserterBuilder<Element, DartType> _hasElement;
11786 AsserterBuilder<DartType, DartType> _isType; 11804 AsserterBuilder<DartType, DartType> _isType;
11787 AsserterBuilder2<Asserter<DartType>, Asserter<DartType>, 11805 AsserterBuilder2<Asserter<DartType>, Asserter<DartType>, DartType>
11788 DartType> _isFunction2Of; 11806 _isFunction2Of;
11789 AsserterBuilderBuilder<Asserter<DartType>, List<Asserter<DartType>>, 11807 AsserterBuilderBuilder<Asserter<DartType>, List<Asserter<DartType>>, DartType>
11790 DartType> _isInstantiationOf; 11808 _isInstantiationOf;
11791 Asserter<DartType> _isInt; 11809 Asserter<DartType> _isInt;
11792 Asserter<DartType> _isNum; 11810 Asserter<DartType> _isNum;
11793 Asserter<DartType> _isString; 11811 Asserter<DartType> _isString;
11794 Asserter<DartType> _isDynamic; 11812 Asserter<DartType> _isDynamic;
11795 AsserterBuilder<Asserter<DartType>, InterfaceType> _isListOf; 11813 AsserterBuilder<Asserter<DartType>, InterfaceType> _isListOf;
11796 AsserterBuilder2<Asserter<DartType>, Asserter<DartType>, 11814 AsserterBuilder2<Asserter<DartType>, Asserter<DartType>, InterfaceType>
11797 InterfaceType> _isMapOf; 11815 _isMapOf;
11816 AsserterBuilder<DartType, DartType> _sameElement;
11798 11817
11799 @override 11818 @override
11800 void setUp() { 11819 void setUp() {
11801 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); 11820 AnalysisOptionsImpl options = new AnalysisOptionsImpl();
11802 options.strongMode = true; 11821 options.strongMode = true;
11803 resetWithOptions(options); 11822 resetWithOptions(options);
11804 _assertions = new TypeAssertions(typeProvider); 11823 _assertions = new TypeAssertions(typeProvider);
11805 _isType = _assertions.isType; 11824 _isType = _assertions.isType;
11806 _hasElement = _assertions.hasElement; 11825 _hasElement = _assertions.hasElement;
11807 _isInstantiationOf = _assertions.isInstantiationOf; 11826 _isInstantiationOf = _assertions.isInstantiationOf;
11808 _isInt = _assertions.isInt; 11827 _isInt = _assertions.isInt;
11809 _isNum = _assertions.isNum; 11828 _isNum = _assertions.isNum;
11810 _isString = _assertions.isString; 11829 _isString = _assertions.isString;
11811 _isDynamic = _assertions.isDynamic; 11830 _isDynamic = _assertions.isDynamic;
11812 _isListOf = _assertions.isListOf; 11831 _isListOf = _assertions.isListOf;
11813 _isMapOf = _assertions.isMapOf; 11832 _isMapOf = _assertions.isMapOf;
11814 _isFunction2Of = _assertions.isFunction2Of; 11833 _isFunction2Of = _assertions.isFunction2Of;
11834 _sameElement = _assertions.sameElement;
11835 }
11836
11837 void test_async_method_propagation() {
11838 String code = r'''
11839 import "dart:async";
11840 class A {
11841 Future f0() => new Future.value(3);
11842 Future f1() async => new Future.value(3);
11843 Future f2() async => await new Future.value(3);
11844
11845 Future<int> f3() => new Future.value(3);
11846 Future<int> f4() async => new Future.value(3);
11847 Future<int> f5() async => await new Future.value(3);
11848
11849 Future g0() { return new Future.value(3); }
11850 Future g1() async { return new Future.value(3); }
11851 Future g2() async { return await new Future.value(3); }
11852
11853 Future<int> g3() { return new Future.value(3); }
11854 Future<int> g4() async { return new Future.value(3); }
11855 Future<int> g5() async { return await new Future.value(3); }
11856 }
11857 ''';
11858 CompilationUnit unit = resolveSource(code);
11859
11860 void check(String name, Asserter<InterfaceType> typeTest) {
11861 MethodDeclaration test = AstFinder.getMethodInClass(unit, "A", name);
11862 FunctionBody body = test.body;
11863 Expression returnExp;
11864 if (body is ExpressionFunctionBody) {
11865 returnExp = body.expression;
11866 } else {
11867 ReturnStatement stmt = (body as BlockFunctionBody).block.statements[0];
11868 returnExp = stmt.expression;
11869 }
11870 DartType type = returnExp.staticType;
11871 if (returnExp is AwaitExpression) {
11872 type = returnExp.expression.staticType;
11873 }
11874 typeTest(type);
11875 }
11876
11877 AsserterBuilder<List<Asserter<DartType>>, InterfaceType> isFutureOf =
11878 _isInstantiationOf(_sameElement(typeProvider.futureType));
11879 Asserter<InterfaceType> assertFutureOfDynamic = isFutureOf([_isDynamic]);
11880 Asserter<InterfaceType> assertFutureOfInt = isFutureOf([_isInt]);
11881
11882 check("f0", assertFutureOfDynamic);
11883 check("f1", assertFutureOfDynamic);
11884 check("f2", assertFutureOfDynamic);
11885
11886 check("f3", assertFutureOfInt);
11887 // This should be int when we handle the implicit Future<T> | T union
Bob Nystrom 2015/12/30 01:03:39 File a tracking bug and link to it here?
Leaf 2015/12/30 18:28:06 https://github.com/dart-lang/sdk/issues/25322
11888 check("f4", assertFutureOfDynamic);
11889 check("f5", assertFutureOfInt);
11890
11891 check("g0", assertFutureOfDynamic);
11892 check("g1", assertFutureOfDynamic);
11893 check("g2", assertFutureOfDynamic);
11894
11895 check("g3", assertFutureOfInt);
11896 // This should be int when we handle the implicit Future<T> | T union
11897 check("g4", assertFutureOfDynamic);
11898 check("g5", assertFutureOfInt);
11899 }
11900
11901 void test_async_propagation() {
11902 String code = r'''
11903 import "dart:async";
11904
11905 Future f0() => new Future.value(3);
11906 Future f1() async => new Future.value(3);
11907 Future f2() async => await new Future.value(3);
11908
11909 Future<int> f3() => new Future.value(3);
11910 Future<int> f4() async => new Future.value(3);
11911 Future<int> f5() async => await new Future.value(3);
11912
11913 Future g0() { return new Future.value(3); }
11914 Future g1() async { return new Future.value(3); }
11915 Future g2() async { return await new Future.value(3); }
11916
11917 Future<int> g3() { return new Future.value(3); }
11918 Future<int> g4() async { return new Future.value(3); }
11919 Future<int> g5() async { return await new Future.value(3); }
11920 ''';
11921 CompilationUnit unit = resolveSource(code);
11922
11923 void check(String name, Asserter<InterfaceType> typeTest) {
11924 FunctionDeclaration test = AstFinder.getTopLevelFunction(unit, name);
11925 FunctionBody body = test.functionExpression.body;
11926 Expression returnExp;
11927 if (body is ExpressionFunctionBody) {
11928 returnExp = body.expression;
11929 } else {
11930 ReturnStatement stmt = (body as BlockFunctionBody).block.statements[0];
11931 returnExp = stmt.expression;
11932 }
11933 DartType type = returnExp.staticType;
11934 if (returnExp is AwaitExpression) {
11935 type = returnExp.expression.staticType;
11936 }
11937 typeTest(type);
11938 }
11939
11940 AsserterBuilder<List<Asserter<DartType>>, InterfaceType> isFutureOf =
11941 _isInstantiationOf(_sameElement(typeProvider.futureType));
11942 Asserter<InterfaceType> assertFutureOfDynamic = isFutureOf([_isDynamic]);
11943 Asserter<InterfaceType> assertFutureOfInt = isFutureOf([_isInt]);
Bob Nystrom 2015/12/30 01:03:39 You could hoist these variables up to the top leve
Leaf 2015/12/30 18:28:06 Done.
11944
11945 check("f0", assertFutureOfDynamic);
11946 check("f1", assertFutureOfDynamic);
11947 check("f2", assertFutureOfDynamic);
11948
11949 check("f3", assertFutureOfInt);
11950 // This should be int when we handle the implicit Future<T> | T union
11951 check("f4", assertFutureOfDynamic);
11952 check("f5", assertFutureOfInt);
11953
11954 check("g0", assertFutureOfDynamic);
11955 check("g1", assertFutureOfDynamic);
11956 check("g2", assertFutureOfDynamic);
11957
11958 check("g3", assertFutureOfInt);
11959 // This should be int when we handle the implicit Future<T> | T union
11960 check("g4", assertFutureOfDynamic);
11961 check("g5", assertFutureOfInt);
11962 }
11963
11964 void test_async_star_method_propagation() {
11965 String code = r'''
11966 import "dart:async";
11967 class A {
11968 Stream g0() async* { yield []; }
11969 Stream g1() async* { yield* new Stream(); }
11970
11971 Stream<List<int>> g2() async* { yield []; }
11972 Stream<List<int>> g3() async* { yield* new Stream(); }
11973 }
11974 ''';
11975 CompilationUnit unit = resolveSource(code);
11976
11977 void check(String name, Asserter<InterfaceType> typeTest) {
11978 MethodDeclaration test = AstFinder.getMethodInClass(unit, "A", name);
11979 BlockFunctionBody body = test.body;
11980 YieldStatement stmt = body.block.statements[0];
11981 Expression exp = stmt.expression;
11982 typeTest(exp.staticType);
11983 }
11984
11985 AsserterBuilder<List<Asserter<DartType>>, InterfaceType> isStreamOf =
11986 _isInstantiationOf(_sameElement(typeProvider.streamType));
11987
11988 check("g0", _isListOf(_isDynamic));
11989 check("g1", isStreamOf([_isDynamic]));
11990
11991 check("g2", _isListOf(_isInt));
11992 check("g3", isStreamOf([_isListOf(_isInt)]));
11993 }
11994
11995 void test_async_star_propagation() {
11996 String code = r'''
11997 import "dart:async";
11998
11999 Stream g0() async* { yield []; }
12000 Stream g1() async* { yield* new Stream(); }
12001
12002 Stream<List<int>> g2() async* { yield []; }
12003 Stream<List<int>> g3() async* { yield* new Stream(); }
12004 ''';
12005 CompilationUnit unit = resolveSource(code);
12006
12007 void check(String name, Asserter<InterfaceType> typeTest) {
12008 FunctionDeclaration test = AstFinder.getTopLevelFunction(unit, name);
12009 BlockFunctionBody body = test.functionExpression.body;
12010 YieldStatement stmt = body.block.statements[0];
12011 Expression exp = stmt.expression;
12012 typeTest(exp.staticType);
12013 }
12014
12015 AsserterBuilder<List<Asserter<DartType>>, InterfaceType> isStreamOf =
12016 _isInstantiationOf(_sameElement(typeProvider.streamType));
12017
12018 check("g0", _isListOf(_isDynamic));
12019 check("g1", isStreamOf([_isDynamic]));
12020
12021 check("g2", _isListOf(_isInt));
12022 check("g3", isStreamOf([_isListOf(_isInt)]));
11815 } 12023 }
11816 12024
11817 void test_cascadeExpression() { 12025 void test_cascadeExpression() {
11818 String code = r''' 12026 String code = r'''
11819 class A<T> { 12027 class A<T> {
11820 List<T> map(T a, List<T> mapper(T x)) => mapper(a); 12028 List<T> map(T a, List<T> mapper(T x)) => mapper(a);
11821 } 12029 }
11822 12030
11823 void main () { 12031 void main () {
11824 A<int> a = new A()..map(0, (x) => [x]); 12032 A<int> a = new A()..map(0, (x) => [x]);
(...skipping 919 matching lines...) Expand 10 before | Expand all | Expand 10 after
12744 } 12952 }
12745 '''; 12953 ''';
12746 CompilationUnit unit = resolveSource(code); 12954 CompilationUnit unit = resolveSource(code);
12747 12955
12748 ConstructorDeclaration constructor = 12956 ConstructorDeclaration constructor =
12749 AstFinder.getConstructorInClass(unit, "A", null); 12957 AstFinder.getConstructorInClass(unit, "A", null);
12750 SuperConstructorInvocation invocation = constructor.initializers[0]; 12958 SuperConstructorInvocation invocation = constructor.initializers[0];
12751 Expression exp = invocation.argumentList.arguments[0]; 12959 Expression exp = invocation.argumentList.arguments[0];
12752 _isListOf(_isString)(exp.staticType); 12960 _isListOf(_isString)(exp.staticType);
12753 } 12961 }
12962
12963 void test_sync_star_method_propagation() {
12964 String code = r'''
12965 import "dart:async";
12966 class A {
12967 Iterable f0() sync* { yield []; }
12968 Iterable f1() sync* { yield* new List(); }
12969
12970 Iterable<List<int>> f2() sync* { yield []; }
12971 Iterable<List<int>> f3() sync* { yield* new List(); }
12972 }
12973 ''';
12974 CompilationUnit unit = resolveSource(code);
12975
12976 void check(String name, Asserter<InterfaceType> typeTest) {
12977 MethodDeclaration test = AstFinder.getMethodInClass(unit, "A", name);
12978 BlockFunctionBody body = test.body;
12979 YieldStatement stmt = body.block.statements[0];
12980 Expression exp = stmt.expression;
12981 typeTest(exp.staticType);
12982 }
12983
12984 AsserterBuilder<List<Asserter<DartType>>, InterfaceType> isIterableOf =
12985 _isInstantiationOf(_sameElement(typeProvider.iterableType));
12986
12987 check("f0", _isListOf(_isDynamic));
12988 check("f1", _isListOf(_isDynamic));
12989
12990 check("f2", _isListOf(_isInt));
12991 check("f3", _isListOf(_isListOf(_isInt)));
12992 }
12993
12994 void test_sync_star_propagation() {
12995 String code = r'''
12996 import "dart:async";
12997
12998 Iterable f0() sync* { yield []; }
12999 Iterable f1() sync* { yield* new List(); }
13000
13001 Iterable<List<int>> f2() sync* { yield []; }
13002 Iterable<List<int>> f3() sync* { yield* new List(); }
13003 ''';
13004 CompilationUnit unit = resolveSource(code);
13005
13006 void check(String name, Asserter<InterfaceType> typeTest) {
13007 FunctionDeclaration test = AstFinder.getTopLevelFunction(unit, name);
13008 BlockFunctionBody body = test.functionExpression.body;
13009 YieldStatement stmt = body.block.statements[0];
13010 Expression exp = stmt.expression;
13011 typeTest(exp.staticType);
13012 }
13013
13014 AsserterBuilder<List<Asserter<DartType>>, InterfaceType> isIterableOf =
13015 _isInstantiationOf(_sameElement(typeProvider.iterableType));
13016
13017 check("f0", _isListOf(_isDynamic));
13018 check("f1", _isListOf(_isDynamic));
13019
13020 check("f2", _isListOf(_isInt));
13021 check("f3", _isListOf(_isListOf(_isInt)));
13022 }
12754 } 13023 }
12755 13024
12756 /** 13025 /**
12757 * Strong mode static analyzer end to end tests 13026 * Strong mode static analyzer end to end tests
12758 */ 13027 */
12759 @reflectiveTest 13028 @reflectiveTest
12760 class StrongModeStaticTypeAnalyzer2Test extends _StaticTypeAnalyzer2TestShared { 13029 class StrongModeStaticTypeAnalyzer2Test extends _StaticTypeAnalyzer2TestShared {
12761 void setUp() { 13030 void setUp() {
12762 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); 13031 AnalysisOptionsImpl options = new AnalysisOptionsImpl();
12763 options.strongMode = true; 13032 options.strongMode = true;
(...skipping 1254 matching lines...) Expand 10 before | Expand all | Expand 10 after
14018 import 'lib.dart'; 14287 import 'lib.dart';
14019 class B extends A { 14288 class B extends A {
14020 m() { 14289 m() {
14021 return v; // marker 14290 return v; // marker
14022 } 14291 }
14023 }'''; 14292 }''';
14024 _assertTypeOfMarkedExpression( 14293 _assertTypeOfMarkedExpression(
14025 code, typeProvider.dynamicType, typeProvider.intType); 14294 code, typeProvider.dynamicType, typeProvider.intType);
14026 } 14295 }
14027 14296
14028 void test_finalPropertyInducingVariable_classMember_instance_propagatedTarget( ) { 14297 void
14298 test_finalPropertyInducingVariable_classMember_instance_propagatedTarget() {
14029 addNamedSource( 14299 addNamedSource(
14030 "/lib.dart", 14300 "/lib.dart",
14031 r''' 14301 r'''
14032 class A { 14302 class A {
14033 final v = 0; 14303 final v = 0;
14034 }'''); 14304 }''');
14035 String code = r''' 14305 String code = r'''
14036 import 'lib.dart'; 14306 import 'lib.dart';
14037 f(p) { 14307 f(p) {
14038 if (p is A) { 14308 if (p is A) {
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
14237 FormalParameter kParameter = EngineTestCase.findNode( 14507 FormalParameter kParameter = EngineTestCase.findNode(
14238 unit, code, "k, ", (node) => node is SimpleFormalParameter); 14508 unit, code, "k, ", (node) => node is SimpleFormalParameter);
14239 expect(kParameter.identifier.propagatedType, same(intType)); 14509 expect(kParameter.identifier.propagatedType, same(intType));
14240 // v 14510 // v
14241 DartType stringType = typeProvider.stringType; 14511 DartType stringType = typeProvider.stringType;
14242 FormalParameter vParameter = EngineTestCase.findNode( 14512 FormalParameter vParameter = EngineTestCase.findNode(
14243 unit, code, "v)", (node) => node is SimpleFormalParameter); 14513 unit, code, "v)", (node) => node is SimpleFormalParameter);
14244 expect(vParameter.identifier.propagatedType, same(stringType)); 14514 expect(vParameter.identifier.propagatedType, same(stringType));
14245 } 14515 }
14246 14516
14247 void test_functionExpression_asInvocationArgument_functionExpressionInvocation () { 14517 void
14518 test_functionExpression_asInvocationArgument_functionExpressionInvocation( ) {
14248 String code = r''' 14519 String code = r'''
14249 main() { 14520 main() {
14250 (f(String value)) {} ((v) { 14521 (f(String value)) {} ((v) {
14251 v; 14522 v;
14252 }); 14523 });
14253 }'''; 14524 }''';
14254 Source source = addSource(code); 14525 Source source = addSource(code);
14255 LibraryElement library = resolve2(source); 14526 LibraryElement library = resolve2(source);
14256 assertNoErrors(source); 14527 assertNoErrors(source);
14257 verify([source]); 14528 verify([source]);
(...skipping 1857 matching lines...) Expand 10 before | Expand all | Expand 10 after
16115 16386
16116 void _resolveTestUnit(String code) { 16387 void _resolveTestUnit(String code) {
16117 testCode = code; 16388 testCode = code;
16118 testSource = addSource(testCode); 16389 testSource = addSource(testCode);
16119 LibraryElement library = resolve2(testSource); 16390 LibraryElement library = resolve2(testSource);
16120 assertNoErrors(testSource); 16391 assertNoErrors(testSource);
16121 verify([testSource]); 16392 verify([testSource]);
16122 testUnit = resolveCompilationUnit(testSource, library); 16393 testUnit = resolveCompilationUnit(testSource, library);
16123 } 16394 }
16124 } 16395 }
OLDNEW
« pkg/analyzer/lib/src/generated/resolver.dart ('K') | « 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