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

Side by Side Diff: pkg/analyzer/test/src/task/strong/inferred_type_test.dart

Issue 2208953002: fix #25944, improve Future.then inference (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: fix based on comments Created 4 years, 4 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/test/src/context/mock_sdk.dart ('k') | sdk/lib/async/future.dart » ('j') | 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) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 // TODO(jmesserly): this file needs to be refactored, it's a port from 5 // TODO(jmesserly): this file needs to be refactored, it's a port from
6 // package:dev_compiler's tests 6 // package:dev_compiler's tests
7 /// Tests for type inference. 7 /// Tests for type inference.
8 library analyzer.test.src.task.strong.inferred_type_test; 8 library analyzer.test.src.task.strong.inferred_type_test;
9 9
10 import 'package:analyzer/dart/element/element.dart'; 10 import 'package:analyzer/dart/element/element.dart';
(...skipping 882 matching lines...) Expand 10 before | Expand all | Expand 10 after
893 l = (l = /*info:INFERRED_TYPE_LITERAL*/[1]); 893 l = (l = /*info:INFERRED_TYPE_LITERAL*/[1]);
894 } 894 }
895 '''); 895 ''');
896 } 896 }
897 897
898 void test_downwardsInferenceAsyncAwait() { 898 void test_downwardsInferenceAsyncAwait() {
899 checkFile(''' 899 checkFile('''
900 import 'dart:async'; 900 import 'dart:async';
901 Future test() async { 901 Future test() async {
902 dynamic d; 902 dynamic d;
903 List<int> l0 = /*warning:DOWN_CAST_COMPOSITE should be pass*/await /*pass shou ld be info:INFERRED_TYPE_LITERAL*/[d]; 903 List<int> l0 = await /*info:INFERRED_TYPE_LITERAL*/[/*info:DYNAMIC_CAST*/d];
904 List<int> l1 = await /*info:INFERRED_TYPE_ALLOCATION*/new Future.value(/*info: INFERRED_TYPE_LITERAL*/[/*info:DYNAMIC_CAST*/d]); 904 List<int> l1 = await /*info:INFERRED_TYPE_ALLOCATION*/new Future.value(/*info: INFERRED_TYPE_LITERAL*/[/*info:DYNAMIC_CAST*/d]);
905 } 905 }
906 '''); 906 ''');
907 } 907 }
908 908
909 void test_downwardsInferenceForEach() { 909 void test_downwardsInferenceForEach() {
910 checkFile(''' 910 checkFile('''
911 import 'dart:async'; 911 import 'dart:async';
912 Future main() async { 912 Future main() async {
913 for(int x in /*info:INFERRED_TYPE_LITERAL*/[1, 2, 3]) {} 913 for(int x in /*info:INFERRED_TYPE_LITERAL*/[1, 2, 3]) {}
(...skipping 602 matching lines...) Expand 10 before | Expand all | Expand 10 after
1516 int get y => null; 1516 int get y => null;
1517 '''); 1517 ''');
1518 var x = mainUnit.types[0].fields[0]; 1518 var x = mainUnit.types[0].fields[0];
1519 expect(x.type.toString(), 'int'); 1519 expect(x.type.toString(), 'int');
1520 } 1520 }
1521 1521
1522 void test_futureThen() { 1522 void test_futureThen() {
1523 checkFile(''' 1523 checkFile('''
1524 import 'dart:async'; 1524 import 'dart:async';
1525 Future f; 1525 Future f;
1526 Future<int> t1 = f.then((_) => new Future<int>.value(42)); 1526 Future<int> t1 = f.then((_) async => await new Future<int>.value(3));
1527 Future<int> t2 = f.then(/*info:INFERRED_TYPE_CLOSURE*/(_) async {return await ne w Future<int>.value(3);});
1528 Future<int> t3 = f.then((_) async => 3);
1529 Future<int> t4 = f.then(/*info:INFERRED_TYPE_CLOSURE*/(_) async {return 3;});
1530 Future<int> t5 = f.then((_) => new Future<int>.value(3));
1531 Future<int> t6 = f.then((_) {return new Future<int>.value(3);});
1532 Future<int> t7 = f.then((_) async => new Future<int>.value(3));
1533 Future<int> t8 = f.then(/*info:INFERRED_TYPE_CLOSURE*/(_) async {return new Futu re<int>.value(3);});
1527 '''); 1534 ''');
1528 } 1535 }
1529 1536
1537 void test_futureThen_conditional() {
1538 checkFile('''
1539 import 'dart:async';
1540 Future<bool> f;
1541 Future<int> t1 = f.then((x) async => x ? 2 : await new Future<int>.value(3));
1542 Future<int> t2 = f.then(/*info:INFERRED_TYPE_CLOSURE*/(x) async {return await x ? 2 : new Future<int>.value(3);});
1543 Future<int> t5 = f.then((x) => x ? 2 : new Future<int>.value(3));
1544 Future<int> t6 = f.then((x) {return x ? 2 : new Future<int>.value(3);});
1545 ''');
1546 }
1547
1548 void test_futureUnion_asyncConditional() {
1549 checkFile('''
1550 import 'dart:async';
1551
1552 Future<int> g1(bool x) async { return x ? 42 : /*info:INFERRED_TYPE_ALLOCATION*/ new Future.value(42); }
1553 Future<int> g2(bool x) async => x ? 42 : /*info:INFERRED_TYPE_ALLOCATION*/new Fu ture.value(42);
1554
1555 Future<int> g3(bool x) async {
1556 var y = x ? 42 : /*info:INFERRED_TYPE_ALLOCATION*/new Future.value(42);
1557 return y;
1558 }
1559 ''');
1560 }
1561
1562 void test_futureUnion_downwards() {
1563 checkFile('''
1564 import 'dart:async';
1565 Future f;
1566 // Instantiates Future<int>
1567 Future<int> t1 = f.then((_) => /*info:INFERRED_TYPE_ALLOCATION*/new Future.value (/*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/'hi'));
1568
1569 // Instantiates List<int>
1570 Future<List<int>> t2 = f.then((_) => /*info:INFERRED_TYPE_LITERAL*/[3]);
1571 Future<List<int>> g2() async { return /*info:INFERRED_TYPE_LITERAL*/[3]; }
1572 Future<List<int>> g3() async { return /*info:INFERRED_TYPE_ALLOCATION*/new Futur e.value(/*info:INFERRED_TYPE_LITERAL*/[3]); }
1573 ''');
1574 }
1575
1530 void test_genericMethods_basicDownwardInference() { 1576 void test_genericMethods_basicDownwardInference() {
1531 checkFile(r''' 1577 checkFile(r'''
1532 /*=T*/ f/*<S, T>*/(/*=S*/ s) => null; 1578 /*=T*/ f/*<S, T>*/(/*=S*/ s) => null;
1533 main() { 1579 main() {
1534 String x = f(42); 1580 String x = f(42);
1535 String y = (f)(42); 1581 String y = (f)(42);
1536 } 1582 }
1537 '''); 1583 ''');
1538 } 1584 }
1539 1585
(...skipping 2761 matching lines...) Expand 10 before | Expand all | Expand 10 after
4301 } 4347 }
4302 4348
4303 /// Adds a file using [helper.addFile] and calls [helper.check]. 4349 /// Adds a file using [helper.addFile] and calls [helper.check].
4304 /// 4350 ///
4305 /// Also returns the resolved compilation unit. 4351 /// Also returns the resolved compilation unit.
4306 @override 4352 @override
4307 CompilationUnitElement checkFile(String content) { 4353 CompilationUnitElement checkFile(String content) {
4308 return helper.checkFile(content).element; 4354 return helper.checkFile(content).element;
4309 } 4355 }
4310 } 4356 }
OLDNEW
« no previous file with comments | « pkg/analyzer/test/src/context/mock_sdk.dart ('k') | sdk/lib/async/future.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698