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

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

Issue 2456803004: fixes #27586, prefer context type in generic inference (Closed)
Patch Set: more tweaks Created 4 years 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) 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 'package:analyzer/dart/ast/ast.dart'; 7 import 'package:analyzer/dart/ast/ast.dart';
8 import 'package:analyzer/dart/element/element.dart'; 8 import 'package:analyzer/dart/element/element.dart';
9 import 'package:analyzer/dart/element/type.dart'; 9 import 'package:analyzer/dart/element/type.dart';
10 import 'package:analyzer/src/dart/element/element.dart'; 10 import 'package:analyzer/src/dart/element/element.dart';
(...skipping 1434 matching lines...) Expand 10 before | Expand all | Expand 10 after
1445 Expression exp = (statements[i] as ExpressionStatement).expression; 1445 Expression exp = (statements[i] as ExpressionStatement).expression;
1446 expect(exp.staticType, typeProvider.dynamicType); 1446 expect(exp.staticType, typeProvider.dynamicType);
1447 } 1447 }
1448 } 1448 }
1449 1449
1450 checkBody("C"); 1450 checkBody("C");
1451 checkBody("D"); 1451 checkBody("D");
1452 } 1452 }
1453 1453
1454 void test_genericFunction_upwardsAndDownwards() { 1454 void test_genericFunction_upwardsAndDownwards() {
1455 // Regression tests for https://github.com/dart-lang/sdk/issues/27151. 1455 // Regression tests for https://github.com/dart-lang/sdk/issues/27586.
1456 resolveTestUnit(r'List<num> x = [1, 2];'); 1456 resolveTestUnit(r'List<num> x = [1, 2];');
1457 expectInitializerType('x', 'List<int>'); 1457 expectInitializerType('x', 'List<num>');
1458 } 1458 }
1459 1459
1460 void test_genericFunction_upwardsAndDownwards_Object() {
Leaf 2016/11/30 05:24:30 Can you add a version of this using generic method
1461 // Regression tests for https://github.com/dart-lang/sdk/issues/27625.
1462 resolveTestUnit(r'''
1463 List<Object> aaa = [];
1464 List<Object> bbb = [1, 2, 3];
1465 List<Object> ccc = [null];
1466 List<Object> ddd = [1 as dynamic];
1467 List<Object> eee = [new Object()];
Leaf 2016/11/30 05:24:29 Do we have any test cases for inference which uses
1468 ''');
1469 expectInitializerType('aaa', 'List<Object>');
1470 expectInitializerType('bbb', 'List<Object>');
1471 expectInitializerType('ccc', 'List<Object>');
1472 expectInitializerType('ddd', 'List<Object>');
1473 expectInitializerType('eee', 'List<Object>');
1474 }
1475
1476
1460 void test_genericMethod() { 1477 void test_genericMethod() {
1461 resolveTestUnit(r''' 1478 resolveTestUnit(r'''
1462 class C<E> { 1479 class C<E> {
1463 List/*<T>*/ f/*<T>*/(E e) => null; 1480 List/*<T>*/ f/*<T>*/(E e) => null;
1464 } 1481 }
1465 main() { 1482 main() {
1466 C<String> cOfString; 1483 C<String> cOfString;
1467 } 1484 }
1468 '''); 1485 ''');
1469 expectFunctionType('f', '<T>(E) → List<T>', 1486 expectFunctionType('f', '<T>(E) → List<T>',
(...skipping 931 matching lines...) Expand 10 before | Expand all | Expand 10 after
2401 main() { 2418 main() {
2402 var v = x; 2419 var v = x;
2403 v; // marker 2420 v; // marker
2404 } 2421 }
2405 int x = 3; 2422 int x = 3;
2406 '''; 2423 ''';
2407 assertPropagatedAssignedType(code, typeProvider.intType, null); 2424 assertPropagatedAssignedType(code, typeProvider.intType, null);
2408 assertTypeOfMarkedExpression(code, typeProvider.intType, null); 2425 assertTypeOfMarkedExpression(code, typeProvider.intType, null);
2409 } 2426 }
2410 } 2427 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698