OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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.strong_mode_test; | 5 library analyzer.test.generated.strong_mode_test; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 | 8 |
9 import 'package:analyzer/dart/ast/ast.dart'; | 9 import 'package:analyzer/dart/ast/ast.dart'; |
10 import 'package:analyzer/dart/ast/standard_resolution_map.dart'; | 10 import 'package:analyzer/dart/ast/standard_resolution_map.dart'; |
(...skipping 1234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1245 test_futureOr_methods1() async { | 1245 test_futureOr_methods1() async { |
1246 // Test that FutureOr has the Object methods | 1246 // Test that FutureOr has the Object methods |
1247 MethodInvocation invoke = await _testFutureOr(r''' | 1247 MethodInvocation invoke = await _testFutureOr(r''' |
1248 dynamic test(FutureOr<int> x) => x.toString(); | 1248 dynamic test(FutureOr<int> x) => x.toString(); |
1249 '''); | 1249 '''); |
1250 _isString(invoke.staticType); | 1250 _isString(invoke.staticType); |
1251 } | 1251 } |
1252 | 1252 |
1253 test_futureOr_methods2() async { | 1253 test_futureOr_methods2() async { |
1254 // Test that FutureOr does not have the constituent type methods | 1254 // Test that FutureOr does not have the constituent type methods |
1255 MethodInvocation invoke = await _testFutureOr( | 1255 MethodInvocation invoke = await _testFutureOr(r''' |
1256 r''' | |
1257 dynamic test(FutureOr<int> x) => x.abs(); | 1256 dynamic test(FutureOr<int> x) => x.abs(); |
1258 ''', | 1257 ''', errors: [StaticTypeWarningCode.UNDEFINED_METHOD]); |
1259 errors: [StaticTypeWarningCode.UNDEFINED_METHOD]); | |
1260 _isDynamic(invoke.staticType); | 1258 _isDynamic(invoke.staticType); |
1261 } | 1259 } |
1262 | 1260 |
1263 test_futureOr_methods3() async { | 1261 test_futureOr_methods3() async { |
1264 // Test that FutureOr does not have the Future type methods | 1262 // Test that FutureOr does not have the Future type methods |
1265 MethodInvocation invoke = await _testFutureOr( | 1263 MethodInvocation invoke = await _testFutureOr(r''' |
1266 r''' | |
1267 dynamic test(FutureOr<int> x) => x.then((x) => x); | 1264 dynamic test(FutureOr<int> x) => x.then((x) => x); |
1268 ''', | 1265 ''', errors: [StaticTypeWarningCode.UNDEFINED_METHOD]); |
1269 errors: [StaticTypeWarningCode.UNDEFINED_METHOD]); | |
1270 _isDynamic(invoke.staticType); | 1266 _isDynamic(invoke.staticType); |
1271 } | 1267 } |
1272 | 1268 |
1273 test_futureOr_methods4() async { | 1269 test_futureOr_methods4() async { |
1274 // Test that FutureOr<dynamic> does not have all methods | 1270 // Test that FutureOr<dynamic> does not have all methods |
1275 MethodInvocation invoke = await _testFutureOr( | 1271 MethodInvocation invoke = await _testFutureOr(r''' |
1276 r''' | |
1277 dynamic test(FutureOr<dynamic> x) => x.abs(); | 1272 dynamic test(FutureOr<dynamic> x) => x.abs(); |
1278 ''', | 1273 ''', errors: [StaticTypeWarningCode.UNDEFINED_METHOD]); |
1279 errors: [StaticTypeWarningCode.UNDEFINED_METHOD]); | |
1280 _isDynamic(invoke.staticType); | 1274 _isDynamic(invoke.staticType); |
1281 } | 1275 } |
1282 | 1276 |
1283 test_futureOr_no_return() async { | 1277 test_futureOr_no_return() async { |
1284 MethodInvocation invoke = await _testFutureOr(r''' | 1278 MethodInvocation invoke = await _testFutureOr(r''' |
1285 FutureOr<T> mk<T>(Future<T> x) => x; | 1279 FutureOr<T> mk<T>(Future<T> x) => x; |
1286 Future<int> f; | 1280 Future<int> f; |
1287 test() => f.then((int x) {}); | 1281 test() => f.then((int x) {}); |
1288 '''); | 1282 '''); |
1289 _isFunction2Of(_isInt, _isNull)( | 1283 _isFunction2Of(_isInt, _isNull)( |
(...skipping 29 matching lines...) Expand all Loading... |
1319 MethodInvocation invoke = await _testFutureOr(r''' | 1313 MethodInvocation invoke = await _testFutureOr(r''' |
1320 Future<T> mk<T>(FutureOr<T> x) => null; | 1314 Future<T> mk<T>(FutureOr<T> x) => null; |
1321 dynamic test() => mk(new Future<int>.value(42)); | 1315 dynamic test() => mk(new Future<int>.value(42)); |
1322 '''); | 1316 '''); |
1323 _isFutureOfInt(invoke.staticType); | 1317 _isFutureOfInt(invoke.staticType); |
1324 } | 1318 } |
1325 | 1319 |
1326 test_futureOr_upwards2() async { | 1320 test_futureOr_upwards2() async { |
1327 // Test that upwards inference fails when the solution doesn't | 1321 // Test that upwards inference fails when the solution doesn't |
1328 // match the bound. | 1322 // match the bound. |
1329 MethodInvocation invoke = await _testFutureOr( | 1323 MethodInvocation invoke = await _testFutureOr(r''' |
1330 r''' | |
1331 Future<T> mk<T extends Future<Object>>(FutureOr<T> x) => null; | 1324 Future<T> mk<T extends Future<Object>>(FutureOr<T> x) => null; |
1332 dynamic test() => mk(new Future<int>.value(42)); | 1325 dynamic test() => mk(new Future<int>.value(42)); |
1333 ''', | 1326 ''', errors: [StrongModeCode.COULD_NOT_INFER]); |
1334 errors: [StrongModeCode.COULD_NOT_INFER]); | |
1335 _isFutureOfInt(invoke.staticType); | 1327 _isFutureOfInt(invoke.staticType); |
1336 } | 1328 } |
1337 | 1329 |
1338 test_futureOrNull_no_return() async { | 1330 test_futureOrNull_no_return() async { |
1339 MethodInvocation invoke = await _testFutureOr(r''' | 1331 MethodInvocation invoke = await _testFutureOr(r''' |
1340 FutureOr<T> mk<T>(Future<T> x) => x; | 1332 FutureOr<T> mk<T>(Future<T> x) => x; |
1341 Future<int> f; | 1333 Future<int> f; |
1342 test() => f.then<Null>((int x) {}); | 1334 test() => f.then<Null>((int x) {}); |
1343 '''); | 1335 '''); |
1344 _isFunction2Of(_isInt, _isNull)( | 1336 _isFunction2Of(_isInt, _isNull)( |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1433 Source source = addSource(r''' | 1425 Source source = addSource(r''' |
1434 typedef R F<T, R>(T t); | 1426 typedef R F<T, R>(T t); |
1435 | 1427 |
1436 F<T, T> g<T>(F<T, T> f) => (x) => f(f(x)); | 1428 F<T, T> g<T>(F<T, T> f) => (x) => f(f(x)); |
1437 | 1429 |
1438 test() { | 1430 test() { |
1439 var h = g((int x) => 42.0); | 1431 var h = g((int x) => 42.0); |
1440 } | 1432 } |
1441 '''); | 1433 '''); |
1442 await computeAnalysisResult(source); | 1434 await computeAnalysisResult(source); |
1443 _expectInferenceError( | 1435 _expectInferenceError(source, [ |
1444 source, | 1436 StrongModeCode.COULD_NOT_INFER, |
1445 [ | 1437 StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE |
1446 StrongModeCode.COULD_NOT_INFER, | 1438 ], r''' |
1447 StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE | |
1448 ], | |
1449 r''' | |
1450 Couldn't infer type parameter 'T'. | 1439 Couldn't infer type parameter 'T'. |
1451 | 1440 |
1452 Tried to infer 'double' for 'T' which doesn't work: | 1441 Tried to infer 'double' for 'T' which doesn't work: |
1453 Parameter 'f' declared as '(T) → T' | 1442 Parameter 'f' declared as '(T) → T' |
1454 but argument is '(int) → double'. | 1443 but argument is '(int) → double'. |
1455 | 1444 |
1456 Consider passing explicit type argument(s) to the generic. | 1445 Consider passing explicit type argument(s) to the generic. |
1457 | 1446 |
1458 '''); | 1447 '''); |
1459 } | 1448 } |
1460 | 1449 |
1461 test_inference_error_arguments2() async { | 1450 test_inference_error_arguments2() async { |
1462 Source source = addSource(r''' | 1451 Source source = addSource(r''' |
1463 typedef R F<T, R>(T t); | 1452 typedef R F<T, R>(T t); |
1464 | 1453 |
1465 F<T, T> g<T>(F<T, T> a, F<T, T> b) => (x) => a(b(x)); | 1454 F<T, T> g<T>(F<T, T> a, F<T, T> b) => (x) => a(b(x)); |
1466 | 1455 |
1467 test() { | 1456 test() { |
1468 var h = g((int x) => 42.0, (double x) => 42); | 1457 var h = g((int x) => 42.0, (double x) => 42); |
1469 } | 1458 } |
1470 '''); | 1459 '''); |
1471 await computeAnalysisResult(source); | 1460 await computeAnalysisResult(source); |
1472 _expectInferenceError( | 1461 _expectInferenceError(source, [ |
1473 source, | 1462 StrongModeCode.COULD_NOT_INFER, |
1474 [ | 1463 StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, |
1475 StrongModeCode.COULD_NOT_INFER, | 1464 StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE |
1476 StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, | 1465 ], r''' |
1477 StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE | |
1478 ], | |
1479 r''' | |
1480 Couldn't infer type parameter 'T'. | 1466 Couldn't infer type parameter 'T'. |
1481 | 1467 |
1482 Tried to infer 'num' for 'T' which doesn't work: | 1468 Tried to infer 'num' for 'T' which doesn't work: |
1483 Parameter 'a' declared as '(T) → T' | 1469 Parameter 'a' declared as '(T) → T' |
1484 but argument is '(int) → double'. | 1470 but argument is '(int) → double'. |
1485 Parameter 'b' declared as '(T) → T' | 1471 Parameter 'b' declared as '(T) → T' |
1486 but argument is '(double) → int'. | 1472 but argument is '(double) → int'. |
1487 | 1473 |
1488 Consider passing explicit type argument(s) to the generic. | 1474 Consider passing explicit type argument(s) to the generic. |
1489 | 1475 |
(...skipping 26 matching lines...) Expand all Loading... |
1516 test_inference_error_extendsFromReturn2() async { | 1502 test_inference_error_extendsFromReturn2() async { |
1517 Source source = addSource(r''' | 1503 Source source = addSource(r''' |
1518 typedef R F<T, R>(T t); | 1504 typedef R F<T, R>(T t); |
1519 F<T, T> g<T extends num>() => (y) => y; | 1505 F<T, T> g<T extends num>() => (y) => y; |
1520 | 1506 |
1521 test() { | 1507 test() { |
1522 F<String, String> hello = g(); | 1508 F<String, String> hello = g(); |
1523 } | 1509 } |
1524 '''); | 1510 '''); |
1525 await computeAnalysisResult(source); | 1511 await computeAnalysisResult(source); |
1526 _expectInferenceError( | 1512 _expectInferenceError(source, [ |
1527 source, | 1513 StrongModeCode.COULD_NOT_INFER, |
1528 [ | 1514 ], r''' |
1529 StrongModeCode.COULD_NOT_INFER, | |
1530 ], | |
1531 r''' | |
1532 Couldn't infer type parameter 'T'. | 1515 Couldn't infer type parameter 'T'. |
1533 | 1516 |
1534 Tried to infer 'String' for 'T' which doesn't work: | 1517 Tried to infer 'String' for 'T' which doesn't work: |
1535 Type parameter 'T' declared to extend 'num'. | 1518 Type parameter 'T' declared to extend 'num'. |
1536 The type 'String' was inferred from: | 1519 The type 'String' was inferred from: |
1537 Return type declared as '(T) → T' | 1520 Return type declared as '(T) → T' |
1538 used where '(String) → String' is required. | 1521 used where '(String) → String' is required. |
1539 | 1522 |
1540 Consider passing explicit type argument(s) to the generic. | 1523 Consider passing explicit type argument(s) to the generic. |
1541 | 1524 |
1542 '''); | 1525 '''); |
1543 } | 1526 } |
1544 | 1527 |
1545 test_inference_error_genericFunction() async { | 1528 test_inference_error_genericFunction() async { |
1546 Source source = addSource(r''' | 1529 Source source = addSource(r''' |
1547 T max<T extends num>(T x, T y) => x < y ? y : x; | 1530 T max<T extends num>(T x, T y) => x < y ? y : x; |
1548 abstract class Iterable<T> { | 1531 abstract class Iterable<T> { |
1549 T get first; | 1532 T get first; |
1550 S fold<S>(S s, S f(S s, T t)); | 1533 S fold<S>(S s, S f(S s, T t)); |
1551 } | 1534 } |
1552 test(Iterable values) { | 1535 test(Iterable values) { |
1553 num n = values.fold(values.first as num, max); | 1536 num n = values.fold(values.first as num, max); |
1554 } | 1537 } |
1555 '''); | 1538 '''); |
1556 await computeAnalysisResult(source); | 1539 await computeAnalysisResult(source); |
1557 _expectInferenceError( | 1540 _expectInferenceError(source, [ |
1558 source, | 1541 StrongModeCode.COULD_NOT_INFER, |
1559 [ | 1542 StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE |
1560 StrongModeCode.COULD_NOT_INFER, | 1543 ], r''' |
1561 StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE | |
1562 ], | |
1563 r''' | |
1564 Couldn't infer type parameter 'T'. | 1544 Couldn't infer type parameter 'T'. |
1565 | 1545 |
1566 Tried to infer 'dynamic' for 'T' which doesn't work: | 1546 Tried to infer 'dynamic' for 'T' which doesn't work: |
1567 Function type declared as '<T extends num>(T, T) → T' | 1547 Function type declared as '<T extends num>(T, T) → T' |
1568 used where '(num, dynamic) → num' is required. | 1548 used where '(num, dynamic) → num' is required. |
1569 | 1549 |
1570 Consider passing explicit type argument(s) to the generic. | 1550 Consider passing explicit type argument(s) to the generic. |
1571 | 1551 |
1572 '''); | 1552 '''); |
1573 } | 1553 } |
1574 | 1554 |
1575 test_inference_error_returnContext() async { | 1555 test_inference_error_returnContext() async { |
1576 Source source = addSource(r''' | 1556 Source source = addSource(r''' |
1577 typedef R F<T, R>(T t); | 1557 typedef R F<T, R>(T t); |
1578 | 1558 |
1579 F<T, T> g<T>(T t) => (x) => t; | 1559 F<T, T> g<T>(T t) => (x) => t; |
1580 | 1560 |
1581 test() { | 1561 test() { |
1582 F<num, int> h = g(42); | 1562 F<num, int> h = g(42); |
1583 } | 1563 } |
1584 '''); | 1564 '''); |
1585 await computeAnalysisResult(source); | 1565 await computeAnalysisResult(source); |
1586 _expectInferenceError( | 1566 _expectInferenceError(source, [StrongModeCode.COULD_NOT_INFER], r''' |
1587 source, | |
1588 [StrongModeCode.COULD_NOT_INFER], | |
1589 r''' | |
1590 Couldn't infer type parameter 'T'. | 1567 Couldn't infer type parameter 'T'. |
1591 | 1568 |
1592 Tried to infer 'num' for 'T' which doesn't work: | 1569 Tried to infer 'num' for 'T' which doesn't work: |
1593 Return type declared as '(T) → T' | 1570 Return type declared as '(T) → T' |
1594 used where '(num) → int' is required. | 1571 used where '(num) → int' is required. |
1595 | 1572 |
1596 Consider passing explicit type argument(s) to the generic. | 1573 Consider passing explicit type argument(s) to the generic. |
1597 | 1574 |
1598 '''); | 1575 '''); |
1599 } | 1576 } |
(...skipping 1202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2802 expect(ft.toString(), '(String) → String'); | 2779 expect(ft.toString(), '(String) → String'); |
2803 } | 2780 } |
2804 | 2781 |
2805 test_genericFunction_bounds() async { | 2782 test_genericFunction_bounds() async { |
2806 await resolveTestUnit(r'/*=T*/ f/*<T extends num>*/(/*=T*/ x) => null;'); | 2783 await resolveTestUnit(r'/*=T*/ f/*<T extends num>*/(/*=T*/ x) => null;'); |
2807 expectFunctionType('f', '<T extends num>(T) → T', | 2784 expectFunctionType('f', '<T extends num>(T) → T', |
2808 elementTypeParams: '[T extends num]', typeFormals: '[T extends num]'); | 2785 elementTypeParams: '[T extends num]', typeFormals: '[T extends num]'); |
2809 } | 2786 } |
2810 | 2787 |
2811 test_genericFunction_parameter() async { | 2788 test_genericFunction_parameter() async { |
2812 await resolveTestUnit( | 2789 await resolveTestUnit(r''' |
2813 r''' | |
2814 void g(/*=T*/ f/*<T>*/(/*=T*/ x)) {} | 2790 void g(/*=T*/ f/*<T>*/(/*=T*/ x)) {} |
2815 ''', | 2791 ''', noErrors: false // TODO(paulberry): remove when dartbug.com/28515 fixed. |
2816 noErrors: false // TODO(paulberry): remove when dartbug.com/28515 fixed. | |
2817 ); | 2792 ); |
2818 expectFunctionType('f', '<T>(T) → T', | 2793 expectFunctionType('f', '<T>(T) → T', |
2819 elementTypeParams: '[T]', typeFormals: '[T]'); | 2794 elementTypeParams: '[T]', typeFormals: '[T]'); |
2820 SimpleIdentifier f = findIdentifier('f'); | 2795 SimpleIdentifier f = findIdentifier('f'); |
2821 ParameterElementImpl e = f.staticElement; | 2796 ParameterElementImpl e = f.staticElement; |
2822 FunctionType type = e.type; | 2797 FunctionType type = e.type; |
2823 FunctionType ft = type.instantiate([typeProvider.stringType]); | 2798 FunctionType ft = type.instantiate([typeProvider.stringType]); |
2824 expect(ft.toString(), '(String) → String'); | 2799 expect(ft.toString(), '(String) → String'); |
2825 } | 2800 } |
2826 | 2801 |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2943 FunctionType ft = f.staticInvokeType; | 2918 FunctionType ft = f.staticInvokeType; |
2944 expect(ft.toString(), '(String) → List<int>'); | 2919 expect(ft.toString(), '(String) → List<int>'); |
2945 expect('${ft.typeArguments}/${ft.typeParameters}', '[String, int]/[E, T]'); | 2920 expect('${ft.typeArguments}/${ft.typeParameters}', '[String, int]/[E, T]'); |
2946 | 2921 |
2947 SimpleIdentifier x = findIdentifier('x'); | 2922 SimpleIdentifier x = findIdentifier('x'); |
2948 expect(x.staticType, | 2923 expect(x.staticType, |
2949 typeProvider.listType.instantiate([typeProvider.intType])); | 2924 typeProvider.listType.instantiate([typeProvider.intType])); |
2950 } | 2925 } |
2951 | 2926 |
2952 test_genericMethod_functionExpressionInvocation_explicit() async { | 2927 test_genericMethod_functionExpressionInvocation_explicit() async { |
2953 await resolveTestUnit( | 2928 await resolveTestUnit(r''' |
2954 r''' | |
2955 class C<E> { | 2929 class C<E> { |
2956 /*=T*/ f/*<T>*/(/*=T*/ e) => null; | 2930 /*=T*/ f/*<T>*/(/*=T*/ e) => null; |
2957 static /*=T*/ g/*<T>*/(/*=T*/ e) => null; | 2931 static /*=T*/ g/*<T>*/(/*=T*/ e) => null; |
2958 static final h = g; | 2932 static final h = g; |
2959 } | 2933 } |
2960 | 2934 |
2961 /*=T*/ topF/*<T>*/(/*=T*/ e) => null; | 2935 /*=T*/ topF/*<T>*/(/*=T*/ e) => null; |
2962 var topG = topF; | 2936 var topG = topF; |
2963 void test/*<S>*/(/*=T*/ pf/*<T>*/(/*=T*/ e)) { | 2937 void test/*<S>*/(/*=T*/ pf/*<T>*/(/*=T*/ e)) { |
2964 var c = new C<int>(); | 2938 var c = new C<int>(); |
2965 /*=T*/ lf/*<T>*/(/*=T*/ e) => null; | 2939 /*=T*/ lf/*<T>*/(/*=T*/ e) => null; |
2966 | 2940 |
2967 var lambdaCall = (/*<E>*/(/*=E*/ e) => e)/*<int>*/(3); | 2941 var lambdaCall = (/*<E>*/(/*=E*/ e) => e)/*<int>*/(3); |
2968 var methodCall = (c.f)/*<int>*/(3); | 2942 var methodCall = (c.f)/*<int>*/(3); |
2969 var staticCall = (C.g)/*<int>*/(3); | 2943 var staticCall = (C.g)/*<int>*/(3); |
2970 var staticFieldCall = (C.h)/*<int>*/(3); | 2944 var staticFieldCall = (C.h)/*<int>*/(3); |
2971 var topFunCall = (topF)/*<int>*/(3); | 2945 var topFunCall = (topF)/*<int>*/(3); |
2972 var topFieldCall = (topG)/*<int>*/(3); | 2946 var topFieldCall = (topG)/*<int>*/(3); |
2973 var localCall = (lf)/*<int>*/(3); | 2947 var localCall = (lf)/*<int>*/(3); |
2974 var paramCall = (pf)/*<int>*/(3); | 2948 var paramCall = (pf)/*<int>*/(3); |
2975 } | 2949 } |
2976 ''', | 2950 ''', noErrors: false // TODO(paulberry): remove when dartbug.com/28515 fixed. |
2977 noErrors: false // TODO(paulberry): remove when dartbug.com/28515 fixed. | |
2978 ); | 2951 ); |
2979 expectIdentifierType('methodCall', "int"); | 2952 expectIdentifierType('methodCall', "int"); |
2980 expectIdentifierType('staticCall', "int"); | 2953 expectIdentifierType('staticCall', "int"); |
2981 expectIdentifierType('staticFieldCall', "int"); | 2954 expectIdentifierType('staticFieldCall', "int"); |
2982 expectIdentifierType('topFunCall', "int"); | 2955 expectIdentifierType('topFunCall', "int"); |
2983 expectIdentifierType('topFieldCall', "int"); | 2956 expectIdentifierType('topFieldCall', "int"); |
2984 expectIdentifierType('localCall', "int"); | 2957 expectIdentifierType('localCall', "int"); |
2985 expectIdentifierType('paramCall', "int"); | 2958 expectIdentifierType('paramCall', "int"); |
2986 expectIdentifierType('lambdaCall', "int"); | 2959 expectIdentifierType('lambdaCall', "int"); |
2987 } | 2960 } |
2988 | 2961 |
2989 test_genericMethod_functionExpressionInvocation_inferred() async { | 2962 test_genericMethod_functionExpressionInvocation_inferred() async { |
2990 await resolveTestUnit( | 2963 await resolveTestUnit(r''' |
2991 r''' | |
2992 class C<E> { | 2964 class C<E> { |
2993 /*=T*/ f/*<T>*/(/*=T*/ e) => null; | 2965 /*=T*/ f/*<T>*/(/*=T*/ e) => null; |
2994 static /*=T*/ g/*<T>*/(/*=T*/ e) => null; | 2966 static /*=T*/ g/*<T>*/(/*=T*/ e) => null; |
2995 static final h = g; | 2967 static final h = g; |
2996 } | 2968 } |
2997 | 2969 |
2998 /*=T*/ topF/*<T>*/(/*=T*/ e) => null; | 2970 /*=T*/ topF/*<T>*/(/*=T*/ e) => null; |
2999 var topG = topF; | 2971 var topG = topF; |
3000 void test/*<S>*/(/*=T*/ pf/*<T>*/(/*=T*/ e)) { | 2972 void test/*<S>*/(/*=T*/ pf/*<T>*/(/*=T*/ e)) { |
3001 var c = new C<int>(); | 2973 var c = new C<int>(); |
3002 /*=T*/ lf/*<T>*/(/*=T*/ e) => null; | 2974 /*=T*/ lf/*<T>*/(/*=T*/ e) => null; |
3003 | 2975 |
3004 var lambdaCall = (/*<E>*/(/*=E*/ e) => e)(3); | 2976 var lambdaCall = (/*<E>*/(/*=E*/ e) => e)(3); |
3005 var methodCall = (c.f)(3); | 2977 var methodCall = (c.f)(3); |
3006 var staticCall = (C.g)(3); | 2978 var staticCall = (C.g)(3); |
3007 var staticFieldCall = (C.h)(3); | 2979 var staticFieldCall = (C.h)(3); |
3008 var topFunCall = (topF)(3); | 2980 var topFunCall = (topF)(3); |
3009 var topFieldCall = (topG)(3); | 2981 var topFieldCall = (topG)(3); |
3010 var localCall = (lf)(3); | 2982 var localCall = (lf)(3); |
3011 var paramCall = (pf)(3); | 2983 var paramCall = (pf)(3); |
3012 } | 2984 } |
3013 ''', | 2985 ''', noErrors: false // TODO(paulberry): remove when dartbug.com/28515 fixed. |
3014 noErrors: false // TODO(paulberry): remove when dartbug.com/28515 fixed. | |
3015 ); | 2986 ); |
3016 expectIdentifierType('methodCall', "int"); | 2987 expectIdentifierType('methodCall', "int"); |
3017 expectIdentifierType('staticCall', "int"); | 2988 expectIdentifierType('staticCall', "int"); |
3018 expectIdentifierType('staticFieldCall', "int"); | 2989 expectIdentifierType('staticFieldCall', "int"); |
3019 expectIdentifierType('topFunCall', "int"); | 2990 expectIdentifierType('topFunCall', "int"); |
3020 expectIdentifierType('topFieldCall', "int"); | 2991 expectIdentifierType('topFieldCall', "int"); |
3021 expectIdentifierType('localCall', "int"); | 2992 expectIdentifierType('localCall', "int"); |
3022 expectIdentifierType('paramCall', "int"); | 2993 expectIdentifierType('paramCall', "int"); |
3023 expectIdentifierType('lambdaCall', "int"); | 2994 expectIdentifierType('lambdaCall', "int"); |
3024 } | 2995 } |
3025 | 2996 |
3026 test_genericMethod_functionInvocation_explicit() async { | 2997 test_genericMethod_functionInvocation_explicit() async { |
3027 await resolveTestUnit( | 2998 await resolveTestUnit(r''' |
3028 r''' | |
3029 class C<E> { | 2999 class C<E> { |
3030 /*=T*/ f/*<T>*/(/*=T*/ e) => null; | 3000 /*=T*/ f/*<T>*/(/*=T*/ e) => null; |
3031 static /*=T*/ g/*<T>*/(/*=T*/ e) => null; | 3001 static /*=T*/ g/*<T>*/(/*=T*/ e) => null; |
3032 static final h = g; | 3002 static final h = g; |
3033 } | 3003 } |
3034 | 3004 |
3035 /*=T*/ topF/*<T>*/(/*=T*/ e) => null; | 3005 /*=T*/ topF/*<T>*/(/*=T*/ e) => null; |
3036 var topG = topF; | 3006 var topG = topF; |
3037 void test/*<S>*/(/*=T*/ pf/*<T>*/(/*=T*/ e)) { | 3007 void test/*<S>*/(/*=T*/ pf/*<T>*/(/*=T*/ e)) { |
3038 var c = new C<int>(); | 3008 var c = new C<int>(); |
3039 /*=T*/ lf/*<T>*/(/*=T*/ e) => null; | 3009 /*=T*/ lf/*<T>*/(/*=T*/ e) => null; |
3040 var methodCall = c.f/*<int>*/(3); | 3010 var methodCall = c.f/*<int>*/(3); |
3041 var staticCall = C.g/*<int>*/(3); | 3011 var staticCall = C.g/*<int>*/(3); |
3042 var staticFieldCall = C.h/*<int>*/(3); | 3012 var staticFieldCall = C.h/*<int>*/(3); |
3043 var topFunCall = topF/*<int>*/(3); | 3013 var topFunCall = topF/*<int>*/(3); |
3044 var topFieldCall = topG/*<int>*/(3); | 3014 var topFieldCall = topG/*<int>*/(3); |
3045 var localCall = lf/*<int>*/(3); | 3015 var localCall = lf/*<int>*/(3); |
3046 var paramCall = pf/*<int>*/(3); | 3016 var paramCall = pf/*<int>*/(3); |
3047 } | 3017 } |
3048 ''', | 3018 ''', noErrors: false // TODO(paulberry): remove when dartbug.com/28515 fixed. |
3049 noErrors: false // TODO(paulberry): remove when dartbug.com/28515 fixed. | |
3050 ); | 3019 ); |
3051 expectIdentifierType('methodCall', "int"); | 3020 expectIdentifierType('methodCall', "int"); |
3052 expectIdentifierType('staticCall', "int"); | 3021 expectIdentifierType('staticCall', "int"); |
3053 expectIdentifierType('staticFieldCall', "int"); | 3022 expectIdentifierType('staticFieldCall', "int"); |
3054 expectIdentifierType('topFunCall', "int"); | 3023 expectIdentifierType('topFunCall', "int"); |
3055 expectIdentifierType('topFieldCall', "int"); | 3024 expectIdentifierType('topFieldCall', "int"); |
3056 expectIdentifierType('localCall', "int"); | 3025 expectIdentifierType('localCall', "int"); |
3057 expectIdentifierType('paramCall', "int"); | 3026 expectIdentifierType('paramCall', "int"); |
3058 } | 3027 } |
3059 | 3028 |
3060 test_genericMethod_functionInvocation_inferred() async { | 3029 test_genericMethod_functionInvocation_inferred() async { |
3061 await resolveTestUnit( | 3030 await resolveTestUnit(r''' |
3062 r''' | |
3063 class C<E> { | 3031 class C<E> { |
3064 /*=T*/ f/*<T>*/(/*=T*/ e) => null; | 3032 /*=T*/ f/*<T>*/(/*=T*/ e) => null; |
3065 static /*=T*/ g/*<T>*/(/*=T*/ e) => null; | 3033 static /*=T*/ g/*<T>*/(/*=T*/ e) => null; |
3066 static final h = g; | 3034 static final h = g; |
3067 } | 3035 } |
3068 | 3036 |
3069 /*=T*/ topF/*<T>*/(/*=T*/ e) => null; | 3037 /*=T*/ topF/*<T>*/(/*=T*/ e) => null; |
3070 var topG = topF; | 3038 var topG = topF; |
3071 void test/*<S>*/(/*=T*/ pf/*<T>*/(/*=T*/ e)) { | 3039 void test/*<S>*/(/*=T*/ pf/*<T>*/(/*=T*/ e)) { |
3072 var c = new C<int>(); | 3040 var c = new C<int>(); |
3073 /*=T*/ lf/*<T>*/(/*=T*/ e) => null; | 3041 /*=T*/ lf/*<T>*/(/*=T*/ e) => null; |
3074 var methodCall = c.f(3); | 3042 var methodCall = c.f(3); |
3075 var staticCall = C.g(3); | 3043 var staticCall = C.g(3); |
3076 var staticFieldCall = C.h(3); | 3044 var staticFieldCall = C.h(3); |
3077 var topFunCall = topF(3); | 3045 var topFunCall = topF(3); |
3078 var topFieldCall = topG(3); | 3046 var topFieldCall = topG(3); |
3079 var localCall = lf(3); | 3047 var localCall = lf(3); |
3080 var paramCall = pf(3); | 3048 var paramCall = pf(3); |
3081 } | 3049 } |
3082 ''', | 3050 ''', noErrors: false // TODO(paulberry): remove when dartbug.com/28515 fixed. |
3083 noErrors: false // TODO(paulberry): remove when dartbug.com/28515 fixed. | |
3084 ); | 3051 ); |
3085 expectIdentifierType('methodCall', "int"); | 3052 expectIdentifierType('methodCall', "int"); |
3086 expectIdentifierType('staticCall', "int"); | 3053 expectIdentifierType('staticCall', "int"); |
3087 expectIdentifierType('staticFieldCall', "int"); | 3054 expectIdentifierType('staticFieldCall', "int"); |
3088 expectIdentifierType('topFunCall', "int"); | 3055 expectIdentifierType('topFunCall', "int"); |
3089 expectIdentifierType('topFieldCall', "int"); | 3056 expectIdentifierType('topFieldCall', "int"); |
3090 expectIdentifierType('localCall', "int"); | 3057 expectIdentifierType('localCall', "int"); |
3091 expectIdentifierType('paramCall', "int"); | 3058 expectIdentifierType('paramCall', "int"); |
3092 } | 3059 } |
3093 | 3060 |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3335 C toSpan(dynamic element) { | 3302 C toSpan(dynamic element) { |
3336 if (element is Iter) { | 3303 if (element is Iter) { |
3337 var y = element.map(toSpan); | 3304 var y = element.map(toSpan); |
3338 } | 3305 } |
3339 return null; | 3306 return null; |
3340 }'''); | 3307 }'''); |
3341 expectIdentifierType('y = ', 'List<C>', isNull); | 3308 expectIdentifierType('y = ', 'List<C>', isNull); |
3342 } | 3309 } |
3343 | 3310 |
3344 test_genericMethod_tearoff() async { | 3311 test_genericMethod_tearoff() async { |
3345 await resolveTestUnit( | 3312 await resolveTestUnit(r''' |
3346 r''' | |
3347 class C<E> { | 3313 class C<E> { |
3348 /*=T*/ f/*<T>*/(E e) => null; | 3314 /*=T*/ f/*<T>*/(E e) => null; |
3349 static /*=T*/ g/*<T>*/(/*=T*/ e) => null; | 3315 static /*=T*/ g/*<T>*/(/*=T*/ e) => null; |
3350 static final h = g; | 3316 static final h = g; |
3351 } | 3317 } |
3352 | 3318 |
3353 /*=T*/ topF/*<T>*/(/*=T*/ e) => null; | 3319 /*=T*/ topF/*<T>*/(/*=T*/ e) => null; |
3354 var topG = topF; | 3320 var topG = topF; |
3355 void test/*<S>*/(/*=T*/ pf/*<T>*/(/*=T*/ e)) { | 3321 void test/*<S>*/(/*=T*/ pf/*<T>*/(/*=T*/ e)) { |
3356 var c = new C<int>(); | 3322 var c = new C<int>(); |
3357 /*=T*/ lf/*<T>*/(/*=T*/ e) => null; | 3323 /*=T*/ lf/*<T>*/(/*=T*/ e) => null; |
3358 var methodTearOff = c.f; | 3324 var methodTearOff = c.f; |
3359 var staticTearOff = C.g; | 3325 var staticTearOff = C.g; |
3360 var staticFieldTearOff = C.h; | 3326 var staticFieldTearOff = C.h; |
3361 var topFunTearOff = topF; | 3327 var topFunTearOff = topF; |
3362 var topFieldTearOff = topG; | 3328 var topFieldTearOff = topG; |
3363 var localTearOff = lf; | 3329 var localTearOff = lf; |
3364 var paramTearOff = pf; | 3330 var paramTearOff = pf; |
3365 } | 3331 } |
3366 ''', | 3332 ''', noErrors: false // TODO(paulberry): remove when dartbug.com/28515 fixed. |
3367 noErrors: false // TODO(paulberry): remove when dartbug.com/28515 fixed. | |
3368 ); | 3333 ); |
3369 expectIdentifierType('methodTearOff', "<T>(int) → T"); | 3334 expectIdentifierType('methodTearOff', "<T>(int) → T"); |
3370 expectIdentifierType('staticTearOff', "<T>(T) → T"); | 3335 expectIdentifierType('staticTearOff', "<T>(T) → T"); |
3371 expectIdentifierType('staticFieldTearOff', "<T>(T) → T"); | 3336 expectIdentifierType('staticFieldTearOff', "<T>(T) → T"); |
3372 expectIdentifierType('topFunTearOff', "<T>(T) → T"); | 3337 expectIdentifierType('topFunTearOff', "<T>(T) → T"); |
3373 expectIdentifierType('topFieldTearOff', "<T>(T) → T"); | 3338 expectIdentifierType('topFieldTearOff', "<T>(T) → T"); |
3374 expectIdentifierType('localTearOff', "<T>(T) → T"); | 3339 expectIdentifierType('localTearOff', "<T>(T) → T"); |
3375 expectIdentifierType('paramTearOff', "<T>(T) → T"); | 3340 expectIdentifierType('paramTearOff', "<T>(T) → T"); |
3376 } | 3341 } |
3377 | 3342 |
(...skipping 835 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4213 var v = x; | 4178 var v = x; |
4214 v; // marker | 4179 v; // marker |
4215 } | 4180 } |
4216 int x = 3; | 4181 int x = 3; |
4217 '''; | 4182 '''; |
4218 CompilationUnit unit = await resolveSource(code); | 4183 CompilationUnit unit = await resolveSource(code); |
4219 assertPropagatedAssignedType(code, unit, typeProvider.intType, null); | 4184 assertPropagatedAssignedType(code, unit, typeProvider.intType, null); |
4220 assertTypeOfMarkedExpression(code, unit, typeProvider.intType, null); | 4185 assertTypeOfMarkedExpression(code, unit, typeProvider.intType, null); |
4221 } | 4186 } |
4222 } | 4187 } |
OLD | NEW |