OLD | NEW |
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 library test.src.task.dart_test; | 5 library test.src.task.dart_test; |
6 | 6 |
7 import 'package:analyzer/src/context/cache.dart'; | 7 import 'package:analyzer/src/context/cache.dart'; |
8 import 'package:analyzer/src/generated/ast.dart'; | 8 import 'package:analyzer/src/generated/ast.dart'; |
9 import 'package:analyzer/src/generated/constant.dart'; | 9 import 'package:analyzer/src/generated/constant.dart'; |
10 import 'package:analyzer/src/generated/element.dart'; | 10 import 'package:analyzer/src/generated/element.dart'; |
(...skipping 25 matching lines...) Expand all Loading... |
36 runReflectiveTests(BuildEnumMemberElementsTaskTest); | 36 runReflectiveTests(BuildEnumMemberElementsTaskTest); |
37 runReflectiveTests(BuildExportNamespaceTaskTest); | 37 runReflectiveTests(BuildExportNamespaceTaskTest); |
38 runReflectiveTests(BuildLibraryElementTaskTest); | 38 runReflectiveTests(BuildLibraryElementTaskTest); |
39 runReflectiveTests(BuildPublicNamespaceTaskTest); | 39 runReflectiveTests(BuildPublicNamespaceTaskTest); |
40 runReflectiveTests(BuildSourceExportClosureTaskTest); | 40 runReflectiveTests(BuildSourceExportClosureTaskTest); |
41 runReflectiveTests(BuildSourceImportExportClosureTaskTest); | 41 runReflectiveTests(BuildSourceImportExportClosureTaskTest); |
42 runReflectiveTests(BuildTypeProviderTaskTest); | 42 runReflectiveTests(BuildTypeProviderTaskTest); |
43 runReflectiveTests(ComputeConstantDependenciesTaskTest); | 43 runReflectiveTests(ComputeConstantDependenciesTaskTest); |
44 runReflectiveTests(ComputeConstantValueTaskTest); | 44 runReflectiveTests(ComputeConstantValueTaskTest); |
45 runReflectiveTests(ComputeInferableStaticVariableDependenciesTaskTest); | 45 runReflectiveTests(ComputeInferableStaticVariableDependenciesTaskTest); |
| 46 runReflectiveTests(ComputeLibraryCycleTaskTest); |
46 runReflectiveTests(ContainingLibrariesTaskTest); | 47 runReflectiveTests(ContainingLibrariesTaskTest); |
47 runReflectiveTests(DartErrorsTaskTest); | 48 runReflectiveTests(DartErrorsTaskTest); |
48 runReflectiveTests(EvaluateUnitConstantsTaskTest); | 49 runReflectiveTests(EvaluateUnitConstantsTaskTest); |
49 runReflectiveTests(GatherUsedImportedElementsTaskTest); | 50 runReflectiveTests(GatherUsedImportedElementsTaskTest); |
50 runReflectiveTests(GatherUsedLocalElementsTaskTest); | 51 runReflectiveTests(GatherUsedLocalElementsTaskTest); |
51 runReflectiveTests(GenerateHintsTaskTest); | 52 runReflectiveTests(GenerateHintsTaskTest); |
52 runReflectiveTests(GenerateLintsTaskTest); | 53 runReflectiveTests(GenerateLintsTaskTest); |
53 runReflectiveTests(InferInstanceMembersInUnitTaskTest); | 54 runReflectiveTests(InferInstanceMembersInUnitTaskTest); |
54 runReflectiveTests(InferStaticVariableTypesInUnitTaskTest); | 55 runReflectiveTests(InferStaticVariableTypesInUnitTaskTest); |
55 runReflectiveTests(InferStaticVariableTypeTaskTest); | 56 runReflectiveTests(InferStaticVariableTypeTaskTest); |
56 runReflectiveTests(LibraryErrorsReadyTaskTest); | 57 runReflectiveTests(LibraryErrorsReadyTaskTest); |
57 runReflectiveTests(LibraryUnitErrorsTaskTest); | 58 runReflectiveTests(LibraryUnitErrorsTaskTest); |
58 runReflectiveTests(ParseDartTaskTest); | 59 runReflectiveTests(ParseDartTaskTest); |
59 runReflectiveTests(PartiallyResolveUnitReferencesTaskTest); | 60 runReflectiveTests(PartiallyResolveUnitReferencesTaskTest); |
60 runReflectiveTests(ResolveFunctionBodiesInUnitTaskTest); | 61 runReflectiveTests(ResolveInstanceFieldsInUnitTaskTest); |
61 runReflectiveTests(ResolveLibraryTypeNamesTaskTest); | 62 runReflectiveTests(ResolveLibraryTypeNamesTaskTest); |
| 63 runReflectiveTests(ResolveUnitTaskTest); |
62 runReflectiveTests(ResolveUnitTypeNamesTaskTest); | 64 runReflectiveTests(ResolveUnitTypeNamesTaskTest); |
63 runReflectiveTests(ResolveVariableReferencesTaskTest); | 65 runReflectiveTests(ResolveVariableReferencesTaskTest); |
64 runReflectiveTests(ScanDartTaskTest); | 66 runReflectiveTests(ScanDartTaskTest); |
65 runReflectiveTests(StrongModeInferenceTest); | 67 runReflectiveTests(StrongModeInferenceTest); |
66 runReflectiveTests(VerifyUnitTaskTest); | 68 runReflectiveTests(VerifyUnitTaskTest); |
67 } | 69 } |
68 | 70 |
69 isInstanceOf isBuildCompilationUnitElementTask = | 71 isInstanceOf isBuildCompilationUnitElementTask = |
70 new isInstanceOf<BuildCompilationUnitElementTask>(); | 72 new isInstanceOf<BuildCompilationUnitElementTask>(); |
71 isInstanceOf isBuildDirectiveElementsTask = | 73 isInstanceOf isBuildDirectiveElementsTask = |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 new isInstanceOf<InferStaticVariableTypesInUnitTask>(); | 109 new isInstanceOf<InferStaticVariableTypesInUnitTask>(); |
108 isInstanceOf isInferStaticVariableTypeTask = | 110 isInstanceOf isInferStaticVariableTypeTask = |
109 new isInstanceOf<InferStaticVariableTypeTask>(); | 111 new isInstanceOf<InferStaticVariableTypeTask>(); |
110 isInstanceOf isLibraryErrorsReadyTask = | 112 isInstanceOf isLibraryErrorsReadyTask = |
111 new isInstanceOf<LibraryErrorsReadyTask>(); | 113 new isInstanceOf<LibraryErrorsReadyTask>(); |
112 isInstanceOf isLibraryUnitErrorsTask = | 114 isInstanceOf isLibraryUnitErrorsTask = |
113 new isInstanceOf<LibraryUnitErrorsTask>(); | 115 new isInstanceOf<LibraryUnitErrorsTask>(); |
114 isInstanceOf isParseDartTask = new isInstanceOf<ParseDartTask>(); | 116 isInstanceOf isParseDartTask = new isInstanceOf<ParseDartTask>(); |
115 isInstanceOf isPartiallyResolveUnitReferencesTask = | 117 isInstanceOf isPartiallyResolveUnitReferencesTask = |
116 new isInstanceOf<PartiallyResolveUnitReferencesTask>(); | 118 new isInstanceOf<PartiallyResolveUnitReferencesTask>(); |
117 isInstanceOf isResolveFunctionBodiesInUnitTask = | |
118 new isInstanceOf<ResolveFunctionBodiesInUnitTask>(); | |
119 isInstanceOf isResolveLibraryTypeNamesTask = | 119 isInstanceOf isResolveLibraryTypeNamesTask = |
120 new isInstanceOf<ResolveLibraryTypeNamesTask>(); | 120 new isInstanceOf<ResolveLibraryTypeNamesTask>(); |
| 121 isInstanceOf isResolveUnitTask = new isInstanceOf<ResolveUnitTask>(); |
121 isInstanceOf isResolveUnitTypeNamesTask = | 122 isInstanceOf isResolveUnitTypeNamesTask = |
122 new isInstanceOf<ResolveUnitTypeNamesTask>(); | 123 new isInstanceOf<ResolveUnitTypeNamesTask>(); |
123 isInstanceOf isResolveVariableReferencesTask = | 124 isInstanceOf isResolveVariableReferencesTask = |
124 new isInstanceOf<ResolveVariableReferencesTask>(); | 125 new isInstanceOf<ResolveVariableReferencesTask>(); |
125 isInstanceOf isScanDartTask = new isInstanceOf<ScanDartTask>(); | 126 isInstanceOf isScanDartTask = new isInstanceOf<ScanDartTask>(); |
126 isInstanceOf isVerifyUnitTask = new isInstanceOf<VerifyUnitTask>(); | 127 isInstanceOf isVerifyUnitTask = new isInstanceOf<VerifyUnitTask>(); |
127 | 128 |
128 final LintCode _testLintCode = new LintCode('test lint', 'test lint code'); | 129 final LintCode _testLintCode = new LintCode('test lint', 'test lint code'); |
129 | 130 |
130 @reflectiveTest | 131 @reflectiveTest |
(...skipping 1291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1422 return unit; | 1423 return unit; |
1423 } | 1424 } |
1424 | 1425 |
1425 CompilationUnit _resolveUnit(String content) => | 1426 CompilationUnit _resolveUnit(String content) => |
1426 _resolveSource(newSource('/test.dart', content)); | 1427 _resolveSource(newSource('/test.dart', content)); |
1427 } | 1428 } |
1428 | 1429 |
1429 @reflectiveTest | 1430 @reflectiveTest |
1430 class ComputeInferableStaticVariableDependenciesTaskTest | 1431 class ComputeInferableStaticVariableDependenciesTaskTest |
1431 extends _AbstractDartTaskTest { | 1432 extends _AbstractDartTaskTest { |
| 1433 @override |
| 1434 void setUp() { |
| 1435 super.setUp(); |
| 1436 // Variable dependencies are only available in strong mode. |
| 1437 enableStrongMode(); |
| 1438 } |
| 1439 |
1432 test_perform() { | 1440 test_perform() { |
1433 AnalysisTarget source = newSource( | 1441 AnalysisTarget source = newSource( |
1434 '/test.dart', | 1442 '/test.dart', |
1435 ''' | 1443 ''' |
1436 const a = b; | 1444 const a = b; |
1437 const b = 0; | 1445 const b = 0; |
1438 '''); | 1446 '''); |
1439 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 1447 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
1440 computeResult(target, RESOLVED_UNIT5); | 1448 computeResult(target, RESOLVED_UNIT5); |
1441 CompilationUnit unit = outputs[RESOLVED_UNIT5]; | 1449 CompilationUnit unit = outputs[RESOLVED_UNIT5]; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1487 computeResult(part, SOURCE_KIND); | 1495 computeResult(part, SOURCE_KIND); |
1488 computeResult(part, CONTAINING_LIBRARIES, | 1496 computeResult(part, CONTAINING_LIBRARIES, |
1489 matcher: isContainingLibrariesTask); | 1497 matcher: isContainingLibrariesTask); |
1490 expect(outputs, hasLength(1)); | 1498 expect(outputs, hasLength(1)); |
1491 List<Source> containingLibraries = outputs[CONTAINING_LIBRARIES]; | 1499 List<Source> containingLibraries = outputs[CONTAINING_LIBRARIES]; |
1492 expect(containingLibraries, unorderedEquals([library])); | 1500 expect(containingLibraries, unorderedEquals([library])); |
1493 } | 1501 } |
1494 } | 1502 } |
1495 | 1503 |
1496 @reflectiveTest | 1504 @reflectiveTest |
| 1505 class ComputeLibraryCycleTaskTest extends _AbstractDartTaskTest { |
| 1506 @override |
| 1507 void setUp() { |
| 1508 super.setUp(); |
| 1509 enableStrongMode(); |
| 1510 } |
| 1511 |
| 1512 void test_library_cycle_singleton() { |
| 1513 Source source = newSource( |
| 1514 '/test.dart', |
| 1515 ''' |
| 1516 import 'dart:core'; |
| 1517 '''); |
| 1518 computeResult(new LibrarySpecificUnit(source, source), LIBRARY_CYCLE); |
| 1519 List<LibraryElement> component = outputs[LIBRARY_CYCLE]; |
| 1520 List<CompilationUnitElement> units = outputs[LIBRARY_CYCLE_UNITS]; |
| 1521 List<CompilationUnitElement> deps = outputs[LIBRARY_CYCLE_DEPENDENCIES]; |
| 1522 expect(component, hasLength(1)); |
| 1523 expect(units, hasLength(1)); |
| 1524 expect(deps, hasLength(1)); |
| 1525 } |
| 1526 |
| 1527 void test_library_cycle_linear() { |
| 1528 List<Source> sources = newSources({ |
| 1529 '/a.dart': ''' |
| 1530 ''', |
| 1531 '/b.dart': ''' |
| 1532 import 'a.dart'; |
| 1533 ''' |
| 1534 }); |
| 1535 List<Map<ResultDescriptor, dynamic>> results = |
| 1536 computeLibraryResultsMap(sources, LIBRARY_CYCLE); |
| 1537 List<LibraryElement> component0 = results[0][LIBRARY_CYCLE]; |
| 1538 List<LibraryElement> component1 = results[1][LIBRARY_CYCLE]; |
| 1539 expect(component0, hasLength(1)); |
| 1540 expect(component1, hasLength(1)); |
| 1541 |
| 1542 List<CompilationUnitElement> units0 = results[0][LIBRARY_CYCLE_UNITS]; |
| 1543 List<CompilationUnitElement> units1 = results[1][LIBRARY_CYCLE_UNITS]; |
| 1544 expect(units0, hasLength(1)); |
| 1545 expect(units1, hasLength(1)); |
| 1546 |
| 1547 List<CompilationUnitElement> dep0 = results[0][LIBRARY_CYCLE_DEPENDENCIES]; |
| 1548 List<CompilationUnitElement> dep1 = results[1][LIBRARY_CYCLE_DEPENDENCIES]; |
| 1549 expect(dep0, hasLength(1)); // dart:core |
| 1550 expect(dep1, hasLength(2)); // dart:core, a.dart |
| 1551 } |
| 1552 |
| 1553 void test_library_cycle_tree() { |
| 1554 List<Source> sources = newSources({ |
| 1555 '/a.dart': ''' |
| 1556 ''', |
| 1557 '/b.dart': ''' |
| 1558 ''', |
| 1559 '/c.dart': ''' |
| 1560 import 'a.dart'; |
| 1561 import 'b.dart'; |
| 1562 ''' |
| 1563 }); |
| 1564 List<Map<ResultDescriptor, dynamic>> results = |
| 1565 computeLibraryResultsMap(sources, LIBRARY_CYCLE); |
| 1566 List<LibraryElement> component0 = results[0][LIBRARY_CYCLE]; |
| 1567 List<LibraryElement> component1 = results[1][LIBRARY_CYCLE]; |
| 1568 List<LibraryElement> component2 = results[2][LIBRARY_CYCLE]; |
| 1569 expect(component0, hasLength(1)); |
| 1570 expect(component1, hasLength(1)); |
| 1571 expect(component2, hasLength(1)); |
| 1572 |
| 1573 List<CompilationUnitElement> units0 = results[0][LIBRARY_CYCLE_UNITS]; |
| 1574 List<CompilationUnitElement> units1 = results[1][LIBRARY_CYCLE_UNITS]; |
| 1575 List<CompilationUnitElement> units2 = results[2][LIBRARY_CYCLE_UNITS]; |
| 1576 expect(units0, hasLength(1)); |
| 1577 expect(units1, hasLength(1)); |
| 1578 expect(units2, hasLength(1)); |
| 1579 |
| 1580 List<CompilationUnitElement> dep0 = results[0][LIBRARY_CYCLE_DEPENDENCIES]; |
| 1581 List<CompilationUnitElement> dep1 = results[1][LIBRARY_CYCLE_DEPENDENCIES]; |
| 1582 List<CompilationUnitElement> dep2 = results[2][LIBRARY_CYCLE_DEPENDENCIES]; |
| 1583 expect(dep0, hasLength(1)); // dart:core |
| 1584 expect(dep1, hasLength(1)); // dart:core, |
| 1585 expect(dep2, hasLength(3)); // dart:core, a.dart, b.dart |
| 1586 } |
| 1587 |
| 1588 void test_library_cycle_loop() { |
| 1589 List<Source> sources = newSources({ |
| 1590 '/a.dart': ''' |
| 1591 import 'c.dart'; |
| 1592 ''', |
| 1593 '/b.dart': ''' |
| 1594 import 'a.dart'; |
| 1595 ''', |
| 1596 '/c.dart': ''' |
| 1597 import 'b.dart'; |
| 1598 ''' |
| 1599 }); |
| 1600 List<Map<ResultDescriptor, dynamic>> results = |
| 1601 computeLibraryResultsMap(sources, LIBRARY_CYCLE).toList(); |
| 1602 List<LibraryElement> component0 = results[0][LIBRARY_CYCLE]; |
| 1603 List<LibraryElement> component1 = results[1][LIBRARY_CYCLE]; |
| 1604 List<LibraryElement> component2 = results[2][LIBRARY_CYCLE]; |
| 1605 |
| 1606 expect(component0, hasLength(3)); |
| 1607 expect(component1, hasLength(3)); |
| 1608 expect(component2, hasLength(3)); |
| 1609 |
| 1610 List<CompilationUnitElement> units0 = results[0][LIBRARY_CYCLE_UNITS]; |
| 1611 List<CompilationUnitElement> units1 = results[1][LIBRARY_CYCLE_UNITS]; |
| 1612 List<CompilationUnitElement> units2 = results[2][LIBRARY_CYCLE_UNITS]; |
| 1613 expect(units0, hasLength(3)); |
| 1614 expect(units1, hasLength(3)); |
| 1615 expect(units2, hasLength(3)); |
| 1616 |
| 1617 List<CompilationUnitElement> dep0 = results[0][LIBRARY_CYCLE_DEPENDENCIES]; |
| 1618 List<CompilationUnitElement> dep1 = results[1][LIBRARY_CYCLE_DEPENDENCIES]; |
| 1619 List<CompilationUnitElement> dep2 = results[2][LIBRARY_CYCLE_DEPENDENCIES]; |
| 1620 expect(dep0, hasLength(1)); // dart:core |
| 1621 expect(dep1, hasLength(1)); // dart:core |
| 1622 expect(dep2, hasLength(1)); // dart:core |
| 1623 } |
| 1624 |
| 1625 void test_library_cycle_self_loop() { |
| 1626 List<Source> sources = newSources({ |
| 1627 '/a.dart': ''' |
| 1628 import 'a.dart'; |
| 1629 ''' |
| 1630 }); |
| 1631 List<Map<ResultDescriptor, dynamic>> results = |
| 1632 computeLibraryResultsMap(sources, LIBRARY_CYCLE).toList(); |
| 1633 List<LibraryElement> component0 = results[0][LIBRARY_CYCLE]; |
| 1634 expect(component0, hasLength(1)); |
| 1635 |
| 1636 List<CompilationUnitElement> units0 = results[0][LIBRARY_CYCLE_UNITS]; |
| 1637 expect(units0, hasLength(1)); |
| 1638 |
| 1639 List<CompilationUnitElement> dep0 = results[0][LIBRARY_CYCLE_DEPENDENCIES]; |
| 1640 expect(dep0, hasLength(1)); // dart:core |
| 1641 } |
| 1642 |
| 1643 void test_library_double_loop() { |
| 1644 List<Source> sources = newSources({ |
| 1645 '/a.dart': ''' |
| 1646 import 'b.dart'; |
| 1647 ''', |
| 1648 '/b.dart': ''' |
| 1649 import 'a.dart'; |
| 1650 ''', |
| 1651 '/c.dart': ''' |
| 1652 import 'd.dart' as foo; |
| 1653 import 'a.dart' as bar; |
| 1654 export 'b.dart'; |
| 1655 ''', |
| 1656 '/d.dart': ''' |
| 1657 import 'c.dart' as foo; |
| 1658 import 'b.dart' as bar; |
| 1659 export 'a.dart'; |
| 1660 ''' |
| 1661 }); |
| 1662 List<Map<ResultDescriptor, dynamic>> results = |
| 1663 computeLibraryResultsMap(sources, LIBRARY_CYCLE).toList(); |
| 1664 List<LibraryElement> component0 = results[0][LIBRARY_CYCLE]; |
| 1665 List<LibraryElement> component1 = results[1][LIBRARY_CYCLE]; |
| 1666 List<LibraryElement> component2 = results[2][LIBRARY_CYCLE]; |
| 1667 List<LibraryElement> component3 = results[3][LIBRARY_CYCLE]; |
| 1668 |
| 1669 expect(component0, hasLength(2)); |
| 1670 expect(component1, hasLength(2)); |
| 1671 expect(component2, hasLength(2)); |
| 1672 expect(component3, hasLength(2)); |
| 1673 |
| 1674 List<CompilationUnitElement> units0 = results[0][LIBRARY_CYCLE_UNITS]; |
| 1675 List<CompilationUnitElement> units1 = results[1][LIBRARY_CYCLE_UNITS]; |
| 1676 List<CompilationUnitElement> units2 = results[2][LIBRARY_CYCLE_UNITS]; |
| 1677 List<CompilationUnitElement> units3 = results[3][LIBRARY_CYCLE_UNITS]; |
| 1678 expect(units0, hasLength(2)); |
| 1679 expect(units1, hasLength(2)); |
| 1680 expect(units2, hasLength(2)); |
| 1681 expect(units3, hasLength(2)); |
| 1682 |
| 1683 List<CompilationUnitElement> dep0 = results[0][LIBRARY_CYCLE_DEPENDENCIES]; |
| 1684 List<CompilationUnitElement> dep1 = results[1][LIBRARY_CYCLE_DEPENDENCIES]; |
| 1685 List<CompilationUnitElement> dep2 = results[2][LIBRARY_CYCLE_DEPENDENCIES]; |
| 1686 List<CompilationUnitElement> dep3 = results[3][LIBRARY_CYCLE_DEPENDENCIES]; |
| 1687 expect(dep0, hasLength(1)); // dart:core |
| 1688 expect(dep1, hasLength(1)); // dart:core |
| 1689 expect(dep3, hasLength(3)); // dart:core, a.dart, b.dart |
| 1690 expect(dep3, hasLength(3)); // dart:core, a.dart, b.dart |
| 1691 } |
| 1692 |
| 1693 void test_library_double_loop_parts() { |
| 1694 List<Source> sources = newSources({ |
| 1695 '/a.dart': ''' |
| 1696 import 'b.dart'; |
| 1697 part 'aa.dart'; |
| 1698 part 'ab.dart'; |
| 1699 ''', |
| 1700 '/b.dart': ''' |
| 1701 import 'a.dart'; |
| 1702 ''', |
| 1703 '/aa.dart': ''' |
| 1704 ''', |
| 1705 '/ab.dart': ''' |
| 1706 ''', |
| 1707 '/c.dart': ''' |
| 1708 import 'd.dart' as foo; |
| 1709 import 'a.dart' as bar; |
| 1710 export 'b.dart'; |
| 1711 ''', |
| 1712 '/d.dart': ''' |
| 1713 import 'c.dart' as foo; |
| 1714 import 'b.dart' as bar; |
| 1715 export 'a.dart'; |
| 1716 part 'da.dart'; |
| 1717 part 'db.dart'; |
| 1718 ''', |
| 1719 '/da.dart': ''' |
| 1720 ''', |
| 1721 '/db.dart': ''' |
| 1722 ''' |
| 1723 }); |
| 1724 computeResult( |
| 1725 new LibrarySpecificUnit(sources[0], sources[0]), LIBRARY_CYCLE); |
| 1726 Map<ResultDescriptor, dynamic> results0 = outputs; |
| 1727 computeResult( |
| 1728 new LibrarySpecificUnit(sources[1], sources[1]), LIBRARY_CYCLE); |
| 1729 Map<ResultDescriptor, dynamic> results1 = outputs; |
| 1730 computeResult( |
| 1731 new LibrarySpecificUnit(sources[0], sources[2]), LIBRARY_CYCLE); |
| 1732 Map<ResultDescriptor, dynamic> results2 = outputs; |
| 1733 computeResult( |
| 1734 new LibrarySpecificUnit(sources[0], sources[3]), LIBRARY_CYCLE); |
| 1735 Map<ResultDescriptor, dynamic> results3 = outputs; |
| 1736 computeResult( |
| 1737 new LibrarySpecificUnit(sources[4], sources[4]), LIBRARY_CYCLE); |
| 1738 Map<ResultDescriptor, dynamic> results4 = outputs; |
| 1739 computeResult( |
| 1740 new LibrarySpecificUnit(sources[5], sources[5]), LIBRARY_CYCLE); |
| 1741 Map<ResultDescriptor, dynamic> results5 = outputs; |
| 1742 computeResult( |
| 1743 new LibrarySpecificUnit(sources[5], sources[6]), LIBRARY_CYCLE); |
| 1744 Map<ResultDescriptor, dynamic> results6 = outputs; |
| 1745 computeResult( |
| 1746 new LibrarySpecificUnit(sources[5], sources[7]), LIBRARY_CYCLE); |
| 1747 Map<ResultDescriptor, dynamic> results7 = outputs; |
| 1748 |
| 1749 List<LibraryElement> component0 = results0[LIBRARY_CYCLE]; |
| 1750 List<LibraryElement> component1 = results1[LIBRARY_CYCLE]; |
| 1751 List<LibraryElement> component2 = results2[LIBRARY_CYCLE]; |
| 1752 List<LibraryElement> component3 = results3[LIBRARY_CYCLE]; |
| 1753 List<LibraryElement> component4 = results4[LIBRARY_CYCLE]; |
| 1754 List<LibraryElement> component5 = results5[LIBRARY_CYCLE]; |
| 1755 List<LibraryElement> component6 = results6[LIBRARY_CYCLE]; |
| 1756 List<LibraryElement> component7 = results7[LIBRARY_CYCLE]; |
| 1757 |
| 1758 expect(component0, hasLength(2)); |
| 1759 expect(component1, hasLength(2)); |
| 1760 expect(component2, hasLength(2)); |
| 1761 expect(component3, hasLength(2)); |
| 1762 expect(component4, hasLength(2)); |
| 1763 expect(component5, hasLength(2)); |
| 1764 expect(component6, hasLength(2)); |
| 1765 expect(component7, hasLength(2)); |
| 1766 |
| 1767 List<CompilationUnitElement> units0 = results0[LIBRARY_CYCLE_UNITS]; |
| 1768 List<CompilationUnitElement> units1 = results1[LIBRARY_CYCLE_UNITS]; |
| 1769 List<CompilationUnitElement> units2 = results2[LIBRARY_CYCLE_UNITS]; |
| 1770 List<CompilationUnitElement> units3 = results3[LIBRARY_CYCLE_UNITS]; |
| 1771 List<CompilationUnitElement> units4 = results4[LIBRARY_CYCLE_UNITS]; |
| 1772 List<CompilationUnitElement> units5 = results5[LIBRARY_CYCLE_UNITS]; |
| 1773 List<CompilationUnitElement> units6 = results6[LIBRARY_CYCLE_UNITS]; |
| 1774 List<CompilationUnitElement> units7 = results7[LIBRARY_CYCLE_UNITS]; |
| 1775 expect(units0, hasLength(4)); |
| 1776 expect(units1, hasLength(4)); |
| 1777 expect(units2, hasLength(4)); |
| 1778 expect(units3, hasLength(4)); |
| 1779 expect(units4, hasLength(4)); |
| 1780 expect(units5, hasLength(4)); |
| 1781 expect(units6, hasLength(4)); |
| 1782 expect(units7, hasLength(4)); |
| 1783 |
| 1784 List<CompilationUnitElement> dep0 = results0[LIBRARY_CYCLE_DEPENDENCIES]; |
| 1785 List<CompilationUnitElement> dep1 = results1[LIBRARY_CYCLE_DEPENDENCIES]; |
| 1786 List<CompilationUnitElement> dep2 = results2[LIBRARY_CYCLE_DEPENDENCIES]; |
| 1787 List<CompilationUnitElement> dep3 = results3[LIBRARY_CYCLE_DEPENDENCIES]; |
| 1788 List<CompilationUnitElement> dep4 = results4[LIBRARY_CYCLE_DEPENDENCIES]; |
| 1789 List<CompilationUnitElement> dep5 = results5[LIBRARY_CYCLE_DEPENDENCIES]; |
| 1790 List<CompilationUnitElement> dep6 = results6[LIBRARY_CYCLE_DEPENDENCIES]; |
| 1791 List<CompilationUnitElement> dep7 = results7[LIBRARY_CYCLE_DEPENDENCIES]; |
| 1792 expect(dep0, hasLength(1)); // dart:core |
| 1793 expect(dep1, hasLength(1)); // dart:core |
| 1794 expect(dep2, hasLength(1)); // dart:core |
| 1795 expect(dep3, hasLength(1)); // dart:core |
| 1796 expect(dep4, hasLength(5)); // dart:core, a.dart, aa.dart, ab.dart, b.dart |
| 1797 expect(dep5, hasLength(5)); // dart:core, a.dart, aa.dart, ab.dart, b.dart |
| 1798 expect(dep6, hasLength(5)); // dart:core, a.dart, aa.dart, ab.dart, b.dart |
| 1799 expect(dep7, hasLength(5)); // dart:core, a.dart, aa.dart, ab.dart, b.dart |
| 1800 } |
| 1801 } |
| 1802 |
| 1803 @reflectiveTest |
1497 class DartErrorsTaskTest extends _AbstractDartTaskTest { | 1804 class DartErrorsTaskTest extends _AbstractDartTaskTest { |
1498 test_perform_definingCompilationUnit() { | 1805 test_perform_definingCompilationUnit() { |
1499 AnalysisTarget library = | 1806 AnalysisTarget library = |
1500 newSource('/test.dart', 'library test; import "dart:math";'); | 1807 newSource('/test.dart', 'library test; import "dart:math";'); |
1501 computeResult(library, INCLUDED_PARTS); | 1808 computeResult(library, INCLUDED_PARTS); |
1502 computeResult(library, DART_ERRORS, matcher: isDartErrorsTask); | 1809 computeResult(library, DART_ERRORS, matcher: isDartErrorsTask); |
1503 expect(outputs, hasLength(1)); | 1810 expect(outputs, hasLength(1)); |
1504 List<AnalysisError> errors = outputs[DART_ERRORS]; | 1811 List<AnalysisError> errors = outputs[DART_ERRORS]; |
1505 expect(errors, hasLength(1)); | 1812 expect(errors, hasLength(1)); |
1506 } | 1813 } |
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1948 Y m(Z x) {} | 2255 Y m(Z x) {} |
1949 } | 2256 } |
1950 class B extends A { | 2257 class B extends A { |
1951 var f; | 2258 var f; |
1952 m(x) {} | 2259 m(x) {} |
1953 } | 2260 } |
1954 class X {} | 2261 class X {} |
1955 class Y {} | 2262 class Y {} |
1956 class Z {} | 2263 class Z {} |
1957 '''); | 2264 '''); |
1958 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT7, | 2265 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT8, |
1959 matcher: isInferInstanceMembersInUnitTask); | 2266 matcher: isInferInstanceMembersInUnitTask); |
1960 CompilationUnit unit = outputs[RESOLVED_UNIT7]; | 2267 CompilationUnit unit = outputs[RESOLVED_UNIT8]; |
1961 VariableDeclaration field = getFieldInClass(unit, 'B', 'f'); | 2268 VariableDeclaration field = getFieldInClass(unit, 'B', 'f'); |
1962 MethodDeclaration method = getMethodInClass(unit, 'B', 'm'); | 2269 MethodDeclaration method = getMethodInClass(unit, 'B', 'm'); |
1963 DartType typeX = getClass(unit, 'X').element.type; | 2270 DartType typeX = getClass(unit, 'X').element.type; |
1964 DartType typeY = getClass(unit, 'Y').element.type; | 2271 DartType typeY = getClass(unit, 'Y').element.type; |
1965 DartType typeZ = getClass(unit, 'Z').element.type; | 2272 DartType typeZ = getClass(unit, 'Z').element.type; |
1966 | 2273 |
1967 expect(field.element.type, typeX); | 2274 expect(field.element.type, typeX); |
1968 expect(method.element.returnType, typeY); | 2275 expect(method.element.returnType, typeY); |
1969 expect(method.element.parameters[0].type, typeZ); | 2276 expect(method.element.parameters[0].type, typeZ); |
1970 } | 2277 } |
(...skipping 11 matching lines...) Expand all Loading... |
1982 '/second.dart', | 2289 '/second.dart', |
1983 ''' | 2290 ''' |
1984 import 'first.dart'; | 2291 import 'first.dart'; |
1985 | 2292 |
1986 const b = a; | 2293 const b = a; |
1987 class M { | 2294 class M { |
1988 String c = a; | 2295 String c = a; |
1989 } | 2296 } |
1990 '''); | 2297 '''); |
1991 computeResult( | 2298 computeResult( |
1992 new LibrarySpecificUnit(firstSource, firstSource), RESOLVED_UNIT7, | 2299 new LibrarySpecificUnit(firstSource, firstSource), RESOLVED_UNIT8, |
1993 matcher: isInferInstanceMembersInUnitTask); | 2300 matcher: isInferInstanceMembersInUnitTask); |
1994 CompilationUnit firstUnit = outputs[RESOLVED_UNIT7]; | 2301 CompilationUnit firstUnit = outputs[RESOLVED_UNIT8]; |
1995 computeResult( | 2302 computeResult( |
1996 new LibrarySpecificUnit(secondSource, secondSource), RESOLVED_UNIT7); | 2303 new LibrarySpecificUnit(secondSource, secondSource), RESOLVED_UNIT8); |
1997 CompilationUnit secondUnit = outputs[RESOLVED_UNIT7]; | 2304 CompilationUnit secondUnit = outputs[RESOLVED_UNIT8]; |
1998 | 2305 |
1999 VariableDeclaration variableA = getTopLevelVariable(firstUnit, 'a'); | 2306 VariableDeclaration variableA = getTopLevelVariable(firstUnit, 'a'); |
2000 VariableDeclaration variableB = getTopLevelVariable(secondUnit, 'b'); | 2307 VariableDeclaration variableB = getTopLevelVariable(secondUnit, 'b'); |
2001 VariableDeclaration variableC = getFieldInClass(secondUnit, 'M', 'c'); | 2308 VariableDeclaration variableC = getFieldInClass(secondUnit, 'M', 'c'); |
2002 InterfaceType stringType = context.typeProvider.stringType; | 2309 InterfaceType stringType = context.typeProvider.stringType; |
2003 | 2310 |
2004 expect(variableA.element.type, stringType); | 2311 expect(variableA.element.type, stringType); |
2005 expect(variableB.element.type, stringType); | 2312 expect(variableB.element.type, stringType); |
2006 expect(variableB.initializer.staticType, stringType); | 2313 expect(variableB.initializer.staticType, stringType); |
2007 expect(variableC.element.type, stringType); | 2314 expect(variableC.element.type, stringType); |
2008 expect(variableC.initializer.staticType, stringType); | 2315 expect(variableC.initializer.staticType, stringType); |
2009 } | 2316 } |
2010 | 2317 |
2011 void test_perform_reresolution() { | 2318 void test_perform_reresolution() { |
2012 enableStrongMode(); | 2319 enableStrongMode(); |
2013 AnalysisTarget source = newSource( | 2320 AnalysisTarget source = newSource( |
2014 '/test.dart', | 2321 '/test.dart', |
2015 ''' | 2322 ''' |
2016 const topLevel = ''; | 2323 const topLevel = ''; |
2017 class C { | 2324 class C { |
2018 String field = topLevel; | 2325 String field = topLevel; |
2019 } | 2326 } |
2020 '''); | 2327 '''); |
2021 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT7); | 2328 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT8); |
2022 CompilationUnit unit = outputs[RESOLVED_UNIT7]; | 2329 CompilationUnit unit = outputs[RESOLVED_UNIT8]; |
2023 VariableDeclaration topLevelDecl = getTopLevelVariable(unit, 'topLevel'); | 2330 VariableDeclaration topLevelDecl = getTopLevelVariable(unit, 'topLevel'); |
2024 VariableDeclaration fieldDecl = getFieldInClass(unit, 'C', 'field'); | 2331 VariableDeclaration fieldDecl = getFieldInClass(unit, 'C', 'field'); |
2025 VariableElement topLevel = topLevelDecl.name.staticElement; | 2332 VariableElement topLevel = topLevelDecl.name.staticElement; |
2026 VariableElement field = fieldDecl.name.staticElement; | 2333 VariableElement field = fieldDecl.name.staticElement; |
2027 | 2334 |
2028 InterfaceType stringType = context.typeProvider.stringType; | 2335 InterfaceType stringType = context.typeProvider.stringType; |
2029 expect(topLevel.type, stringType); | 2336 expect(topLevel.type, stringType); |
2030 expect(field.type, stringType); | 2337 expect(field.type, stringType); |
2031 expect(fieldDecl.initializer.staticType, stringType); | 2338 expect(fieldDecl.initializer.staticType, stringType); |
2032 } | 2339 } |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2158 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT5); | 2465 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT5); |
2159 CompilationUnit unit = outputs[RESOLVED_UNIT5]; | 2466 CompilationUnit unit = outputs[RESOLVED_UNIT5]; |
2160 VariableDeclaration declaration = getTopLevelVariable(unit, 'topLevel'); | 2467 VariableDeclaration declaration = getTopLevelVariable(unit, 'topLevel'); |
2161 VariableElement variable = declaration.name.staticElement; | 2468 VariableElement variable = declaration.name.staticElement; |
2162 InferStaticVariableTypeTask inferTask = | 2469 InferStaticVariableTypeTask inferTask = |
2163 new InferStaticVariableTypeTask(task.context, variable); | 2470 new InferStaticVariableTypeTask(task.context, variable); |
2164 expect(inferTask.getDeclaration(unit), declaration); | 2471 expect(inferTask.getDeclaration(unit), declaration); |
2165 } | 2472 } |
2166 | 2473 |
2167 void test_perform() { | 2474 void test_perform() { |
| 2475 enableStrongMode(); |
2168 AnalysisTarget source = newSource( | 2476 AnalysisTarget source = newSource( |
2169 '/test3.dart', | 2477 '/test3.dart', |
2170 ''' | 2478 ''' |
2171 var topLevel3 = ''; | 2479 var topLevel3 = ''; |
2172 class C { | 2480 class C { |
2173 var field3 = topLevel3; | 2481 var field3 = topLevel3; |
2174 } | 2482 } |
2175 '''); | 2483 '''); |
2176 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT5); | 2484 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT5); |
2177 CompilationUnit unit = outputs[RESOLVED_UNIT5]; | 2485 CompilationUnit unit = outputs[RESOLVED_UNIT5]; |
2178 VariableDeclaration topLevelDecl = getTopLevelVariable(unit, 'topLevel3'); | 2486 VariableDeclaration topLevelDecl = getTopLevelVariable(unit, 'topLevel3'); |
2179 VariableDeclaration fieldDecl = getFieldInClass(unit, 'C', 'field3'); | 2487 VariableDeclaration fieldDecl = getFieldInClass(unit, 'C', 'field3'); |
2180 VariableElement topLevel = topLevelDecl.name.staticElement; | 2488 VariableElement topLevel = topLevelDecl.name.staticElement; |
2181 VariableElement field = fieldDecl.name.staticElement; | 2489 VariableElement field = fieldDecl.name.staticElement; |
2182 | 2490 |
2183 computeResult(field, INFERRED_STATIC_VARIABLE, | 2491 computeResult(field, INFERRED_STATIC_VARIABLE, |
2184 matcher: isInferStaticVariableTypeTask); | 2492 matcher: isInferStaticVariableTypeTask); |
2185 InterfaceType stringType = context.typeProvider.stringType; | 2493 InterfaceType stringType = context.typeProvider.stringType; |
2186 expect(topLevel.type, stringType); | 2494 expect(topLevel.type, stringType); |
2187 expect(field.type, stringType); | 2495 expect(field.type, stringType); |
2188 expect(fieldDecl.initializer.staticType, stringType); | 2496 expect(fieldDecl.initializer.staticType, stringType); |
2189 expect(outputs[INFER_STATIC_VARIABLE_ERRORS], hasLength(0)); | |
2190 } | 2497 } |
2191 | 2498 |
2192 void test_perform_const() { | 2499 void test_perform_const() { |
| 2500 enableStrongMode(); |
2193 AnalysisTarget source = newSource( | 2501 AnalysisTarget source = newSource( |
2194 '/test.dart', | 2502 '/test.dart', |
2195 ''' | 2503 ''' |
2196 const topLevel = "hello"; | 2504 const topLevel = "hello"; |
2197 class C { | 2505 class C { |
2198 var field = topLevel; | 2506 var field = topLevel; |
2199 } | 2507 } |
2200 '''); | 2508 '''); |
2201 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT5); | 2509 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT5); |
2202 CompilationUnit unit = outputs[RESOLVED_UNIT5]; | 2510 CompilationUnit unit = outputs[RESOLVED_UNIT5]; |
2203 VariableElement topLevel = | 2511 VariableElement topLevel = |
2204 getTopLevelVariable(unit, 'topLevel').name.staticElement; | 2512 getTopLevelVariable(unit, 'topLevel').name.staticElement; |
2205 VariableElement field = | 2513 VariableElement field = |
2206 getFieldInClass(unit, 'C', 'field').name.staticElement; | 2514 getFieldInClass(unit, 'C', 'field').name.staticElement; |
2207 | 2515 |
2208 computeResult(field, INFERRED_STATIC_VARIABLE, | 2516 computeResult(field, INFERRED_STATIC_VARIABLE, |
2209 matcher: isInferStaticVariableTypeTask); | 2517 matcher: isInferStaticVariableTypeTask); |
2210 InterfaceType stringType = context.typeProvider.stringType; | 2518 InterfaceType stringType = context.typeProvider.stringType; |
2211 expect(topLevel.type, stringType); | 2519 expect(topLevel.type, stringType); |
2212 expect(field.type, stringType); | 2520 expect(field.type, stringType); |
2213 expect(outputs[INFER_STATIC_VARIABLE_ERRORS], hasLength(0)); | |
2214 } | 2521 } |
2215 | 2522 |
2216 void test_perform_cycle() { | 2523 void test_perform_cycle() { |
| 2524 enableStrongMode(); |
2217 AnalysisTarget source = newSource( | 2525 AnalysisTarget source = newSource( |
2218 '/test.dart', | 2526 '/test.dart', |
2219 ''' | 2527 ''' |
2220 var piFirst = true; | 2528 var piFirst = true; |
2221 var pi = piFirst ? 3.14 : tau / 2; | 2529 var pi = piFirst ? 3.14 : tau / 2; |
2222 var tau = piFirst ? pi * 2 : 6.28; | 2530 var tau = piFirst ? pi * 2 : 6.28; |
2223 '''); | 2531 '''); |
2224 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT5); | 2532 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT5); |
2225 CompilationUnit unit = outputs[RESOLVED_UNIT5]; | 2533 CompilationUnit unit = outputs[RESOLVED_UNIT5]; |
2226 VariableElement piFirst = | 2534 VariableElement piFirst = |
2227 getTopLevelVariable(unit, 'piFirst').name.staticElement; | 2535 getTopLevelVariable(unit, 'piFirst').name.staticElement; |
2228 VariableElement pi = getTopLevelVariable(unit, 'pi').name.staticElement; | 2536 VariableElement pi = getTopLevelVariable(unit, 'pi').name.staticElement; |
2229 VariableElement tau = getTopLevelVariable(unit, 'tau').name.staticElement; | 2537 VariableElement tau = getTopLevelVariable(unit, 'tau').name.staticElement; |
2230 | 2538 |
2231 computeResult(piFirst, INFERRED_STATIC_VARIABLE, | 2539 computeResult(piFirst, INFERRED_STATIC_VARIABLE, |
2232 matcher: isInferStaticVariableTypeTask); | 2540 matcher: isInferStaticVariableTypeTask); |
2233 expect(piFirst.type, context.typeProvider.boolType); | 2541 expect(piFirst.type, context.typeProvider.boolType); |
2234 expect(pi.type.isDynamic, isTrue); | 2542 expect(pi.type.isDynamic, isTrue); |
2235 expect(tau.type.isDynamic, isTrue); | 2543 expect(tau.type.isDynamic, isTrue); |
2236 expect(outputs[INFER_STATIC_VARIABLE_ERRORS], hasLength(0)); | |
2237 } | 2544 } |
2238 | 2545 |
2239 void test_perform_error() { | 2546 void test_perform_error() { |
| 2547 enableStrongMode(); |
2240 AnalysisTarget source = newSource( | 2548 AnalysisTarget source = newSource( |
2241 '/test.dart', | 2549 '/test.dart', |
2242 ''' | 2550 ''' |
2243 var a = '' / null; | 2551 var a = '' / null; |
2244 '''); | 2552 '''); |
2245 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT5); | 2553 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT5); |
2246 CompilationUnit unit = outputs[RESOLVED_UNIT5]; | 2554 CompilationUnit unit = outputs[RESOLVED_UNIT5]; |
2247 VariableElement a = getTopLevelVariable(unit, 'a').name.staticElement; | 2555 VariableElement a = getTopLevelVariable(unit, 'a').name.staticElement; |
2248 | 2556 |
2249 computeResult(a, INFERRED_STATIC_VARIABLE, | 2557 computeResult(a, INFERRED_STATIC_VARIABLE, |
2250 matcher: isInferStaticVariableTypeTask); | 2558 matcher: isInferStaticVariableTypeTask); |
2251 expect(a.type.isDynamic, isTrue); | 2559 expect(a.type.isDynamic, isTrue); |
2252 expect(outputs[INFER_STATIC_VARIABLE_ERRORS], hasLength(1)); | |
2253 } | 2560 } |
2254 | 2561 |
2255 void test_perform_null() { | 2562 void test_perform_null() { |
| 2563 enableStrongMode(); |
2256 AnalysisTarget source = newSource( | 2564 AnalysisTarget source = newSource( |
2257 '/test.dart', | 2565 '/test.dart', |
2258 ''' | 2566 ''' |
2259 var a = null; | 2567 var a = null; |
2260 '''); | 2568 '''); |
2261 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT5); | 2569 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT5); |
2262 CompilationUnit unit = outputs[RESOLVED_UNIT5]; | 2570 CompilationUnit unit = outputs[RESOLVED_UNIT5]; |
2263 VariableElement a = getTopLevelVariable(unit, 'a').name.staticElement; | 2571 VariableElement a = getTopLevelVariable(unit, 'a').name.staticElement; |
2264 | 2572 |
2265 computeResult(a, INFERRED_STATIC_VARIABLE, | 2573 computeResult(a, INFERRED_STATIC_VARIABLE, |
2266 matcher: isInferStaticVariableTypeTask); | 2574 matcher: isInferStaticVariableTypeTask); |
2267 expect(a.type.isDynamic, isTrue); | 2575 expect(a.type.isDynamic, isTrue); |
2268 expect(outputs[INFER_STATIC_VARIABLE_ERRORS], hasLength(0)); | |
2269 } | |
2270 | |
2271 void test_perform_reresolution() { | |
2272 AnalysisTarget source = newSource( | |
2273 '/test.dart', | |
2274 ''' | |
2275 const topLevel = ''; | |
2276 class C { | |
2277 String field = topLevel; | |
2278 } | |
2279 '''); | |
2280 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT5); | |
2281 CompilationUnit unit = outputs[RESOLVED_UNIT5]; | |
2282 VariableDeclaration topLevelDecl = getTopLevelVariable(unit, 'topLevel'); | |
2283 VariableDeclaration fieldDecl = getFieldInClass(unit, 'C', 'field'); | |
2284 VariableElement topLevel = topLevelDecl.name.staticElement; | |
2285 VariableElement field = fieldDecl.name.staticElement; | |
2286 | |
2287 computeResult(field, INFERRED_STATIC_VARIABLE, | |
2288 matcher: isInferStaticVariableTypeTask); | |
2289 InterfaceType stringType = context.typeProvider.stringType; | |
2290 expect(topLevel.type, stringType); | |
2291 expect(field.type, stringType); | |
2292 expect(fieldDecl.initializer.staticType, stringType); | |
2293 expect(outputs[INFER_STATIC_VARIABLE_ERRORS], hasLength(0)); | |
2294 } | 2576 } |
2295 } | 2577 } |
2296 | 2578 |
2297 @reflectiveTest | 2579 @reflectiveTest |
2298 class LibraryErrorsReadyTaskTest extends _AbstractDartTaskTest { | 2580 class LibraryErrorsReadyTaskTest extends _AbstractDartTaskTest { |
2299 test_perform() { | 2581 test_perform() { |
2300 Source library = newSource( | 2582 Source library = newSource( |
2301 '/lib.dart', | 2583 '/lib.dart', |
2302 r''' | 2584 r''' |
2303 library lib; | 2585 library lib; |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2491 class A {} | 2773 class A {} |
2492 class C { | 2774 class C { |
2493 static final f = ''; | 2775 static final f = ''; |
2494 var g = 0; | 2776 var g = 0; |
2495 } | 2777 } |
2496 '''); | 2778 '''); |
2497 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 2779 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
2498 computeResult(target, RESOLVED_UNIT5, | 2780 computeResult(target, RESOLVED_UNIT5, |
2499 matcher: isPartiallyResolveUnitReferencesTask); | 2781 matcher: isPartiallyResolveUnitReferencesTask); |
2500 // Test the outputs | 2782 // Test the outputs |
2501 expect(outputs[INFERABLE_STATIC_VARIABLES_IN_UNIT], hasLength(5)); | 2783 expect(outputs[INFERABLE_STATIC_VARIABLES_IN_UNIT], hasLength(4)); |
2502 CompilationUnit unit = outputs[RESOLVED_UNIT5]; | 2784 CompilationUnit unit = outputs[RESOLVED_UNIT5]; |
2503 expect(unit, same(outputs[RESOLVED_UNIT5])); | 2785 expect(unit, same(outputs[RESOLVED_UNIT5])); |
2504 // Test the state of the AST | 2786 // Test the state of the AST |
2505 TopLevelVariableDeclaration a = unit.declarations[0]; | 2787 TopLevelVariableDeclaration a = unit.declarations[0]; |
2506 VariableDeclaration variableA = a.variables.variables[0]; | 2788 VariableDeclaration variableA = a.variables.variables[0]; |
2507 SimpleIdentifier initializer = variableA.initializer; | 2789 SimpleIdentifier initializer = variableA.initializer; |
2508 expect(initializer.staticElement, isNotNull); | 2790 expect(initializer.staticElement, isNotNull); |
2509 // Test the error generation | |
2510 _fillErrorListener(PARTIALLY_RESOLVE_REFERENCES_ERRORS); | |
2511 errorListener.assertNoErrors(); | |
2512 } | 2791 } |
2513 | 2792 |
2514 test_perform_importExport() { | 2793 test_perform_importExport() { |
2515 newSource( | 2794 newSource( |
2516 '/a.dart', | 2795 '/a.dart', |
2517 ''' | 2796 ''' |
2518 library a; | 2797 library a; |
2519 class A<T> { | 2798 class A<T> { |
2520 T m() {} | 2799 T m() {} |
2521 } | 2800 } |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2612 | 2891 |
2613 ConstructorDeclaration constructor = members[0]; | 2892 ConstructorDeclaration constructor = members[0]; |
2614 expectReference(constructor.body, false); | 2893 expectReference(constructor.body, false); |
2615 | 2894 |
2616 MethodDeclaration method = members[1]; | 2895 MethodDeclaration method = members[1]; |
2617 expectReference(method.body, false); | 2896 expectReference(method.body, false); |
2618 } | 2897 } |
2619 } | 2898 } |
2620 | 2899 |
2621 @reflectiveTest | 2900 @reflectiveTest |
2622 class ResolveFunctionBodiesInUnitTaskTest extends _AbstractDartTaskTest { | 2901 class ResolveInstanceFieldsInUnitTaskTest extends _AbstractDartTaskTest { |
2623 void test_perform() { | 2902 @override |
2624 AnalysisTarget source = newSource( | 2903 void setUp() { |
2625 '/test.dart', | 2904 super.setUp(); |
2626 ''' | 2905 enableStrongMode(); |
2627 void f() { | 2906 } |
2628 var c = new C(); | 2907 |
2629 c.m(); | 2908 // Test inference of instance fields across units |
2630 } | 2909 void test_perform_inference_instance() { |
2631 class C { | 2910 List<Source> sources = newSources({ |
2632 void m() { | 2911 '/a.dart': ''' |
2633 f(); | 2912 import 'b.dart'; |
2634 } | 2913 class A { |
2635 } | 2914 final a2 = new B().b2; |
2636 '''); | 2915 } |
2637 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT8, | 2916 |
2638 matcher: isResolveFunctionBodiesInUnitTask); | 2917 class B { |
2639 CompilationUnit unit = outputs[RESOLVED_UNIT8]; | 2918 final b2 = 1; |
2640 | 2919 } |
2641 FunctionDeclaration f = unit.declarations[0]; | 2920 ''', |
2642 _assertResolved(f.functionExpression.body); | 2921 '/main.dart': ''' |
2643 | 2922 import "a.dart"; |
2644 MethodDeclaration m = (unit.declarations[1] as ClassDeclaration).members[0]; | 2923 |
2645 _assertResolved(m.body); | 2924 test1() { |
2646 | 2925 int x = 0; |
2647 expect(outputs[RESOLVE_FUNCTION_BODIES_ERRORS], hasLength(0)); | 2926 x = new A().a2; |
2648 } | 2927 } |
2649 | 2928 ''' |
2650 void _assertResolved(FunctionBody body) { | 2929 }); |
2651 ResolutionVerifier verifier = new ResolutionVerifier(); | 2930 InterfaceType intType = context.typeProvider.intType; |
2652 body.accept(verifier); | 2931 DartType dynamicType = context.typeProvider.dynamicType; |
2653 verifier.assertResolved(); | 2932 |
| 2933 computeResult( |
| 2934 new LibrarySpecificUnit(sources[0], sources[0]), RESOLVED_UNIT7); |
| 2935 CompilationUnit unit0 = outputs[RESOLVED_UNIT7]; |
| 2936 |
| 2937 // A.a2 should now be resolved on the rhs, but not yet inferred. |
| 2938 assertVariableDeclarationTypes( |
| 2939 getFieldInClass(unit0, "A", "a2"), dynamicType, dynamicType); |
| 2940 |
| 2941 // B.b2 shoud be resolved on the rhs, but not yet inferred. |
| 2942 assertVariableDeclarationTypes( |
| 2943 getFieldInClass(unit0, "B", "b2"), dynamicType, intType); |
| 2944 |
| 2945 computeResult( |
| 2946 new LibrarySpecificUnit(sources[1], sources[1]), RESOLVED_UNIT7); |
| 2947 CompilationUnit unit1 = outputs[RESOLVED_UNIT7]; |
| 2948 |
| 2949 // A.a2 should now be fully resolved and inferred. |
| 2950 assertVariableDeclarationTypes( |
| 2951 getFieldInClass(unit0, "A", "a2"), dynamicType, dynamicType); |
| 2952 |
| 2953 // B.b2 should now be fully resolved and inferred. |
| 2954 assertVariableDeclarationTypes( |
| 2955 getFieldInClass(unit0, "B", "b2"), intType, intType); |
| 2956 } |
| 2957 |
| 2958 // Test inference of instance fields across units |
| 2959 void test_perform_inference_cross_unit_instance() { |
| 2960 List<Source> sources = newSources({ |
| 2961 '/a.dart': ''' |
| 2962 import 'b.dart'; |
| 2963 class A { |
| 2964 final a2 = new B().b2; |
| 2965 } |
| 2966 ''', |
| 2967 '/b.dart': ''' |
| 2968 class B { |
| 2969 final b2 = 1; |
| 2970 } |
| 2971 ''', |
| 2972 '/main.dart': ''' |
| 2973 import "a.dart"; |
| 2974 |
| 2975 test1() { |
| 2976 int x = 0; |
| 2977 x = new A().a2; |
| 2978 } |
| 2979 ''' |
| 2980 }); |
| 2981 InterfaceType intType = context.typeProvider.intType; |
| 2982 DartType dynamicType = context.typeProvider.dynamicType; |
| 2983 |
| 2984 computeResult( |
| 2985 new LibrarySpecificUnit(sources[1], sources[1]), RESOLVED_UNIT7); |
| 2986 CompilationUnit unit1 = outputs[RESOLVED_UNIT7]; |
| 2987 |
| 2988 // B.b2 shoud be resolved on the rhs, but not yet inferred. |
| 2989 assertVariableDeclarationTypes( |
| 2990 getFieldInClass(unit1, "B", "b2"), dynamicType, intType); |
| 2991 |
| 2992 computeResult( |
| 2993 new LibrarySpecificUnit(sources[0], sources[0]), RESOLVED_UNIT7); |
| 2994 CompilationUnit unit0 = outputs[RESOLVED_UNIT7]; |
| 2995 |
| 2996 // B.b2 should now be fully resolved and inferred. |
| 2997 assertVariableDeclarationTypes( |
| 2998 getFieldInClass(unit1, "B", "b2"), intType, intType); |
| 2999 |
| 3000 // A.a2 should now be resolved on the rhs, but not yet inferred. |
| 3001 assertVariableDeclarationTypes( |
| 3002 getFieldInClass(unit0, "A", "a2"), dynamicType, intType); |
| 3003 |
| 3004 computeResult( |
| 3005 new LibrarySpecificUnit(sources[2], sources[2]), RESOLVED_UNIT7); |
| 3006 CompilationUnit unit2 = outputs[RESOLVED_UNIT7]; |
| 3007 |
| 3008 // A.a2 should now be fully resolved and inferred. |
| 3009 assertVariableDeclarationTypes( |
| 3010 getFieldInClass(unit0, "A", "a2"), intType, intType); |
| 3011 |
| 3012 assertVariableDeclarationTypes( |
| 3013 getFieldInClass(unit1, "B", "b2"), intType, intType); |
| 3014 } |
| 3015 |
| 3016 // Test inference of instance fields across units with cycles |
| 3017 void test_perform_inference_cross_unit_instance_cyclic() { |
| 3018 List<Source> sources = newSources({ |
| 3019 '/a.dart': ''' |
| 3020 import 'b.dart'; |
| 3021 class A { |
| 3022 final a2 = new B().b2; |
| 3023 } |
| 3024 ''', |
| 3025 '/b.dart': ''' |
| 3026 import 'a.dart'; |
| 3027 class B { |
| 3028 final b2 = 1; |
| 3029 } |
| 3030 ''', |
| 3031 '/main.dart': ''' |
| 3032 import "a.dart"; |
| 3033 |
| 3034 test1() { |
| 3035 int x = 0; |
| 3036 x = new A().a2; |
| 3037 } |
| 3038 ''' |
| 3039 }); |
| 3040 InterfaceType intType = context.typeProvider.intType; |
| 3041 DartType dynamicType = context.typeProvider.dynamicType; |
| 3042 |
| 3043 computeResult( |
| 3044 new LibrarySpecificUnit(sources[0], sources[0]), RESOLVED_UNIT7); |
| 3045 CompilationUnit unit0 = outputs[RESOLVED_UNIT7]; |
| 3046 |
| 3047 // A.a2 should now be resolved on the rhs, but not yet inferred. |
| 3048 assertVariableDeclarationTypes( |
| 3049 getFieldInClass(unit0, "A", "a2"), dynamicType, dynamicType); |
| 3050 |
| 3051 computeResult( |
| 3052 new LibrarySpecificUnit(sources[2], sources[2]), RESOLVED_UNIT7); |
| 3053 CompilationUnit unit2 = outputs[RESOLVED_UNIT7]; |
| 3054 |
| 3055 // A.a2 should now be fully resolved and inferred. |
| 3056 assertVariableDeclarationTypes( |
| 3057 getFieldInClass(unit0, "A", "a2"), dynamicType, dynamicType); |
| 3058 } |
| 3059 |
| 3060 // Test inference between static and instance fields |
| 3061 void test_perform_inference_cross_unit_static_instance() { |
| 3062 List<Source> sources = newSources({ |
| 3063 '/a.dart': ''' |
| 3064 import 'b.dart'; |
| 3065 class A { |
| 3066 static final a1 = B.b1; |
| 3067 final a2 = new B().b2; |
| 3068 } |
| 3069 ''', |
| 3070 '/b.dart': ''' |
| 3071 class B { |
| 3072 static final b1 = 1; |
| 3073 final b2 = 1; |
| 3074 } |
| 3075 ''', |
| 3076 '/main.dart': ''' |
| 3077 import "a.dart"; |
| 3078 |
| 3079 test1() { |
| 3080 int x = 0; |
| 3081 // inference in A now works. |
| 3082 x = A.a1; |
| 3083 x = new A().a2; |
| 3084 } |
| 3085 ''' |
| 3086 }); |
| 3087 InterfaceType intType = context.typeProvider.intType; |
| 3088 DartType dynamicType = context.typeProvider.dynamicType; |
| 3089 |
| 3090 computeResult( |
| 3091 new LibrarySpecificUnit(sources[1], sources[1]), RESOLVED_UNIT7); |
| 3092 CompilationUnit unit1 = outputs[RESOLVED_UNIT7]; |
| 3093 |
| 3094 assertVariableDeclarationTypes( |
| 3095 getFieldInClass(unit1, "B", "b1"), intType, intType); |
| 3096 assertVariableDeclarationTypes( |
| 3097 getFieldInClass(unit1, "B", "b2"), dynamicType, intType); |
| 3098 |
| 3099 computeResult( |
| 3100 new LibrarySpecificUnit(sources[0], sources[0]), RESOLVED_UNIT7); |
| 3101 CompilationUnit unit0 = outputs[RESOLVED_UNIT7]; |
| 3102 |
| 3103 assertVariableDeclarationTypes( |
| 3104 getFieldInClass(unit0, "A", "a1"), intType, intType); |
| 3105 assertVariableDeclarationTypes( |
| 3106 getFieldInClass(unit0, "A", "a2"), dynamicType, intType); |
| 3107 |
| 3108 assertVariableDeclarationTypes( |
| 3109 getFieldInClass(unit1, "B", "b1"), intType, intType); |
| 3110 assertVariableDeclarationTypes( |
| 3111 getFieldInClass(unit1, "B", "b2"), intType, intType); |
| 3112 |
| 3113 computeResult( |
| 3114 new LibrarySpecificUnit(sources[2], sources[2]), RESOLVED_UNIT7); |
| 3115 CompilationUnit unit2 = outputs[RESOLVED_UNIT7]; |
| 3116 |
| 3117 assertVariableDeclarationTypes( |
| 3118 getFieldInClass(unit0, "A", "a1"), intType, intType); |
| 3119 assertVariableDeclarationTypes( |
| 3120 getFieldInClass(unit0, "A", "a2"), intType, intType); |
| 3121 |
| 3122 assertVariableDeclarationTypes( |
| 3123 getFieldInClass(unit1, "B", "b1"), intType, intType); |
| 3124 assertVariableDeclarationTypes( |
| 3125 getFieldInClass(unit1, "B", "b2"), intType, intType); |
2654 } | 3126 } |
2655 } | 3127 } |
2656 | 3128 |
2657 @reflectiveTest | 3129 @reflectiveTest |
2658 class ResolveLibraryTypeNamesTaskTest extends _AbstractDartTaskTest { | 3130 class ResolveLibraryTypeNamesTaskTest extends _AbstractDartTaskTest { |
2659 test_perform() { | 3131 test_perform() { |
2660 Source sourceLib = newSource( | 3132 Source sourceLib = newSource( |
2661 '/my_lib.dart', | 3133 '/my_lib.dart', |
2662 ''' | 3134 ''' |
2663 library my_lib; | 3135 library my_lib; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2708 { | 3180 { |
2709 ClassElement clazz = library.getType('A'); | 3181 ClassElement clazz = library.getType('A'); |
2710 expect(clazz.displayName, 'A'); | 3182 expect(clazz.displayName, 'A'); |
2711 clazz = clazz.supertype.element; | 3183 clazz = clazz.supertype.element; |
2712 expect(clazz.displayName, 'B'); | 3184 expect(clazz.displayName, 'B'); |
2713 } | 3185 } |
2714 } | 3186 } |
2715 } | 3187 } |
2716 | 3188 |
2717 @reflectiveTest | 3189 @reflectiveTest |
| 3190 class ResolveUnitTaskTest extends _AbstractDartTaskTest { |
| 3191 void test_perform() { |
| 3192 AnalysisTarget source = newSource( |
| 3193 '/test.dart', |
| 3194 ''' |
| 3195 void f() { |
| 3196 var c = new C(); |
| 3197 c.m(); |
| 3198 } |
| 3199 class C { |
| 3200 void m() { |
| 3201 f(); |
| 3202 } |
| 3203 } |
| 3204 '''); |
| 3205 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT9, |
| 3206 matcher: isResolveUnitTask); |
| 3207 CompilationUnit unit = outputs[RESOLVED_UNIT9]; |
| 3208 |
| 3209 FunctionDeclaration f = unit.declarations[0]; |
| 3210 _assertResolved(f.functionExpression.body); |
| 3211 |
| 3212 MethodDeclaration m = (unit.declarations[1] as ClassDeclaration).members[0]; |
| 3213 _assertResolved(m.body); |
| 3214 |
| 3215 expect(outputs[RESOLVE_UNIT_ERRORS], hasLength(0)); |
| 3216 } |
| 3217 |
| 3218 void _assertResolved(FunctionBody body) { |
| 3219 ResolutionVerifier verifier = new ResolutionVerifier(); |
| 3220 body.accept(verifier); |
| 3221 verifier.assertResolved(); |
| 3222 } |
| 3223 } |
| 3224 |
| 3225 @reflectiveTest |
2718 class ResolveUnitTypeNamesTaskTest extends _AbstractDartTaskTest { | 3226 class ResolveUnitTypeNamesTaskTest extends _AbstractDartTaskTest { |
2719 test_perform() { | 3227 test_perform() { |
2720 Source source = newSource( | 3228 Source source = newSource( |
2721 '/test.dart', | 3229 '/test.dart', |
2722 ''' | 3230 ''' |
2723 class A {} | 3231 class A {} |
2724 class B extends A {} | 3232 class B extends A {} |
2725 int f(String p) => p.length; | 3233 int f(String p) => p.length; |
2726 '''); | 3234 '''); |
2727 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 3235 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2927 } | 3435 } |
2928 | 3436 |
2929 void _performScanTask(String content) { | 3437 void _performScanTask(String content) { |
2930 AnalysisTarget target = newSource('/test.dart', content); | 3438 AnalysisTarget target = newSource('/test.dart', content); |
2931 computeResult(target, TOKEN_STREAM, matcher: isScanDartTask); | 3439 computeResult(target, TOKEN_STREAM, matcher: isScanDartTask); |
2932 } | 3440 } |
2933 } | 3441 } |
2934 | 3442 |
2935 @reflectiveTest | 3443 @reflectiveTest |
2936 class StrongModeInferenceTest extends _AbstractDartTaskTest { | 3444 class StrongModeInferenceTest extends _AbstractDartTaskTest { |
2937 void assertAssignmentStatementTypes( | |
2938 Statement stmt, DartType leftType, DartType rightType) { | |
2939 AssignmentExpression assgn = (stmt as ExpressionStatement).expression; | |
2940 expect(assgn.leftHandSide.staticType, leftType); | |
2941 expect(assgn.rightHandSide.staticType, rightType); | |
2942 } | |
2943 | |
2944 // Check that even within a static variable cycle, inferred | |
2945 // types get propagated to the members of the cycle. | |
2946 void assertVariableDeclarationStatementTypes( | |
2947 Statement stmt, DartType varType, DartType initializerType) { | |
2948 VariableDeclaration decl = | |
2949 (stmt as VariableDeclarationStatement).variables.variables[0]; | |
2950 assertVariableDeclarationTypes(decl, varType, initializerType); | |
2951 } | |
2952 | |
2953 void assertVariableDeclarationTypes( | |
2954 VariableDeclaration decl, DartType varType, DartType initializerType) { | |
2955 expect(decl.element.type, varType); | |
2956 expect(decl.initializer.staticType, initializerType); | |
2957 } | |
2958 | |
2959 void fail_perform_inference_cross_unit_instance() { | |
2960 List<Source> sources = newSources({ | |
2961 '/a7.dart': ''' | |
2962 import 'b7.dart'; | |
2963 class A { | |
2964 final a2 = new B().b2; | |
2965 } | |
2966 ''', | |
2967 '/b7.dart': ''' | |
2968 class B { | |
2969 final b2 = 1; | |
2970 } | |
2971 ''', | |
2972 '/main7.dart': ''' | |
2973 import "a7.dart"; | |
2974 | |
2975 test1() { | |
2976 int x = 0; | |
2977 x = new A().a2; | |
2978 } | |
2979 ''' | |
2980 }); | |
2981 List<dynamic> units = | |
2982 computeLibraryResults(sources, RESOLVED_UNIT8).toList(); | |
2983 CompilationUnit unit0 = units[0]; | |
2984 CompilationUnit unit1 = units[1]; | |
2985 CompilationUnit unit2 = units[2]; | |
2986 | |
2987 InterfaceType intType = context.typeProvider.intType; | |
2988 | |
2989 assertVariableDeclarationTypes( | |
2990 getFieldInClass(unit0, "A", "a2"), intType, intType); | |
2991 | |
2992 assertVariableDeclarationTypes( | |
2993 getFieldInClass(unit1, "B", "b2"), intType, intType); | |
2994 | |
2995 List<Statement> statements = | |
2996 getStatementsInTopLevelFunction(unit2, "test1"); | |
2997 | |
2998 assertAssignmentStatementTypes(statements[1], intType, intType); | |
2999 } | |
3000 | |
3001 void fail_perform_inference_cross_unit_static_instance() { | |
3002 List<Source> sources = newSources({ | |
3003 '/a.dart': ''' | |
3004 import 'b.dart'; | |
3005 class A { | |
3006 static final a1 = B.b1; | |
3007 final a2 = new B().b2; | |
3008 } | |
3009 ''', | |
3010 '/b.dart': ''' | |
3011 class B { | |
3012 static final b1 = 1; | |
3013 final b2 = 1; | |
3014 } | |
3015 ''', | |
3016 '/main.dart': ''' | |
3017 import "a.dart"; | |
3018 | |
3019 test1() { | |
3020 int x = 0; | |
3021 // inference in A now works. | |
3022 x = A.a1; | |
3023 x = new A().a2; | |
3024 } | |
3025 ''' | |
3026 }); | |
3027 List<dynamic> units = | |
3028 computeLibraryResults(sources, RESOLVED_UNIT8).toList(); | |
3029 CompilationUnit unit0 = units[0]; | |
3030 CompilationUnit unit1 = units[1]; | |
3031 CompilationUnit unit2 = units[2]; | |
3032 | |
3033 InterfaceType intType = context.typeProvider.intType; | |
3034 | |
3035 assertVariableDeclarationTypes( | |
3036 getFieldInClass(unit0, "A", "a1"), intType, intType); | |
3037 assertVariableDeclarationTypes( | |
3038 getFieldInClass(unit0, "A", "a2"), intType, intType); | |
3039 | |
3040 assertVariableDeclarationTypes( | |
3041 getFieldInClass(unit1, "B", "b1"), intType, intType); | |
3042 assertVariableDeclarationTypes( | |
3043 getFieldInClass(unit1, "B", "b2"), intType, intType); | |
3044 | |
3045 List<Statement> statements = | |
3046 getStatementsInTopLevelFunction(unit2, "test1"); | |
3047 | |
3048 assertAssignmentStatementTypes(statements[1], intType, intType); | |
3049 assertAssignmentStatementTypes(statements[2], intType, intType); | |
3050 } | |
3051 | |
3052 @override | 3445 @override |
3053 void setUp() { | 3446 void setUp() { |
3054 super.setUp(); | 3447 super.setUp(); |
3055 enableStrongMode(); | 3448 enableStrongMode(); |
3056 } | 3449 } |
3057 | 3450 |
3058 // Test that local variables in method bodies are inferred appropriately | 3451 // Check that even within a static variable cycle, inferred |
| 3452 // types get propagated to the members of the cycle. |
3059 void test_perform_cycle() { | 3453 void test_perform_cycle() { |
3060 AnalysisTarget source = newSource( | 3454 AnalysisTarget source = newSource( |
3061 '/test.dart', | 3455 '/test.dart', |
3062 ''' | 3456 ''' |
3063 var piFirst = true; | 3457 var piFirst = true; |
3064 var pi = piFirst ? 3.14 : tau / 2; | 3458 var pi = piFirst ? 3.14 : tau / 2; |
3065 var tau = piFirst ? pi * 2 : 6.28; | 3459 var tau = piFirst ? pi * 2 : 6.28; |
3066 '''); | 3460 '''); |
3067 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT8); | 3461 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT9); |
3068 CompilationUnit unit = outputs[RESOLVED_UNIT8]; | 3462 CompilationUnit unit = outputs[RESOLVED_UNIT9]; |
3069 VariableElement piFirst = | 3463 VariableElement piFirst = |
3070 getTopLevelVariable(unit, 'piFirst').name.staticElement; | 3464 getTopLevelVariable(unit, 'piFirst').name.staticElement; |
3071 VariableElement pi = getTopLevelVariable(unit, 'pi').name.staticElement; | 3465 VariableElement pi = getTopLevelVariable(unit, 'pi').name.staticElement; |
3072 VariableElement tau = getTopLevelVariable(unit, 'tau').name.staticElement; | 3466 VariableElement tau = getTopLevelVariable(unit, 'tau').name.staticElement; |
3073 Expression piFirstUse = (getTopLevelVariable(unit, 'tau').initializer | 3467 Expression piFirstUse = (getTopLevelVariable(unit, 'tau').initializer |
3074 as ConditionalExpression).condition; | 3468 as ConditionalExpression).condition; |
3075 | 3469 |
3076 expect(piFirstUse.staticType, context.typeProvider.boolType); | 3470 expect(piFirstUse.staticType, context.typeProvider.boolType); |
3077 expect(piFirst.type, context.typeProvider.boolType); | 3471 expect(piFirst.type, context.typeProvider.boolType); |
3078 expect(pi.type.isDynamic, isTrue); | 3472 expect(pi.type.isDynamic, isTrue); |
3079 expect(tau.type.isDynamic, isTrue); | 3473 expect(tau.type.isDynamic, isTrue); |
3080 } | 3474 } |
3081 | 3475 |
3082 // Test inference interactions between local variables and fields | 3476 void test_perform_local_explicit_disabled() { |
3083 void test_perform_inference_cross_unit_cyclic() { | 3477 AnalysisTarget source = newSource( |
3084 AnalysisTarget firstSource = newSource( | |
3085 '/a.dart', | |
3086 ''' | |
3087 import 'test.dart'; | |
3088 var x = 2; | |
3089 class A { static var x = 2; } | |
3090 '''); | |
3091 AnalysisTarget secondSource = newSource( | |
3092 '/test.dart', | 3478 '/test.dart', |
3093 ''' | 3479 ''' |
3094 import 'a.dart'; | 3480 test() { |
3095 var y = x; | 3481 int x = 3; |
3096 class B { static var y = A.x; } | 3482 x = "hi"; |
3097 | 3483 } |
3098 test1() { | |
3099 int t = 3; | |
3100 t = x; | |
3101 t = y; | |
3102 t = A.x; | |
3103 t = B.y; | |
3104 } | |
3105 '''); | 3484 '''); |
3106 computeResult( | 3485 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT9); |
3107 new LibrarySpecificUnit(firstSource, firstSource), RESOLVED_UNIT8); | 3486 CompilationUnit unit = outputs[RESOLVED_UNIT9]; |
3108 CompilationUnit unit1 = outputs[RESOLVED_UNIT8]; | |
3109 computeResult( | |
3110 new LibrarySpecificUnit(secondSource, secondSource), RESOLVED_UNIT8); | |
3111 CompilationUnit unit2 = outputs[RESOLVED_UNIT8]; | |
3112 | |
3113 InterfaceType intType = context.typeProvider.intType; | |
3114 | |
3115 assertVariableDeclarationTypes( | |
3116 getTopLevelVariable(unit1, "x"), intType, intType); | |
3117 assertVariableDeclarationTypes( | |
3118 getFieldInClass(unit1, "A", "x"), intType, intType); | |
3119 | |
3120 assertVariableDeclarationTypes( | |
3121 getTopLevelVariable(unit2, "y"), intType, intType); | |
3122 assertVariableDeclarationTypes( | |
3123 getFieldInClass(unit2, "B", "y"), intType, intType); | |
3124 | |
3125 List<Statement> statements = | |
3126 getStatementsInTopLevelFunction(unit2, "test1"); | |
3127 | |
3128 assertAssignmentStatementTypes(statements[1], intType, intType); | |
3129 assertAssignmentStatementTypes(statements[2], intType, intType); | |
3130 assertAssignmentStatementTypes(statements[3], intType, intType); | |
3131 assertAssignmentStatementTypes(statements[4], intType, intType); | |
3132 } | |
3133 | |
3134 // Test inference interactions between local variables and top level | |
3135 // variables | |
3136 void test_perform_inference_cross_unit_non_cyclic() { | |
3137 AnalysisTarget firstSource = newSource( | |
3138 '/a.dart', | |
3139 ''' | |
3140 var x = 2; | |
3141 class A { static var x = 2; } | |
3142 '''); | |
3143 AnalysisTarget secondSource = newSource( | |
3144 '/test.dart', | |
3145 ''' | |
3146 import 'a.dart'; | |
3147 var y = x; | |
3148 class B { static var y = A.x; } | |
3149 | |
3150 test1() { | |
3151 x = /*severe:StaticTypeError*/"hi"; | |
3152 y = /*severe:StaticTypeError*/"hi"; | |
3153 A.x = /*severe:StaticTypeError*/"hi"; | |
3154 B.y = /*severe:StaticTypeError*/"hi"; | |
3155 } | |
3156 '''); | |
3157 computeResult( | |
3158 new LibrarySpecificUnit(firstSource, firstSource), RESOLVED_UNIT8); | |
3159 CompilationUnit unit1 = outputs[RESOLVED_UNIT8]; | |
3160 computeResult( | |
3161 new LibrarySpecificUnit(secondSource, secondSource), RESOLVED_UNIT8); | |
3162 CompilationUnit unit2 = outputs[RESOLVED_UNIT8]; | |
3163 | 3487 |
3164 InterfaceType intType = context.typeProvider.intType; | 3488 InterfaceType intType = context.typeProvider.intType; |
3165 InterfaceType stringType = context.typeProvider.stringType; | 3489 InterfaceType stringType = context.typeProvider.stringType; |
3166 | 3490 |
3167 assertVariableDeclarationTypes( | 3491 List<Statement> statements = getStatementsInTopLevelFunction(unit, "test"); |
3168 getTopLevelVariable(unit1, "x"), intType, intType); | 3492 VariableDeclaration decl = |
3169 assertVariableDeclarationTypes( | 3493 (statements[0] as VariableDeclarationStatement).variables.variables[0]; |
3170 getFieldInClass(unit1, "A", "x"), intType, intType); | 3494 expect(decl.element.type, intType); |
| 3495 expect(decl.initializer.staticType, intType); |
3171 | 3496 |
3172 assertVariableDeclarationTypes( | 3497 ExpressionStatement statement = statements[1]; |
3173 getTopLevelVariable(unit2, "y"), intType, intType); | 3498 AssignmentExpression assgn = statement.expression; |
3174 assertVariableDeclarationTypes( | 3499 expect(assgn.leftHandSide.staticType, intType); |
3175 getFieldInClass(unit2, "B", "y"), intType, intType); | 3500 expect(assgn.rightHandSide.staticType, stringType); |
3176 | |
3177 List<Statement> statements = | |
3178 getStatementsInTopLevelFunction(unit2, "test1"); | |
3179 | |
3180 assertAssignmentStatementTypes(statements[0], intType, stringType); | |
3181 assertAssignmentStatementTypes(statements[1], intType, stringType); | |
3182 } | 3501 } |
3183 | 3502 |
3184 // Test that inference does not propagate from null | 3503 // Test that local variables in method bodies are inferred appropriately |
3185 void test_perform_inference_local_variables() { | 3504 void test_perform_inference_local_variables() { |
3186 AnalysisTarget source = newSource( | 3505 AnalysisTarget source = newSource( |
3187 '/test.dart', | 3506 '/test.dart', |
3188 ''' | 3507 ''' |
3189 test() { | 3508 test() { |
3190 int x = 3; | 3509 int x = 3; |
3191 x = "hi"; | 3510 x = "hi"; |
3192 var y = 3; | 3511 var y = 3; |
3193 y = "hi"; | 3512 y = "hi"; |
3194 } | 3513 } |
3195 '''); | 3514 '''); |
3196 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT8); | 3515 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT9); |
3197 CompilationUnit unit = outputs[RESOLVED_UNIT8]; | 3516 CompilationUnit unit = outputs[RESOLVED_UNIT9]; |
3198 | 3517 |
3199 InterfaceType intType = context.typeProvider.intType; | 3518 InterfaceType intType = context.typeProvider.intType; |
3200 InterfaceType stringType = context.typeProvider.stringType; | 3519 InterfaceType stringType = context.typeProvider.stringType; |
3201 | 3520 |
3202 List<Statement> statements = getStatementsInTopLevelFunction(unit, "test"); | 3521 List<Statement> statements = getStatementsInTopLevelFunction(unit, "test"); |
3203 | 3522 |
3204 assertVariableDeclarationStatementTypes(statements[0], intType, intType); | 3523 assertVariableDeclarationStatementTypes(statements[0], intType, intType); |
3205 assertAssignmentStatementTypes(statements[1], intType, stringType); | 3524 assertAssignmentStatementTypes(statements[1], intType, stringType); |
3206 assertVariableDeclarationStatementTypes(statements[2], intType, intType); | 3525 assertVariableDeclarationStatementTypes(statements[2], intType, intType); |
3207 assertAssignmentStatementTypes(statements[3], intType, stringType); | 3526 assertAssignmentStatementTypes(statements[3], intType, stringType); |
3208 } | 3527 } |
3209 | 3528 |
3210 // Test inference across units (non-cyclic) | 3529 // Test inference interactions between local variables and fields |
3211 void test_perform_inference_local_variables_fields() { | 3530 void test_perform_inference_local_variables_fields() { |
3212 AnalysisTarget source = newSource( | 3531 AnalysisTarget source = newSource( |
3213 '/test.dart', | 3532 '/test.dart', |
3214 ''' | 3533 ''' |
3215 class A { | 3534 class A { |
3216 int x = 0; | 3535 int x = 0; |
3217 | 3536 |
3218 test1() { | 3537 test1() { |
3219 var a = x; | 3538 var a = x; |
3220 a = "hi"; | 3539 a = "hi"; |
3221 a = 3; | 3540 a = 3; |
3222 var b = y; | 3541 var b = y; |
3223 b = "hi"; | 3542 b = "hi"; |
3224 b = 4; | 3543 b = 4; |
3225 var c = z; | 3544 var c = z; |
3226 c = "hi"; | 3545 c = "hi"; |
3227 c = 4; | 3546 c = 4; |
3228 } | 3547 } |
3229 | 3548 |
3230 int y; // field def after use | 3549 int y; // field def after use |
3231 final z = 42; // should infer `int` | 3550 final z = 42; // should infer `int` |
3232 } | 3551 } |
3233 '''); | 3552 '''); |
3234 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT8); | 3553 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT9); |
3235 CompilationUnit unit = outputs[RESOLVED_UNIT8]; | 3554 CompilationUnit unit = outputs[RESOLVED_UNIT9]; |
3236 | 3555 |
3237 InterfaceType intType = context.typeProvider.intType; | 3556 InterfaceType intType = context.typeProvider.intType; |
3238 InterfaceType stringType = context.typeProvider.stringType; | 3557 InterfaceType stringType = context.typeProvider.stringType; |
3239 | 3558 |
3240 List<Statement> statements = getStatementsInMethod(unit, "A", "test1"); | 3559 List<Statement> statements = getStatementsInMethod(unit, "A", "test1"); |
3241 | 3560 |
3242 assertVariableDeclarationStatementTypes(statements[0], intType, intType); | 3561 assertVariableDeclarationStatementTypes(statements[0], intType, intType); |
3243 assertAssignmentStatementTypes(statements[1], intType, stringType); | 3562 assertAssignmentStatementTypes(statements[1], intType, stringType); |
3244 assertAssignmentStatementTypes(statements[2], intType, intType); | 3563 assertAssignmentStatementTypes(statements[2], intType, intType); |
3245 | 3564 |
3246 assertVariableDeclarationStatementTypes(statements[3], intType, intType); | 3565 assertVariableDeclarationStatementTypes(statements[3], intType, intType); |
3247 assertAssignmentStatementTypes(statements[4], intType, stringType); | 3566 assertAssignmentStatementTypes(statements[4], intType, stringType); |
3248 assertAssignmentStatementTypes(statements[5], intType, intType); | 3567 assertAssignmentStatementTypes(statements[5], intType, intType); |
3249 | 3568 |
3250 assertVariableDeclarationStatementTypes(statements[6], intType, intType); | 3569 assertVariableDeclarationStatementTypes(statements[6], intType, intType); |
3251 assertAssignmentStatementTypes(statements[7], intType, stringType); | 3570 assertAssignmentStatementTypes(statements[7], intType, stringType); |
3252 assertAssignmentStatementTypes(statements[8], intType, intType); | 3571 assertAssignmentStatementTypes(statements[8], intType, intType); |
3253 | 3572 |
3254 assertVariableDeclarationTypes( | 3573 assertVariableDeclarationTypes( |
3255 getFieldInClass(unit, "A", "x"), intType, intType); | 3574 getFieldInClass(unit, "A", "x"), intType, intType); |
3256 assertVariableDeclarationTypes( | 3575 assertVariableDeclarationTypes( |
3257 getFieldInClass(unit, "A", "z"), intType, intType); | 3576 getFieldInClass(unit, "A", "z"), intType, intType); |
3258 } | 3577 } |
3259 | 3578 |
3260 // Test inference across units (cyclic) | 3579 // Test inference interactions between local variables and top level |
| 3580 // variables |
3261 void test_perform_inference_local_variables_topLevel() { | 3581 void test_perform_inference_local_variables_topLevel() { |
3262 AnalysisTarget source = newSource( | 3582 AnalysisTarget source = newSource( |
3263 '/test.dart', | 3583 '/test.dart', |
3264 ''' | 3584 ''' |
3265 int x = 0; | 3585 int x = 0; |
3266 | 3586 |
3267 test1() { | 3587 test1() { |
3268 var a = x; | 3588 var a = x; |
3269 a = /*severe:StaticTypeError*/"hi"; | 3589 a = /*severe:StaticTypeError*/"hi"; |
3270 a = 3; | 3590 a = 3; |
3271 var b = y; | 3591 var b = y; |
3272 b = /*severe:StaticTypeError*/"hi"; | 3592 b = /*severe:StaticTypeError*/"hi"; |
3273 b = 4; | 3593 b = 4; |
3274 var c = z; | 3594 var c = z; |
3275 c = /*severe:StaticTypeError*/"hi"; | 3595 c = /*severe:StaticTypeError*/"hi"; |
3276 c = 4; | 3596 c = 4; |
3277 } | 3597 } |
3278 | 3598 |
3279 int y = 0; // field def after use | 3599 int y = 0; // field def after use |
3280 final z = 42; // should infer `int` | 3600 final z = 42; // should infer `int` |
3281 '''); | 3601 '''); |
3282 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT8); | 3602 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT9); |
3283 CompilationUnit unit = outputs[RESOLVED_UNIT8]; | 3603 CompilationUnit unit = outputs[RESOLVED_UNIT9]; |
3284 | 3604 |
3285 InterfaceType intType = context.typeProvider.intType; | 3605 InterfaceType intType = context.typeProvider.intType; |
3286 InterfaceType stringType = context.typeProvider.stringType; | 3606 InterfaceType stringType = context.typeProvider.stringType; |
3287 | 3607 |
3288 List<Statement> statements = getStatementsInTopLevelFunction(unit, "test1"); | 3608 List<Statement> statements = getStatementsInTopLevelFunction(unit, "test1"); |
3289 | 3609 |
3290 assertVariableDeclarationStatementTypes(statements[0], intType, intType); | 3610 assertVariableDeclarationStatementTypes(statements[0], intType, intType); |
3291 assertAssignmentStatementTypes(statements[1], intType, stringType); | 3611 assertAssignmentStatementTypes(statements[1], intType, stringType); |
3292 assertAssignmentStatementTypes(statements[2], intType, intType); | 3612 assertAssignmentStatementTypes(statements[2], intType, intType); |
3293 | 3613 |
3294 assertVariableDeclarationStatementTypes(statements[3], intType, intType); | 3614 assertVariableDeclarationStatementTypes(statements[3], intType, intType); |
3295 assertAssignmentStatementTypes(statements[4], intType, stringType); | 3615 assertAssignmentStatementTypes(statements[4], intType, stringType); |
3296 assertAssignmentStatementTypes(statements[5], intType, intType); | 3616 assertAssignmentStatementTypes(statements[5], intType, intType); |
3297 | 3617 |
3298 assertVariableDeclarationStatementTypes(statements[6], intType, intType); | 3618 assertVariableDeclarationStatementTypes(statements[6], intType, intType); |
3299 assertAssignmentStatementTypes(statements[7], intType, stringType); | 3619 assertAssignmentStatementTypes(statements[7], intType, stringType); |
3300 assertAssignmentStatementTypes(statements[8], intType, intType); | 3620 assertAssignmentStatementTypes(statements[8], intType, intType); |
3301 | 3621 |
3302 assertVariableDeclarationTypes( | 3622 assertVariableDeclarationTypes( |
3303 getTopLevelVariable(unit, "x"), intType, intType); | 3623 getTopLevelVariable(unit, "x"), intType, intType); |
3304 assertVariableDeclarationTypes( | 3624 assertVariableDeclarationTypes( |
3305 getTopLevelVariable(unit, "y"), intType, intType); | 3625 getTopLevelVariable(unit, "y"), intType, intType); |
3306 assertVariableDeclarationTypes( | 3626 assertVariableDeclarationTypes( |
3307 getTopLevelVariable(unit, "z"), intType, intType); | 3627 getTopLevelVariable(unit, "z"), intType, intType); |
3308 } | 3628 } |
3309 | 3629 |
3310 // Test inference of instance fields across units | 3630 // Test that inference does not propagate from null |
3311 // TODO(leafp): Fix this | |
3312 // https://github.com/dart-lang/dev_compiler/issues/354 | |
3313 void test_perform_inference_null() { | 3631 void test_perform_inference_null() { |
3314 AnalysisTarget source = newSource( | 3632 AnalysisTarget source = newSource( |
3315 '/test.dart', | 3633 '/test.dart', |
3316 ''' | 3634 ''' |
3317 var x = null; | 3635 var x = null; |
3318 var y = 3; | 3636 var y = 3; |
3319 class A { | 3637 class A { |
3320 static var x = null; | 3638 static var x = null; |
3321 static var y = 3; | 3639 static var y = 3; |
3322 | 3640 |
3323 var x2 = null; | 3641 var x2 = null; |
3324 var y2 = 3; | 3642 var y2 = 3; |
3325 } | 3643 } |
3326 | 3644 |
3327 test() { | 3645 test() { |
3328 x = "hi"; | 3646 x = "hi"; |
3329 y = /*severe:StaticTypeError*/"hi"; | 3647 y = /*severe:StaticTypeError*/"hi"; |
3330 A.x = "hi"; | 3648 A.x = "hi"; |
3331 A.y = /*severe:StaticTypeError*/"hi"; | 3649 A.y = /*severe:StaticTypeError*/"hi"; |
3332 new A().x2 = "hi"; | 3650 new A().x2 = "hi"; |
3333 new A().y2 = /*severe:StaticTypeError*/"hi"; | 3651 new A().y2 = /*severe:StaticTypeError*/"hi"; |
3334 } | 3652 } |
3335 '''); | 3653 '''); |
3336 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT8); | 3654 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT9); |
3337 CompilationUnit unit = outputs[RESOLVED_UNIT8]; | 3655 CompilationUnit unit = outputs[RESOLVED_UNIT9]; |
3338 | 3656 |
3339 InterfaceType intType = context.typeProvider.intType; | 3657 InterfaceType intType = context.typeProvider.intType; |
3340 InterfaceType stringType = context.typeProvider.stringType; | 3658 InterfaceType stringType = context.typeProvider.stringType; |
3341 DartType bottomType = context.typeProvider.bottomType; | 3659 DartType bottomType = context.typeProvider.bottomType; |
3342 DartType dynamicType = context.typeProvider.dynamicType; | 3660 DartType dynamicType = context.typeProvider.dynamicType; |
3343 | 3661 |
3344 assertVariableDeclarationTypes( | 3662 assertVariableDeclarationTypes( |
3345 getTopLevelVariable(unit, "x"), dynamicType, bottomType); | 3663 getTopLevelVariable(unit, "x"), dynamicType, bottomType); |
3346 assertVariableDeclarationTypes( | 3664 assertVariableDeclarationTypes( |
3347 getTopLevelVariable(unit, "y"), intType, intType); | 3665 getTopLevelVariable(unit, "y"), intType, intType); |
3348 assertVariableDeclarationTypes( | 3666 assertVariableDeclarationTypes( |
3349 getFieldInClass(unit, "A", "x"), dynamicType, bottomType); | 3667 getFieldInClass(unit, "A", "x"), dynamicType, bottomType); |
3350 assertVariableDeclarationTypes( | 3668 assertVariableDeclarationTypes( |
3351 getFieldInClass(unit, "A", "y"), intType, intType); | 3669 getFieldInClass(unit, "A", "y"), intType, intType); |
3352 assertVariableDeclarationTypes( | 3670 assertVariableDeclarationTypes( |
3353 getFieldInClass(unit, "A", "x2"), dynamicType, bottomType); | 3671 getFieldInClass(unit, "A", "x2"), dynamicType, bottomType); |
3354 assertVariableDeclarationTypes( | 3672 assertVariableDeclarationTypes( |
3355 getFieldInClass(unit, "A", "y2"), intType, intType); | 3673 getFieldInClass(unit, "A", "y2"), intType, intType); |
3356 | 3674 |
3357 List<Statement> statements = getStatementsInTopLevelFunction(unit, "test"); | 3675 List<Statement> statements = getStatementsInTopLevelFunction(unit, "test"); |
3358 | 3676 |
3359 assertAssignmentStatementTypes(statements[0], dynamicType, stringType); | 3677 assertAssignmentStatementTypes(statements[0], dynamicType, stringType); |
3360 assertAssignmentStatementTypes(statements[1], intType, stringType); | 3678 assertAssignmentStatementTypes(statements[1], intType, stringType); |
3361 assertAssignmentStatementTypes(statements[2], dynamicType, stringType); | 3679 assertAssignmentStatementTypes(statements[2], dynamicType, stringType); |
3362 assertAssignmentStatementTypes(statements[3], intType, stringType); | 3680 assertAssignmentStatementTypes(statements[3], intType, stringType); |
3363 assertAssignmentStatementTypes(statements[4], dynamicType, stringType); | 3681 assertAssignmentStatementTypes(statements[4], dynamicType, stringType); |
3364 assertAssignmentStatementTypes(statements[5], intType, stringType); | 3682 assertAssignmentStatementTypes(statements[5], intType, stringType); |
3365 } | 3683 } |
3366 | 3684 |
| 3685 // Test inference across units (non-cyclic) |
| 3686 void test_perform_inference_cross_unit_non_cyclic() { |
| 3687 AnalysisTarget firstSource = newSource( |
| 3688 '/a.dart', |
| 3689 ''' |
| 3690 var x = 2; |
| 3691 class A { static var x = 2; } |
| 3692 '''); |
| 3693 AnalysisTarget secondSource = newSource( |
| 3694 '/test.dart', |
| 3695 ''' |
| 3696 import 'a.dart'; |
| 3697 var y = x; |
| 3698 class B { static var y = A.x; } |
| 3699 |
| 3700 test1() { |
| 3701 x = /*severe:StaticTypeError*/"hi"; |
| 3702 y = /*severe:StaticTypeError*/"hi"; |
| 3703 A.x = /*severe:StaticTypeError*/"hi"; |
| 3704 B.y = /*severe:StaticTypeError*/"hi"; |
| 3705 } |
| 3706 '''); |
| 3707 computeResult( |
| 3708 new LibrarySpecificUnit(firstSource, firstSource), RESOLVED_UNIT9); |
| 3709 CompilationUnit unit1 = outputs[RESOLVED_UNIT9]; |
| 3710 computeResult( |
| 3711 new LibrarySpecificUnit(secondSource, secondSource), RESOLVED_UNIT9); |
| 3712 CompilationUnit unit2 = outputs[RESOLVED_UNIT9]; |
| 3713 |
| 3714 InterfaceType intType = context.typeProvider.intType; |
| 3715 InterfaceType stringType = context.typeProvider.stringType; |
| 3716 |
| 3717 assertVariableDeclarationTypes( |
| 3718 getTopLevelVariable(unit1, "x"), intType, intType); |
| 3719 assertVariableDeclarationTypes( |
| 3720 getFieldInClass(unit1, "A", "x"), intType, intType); |
| 3721 |
| 3722 assertVariableDeclarationTypes( |
| 3723 getTopLevelVariable(unit2, "y"), intType, intType); |
| 3724 assertVariableDeclarationTypes( |
| 3725 getFieldInClass(unit2, "B", "y"), intType, intType); |
| 3726 |
| 3727 List<Statement> statements = |
| 3728 getStatementsInTopLevelFunction(unit2, "test1"); |
| 3729 |
| 3730 assertAssignmentStatementTypes(statements[0], intType, stringType); |
| 3731 assertAssignmentStatementTypes(statements[1], intType, stringType); |
| 3732 } |
| 3733 |
| 3734 // Test inference across units (cyclic) |
| 3735 void test_perform_inference_cross_unit_cyclic() { |
| 3736 AnalysisTarget firstSource = newSource( |
| 3737 '/a.dart', |
| 3738 ''' |
| 3739 import 'test.dart'; |
| 3740 var x = 2; |
| 3741 class A { static var x = 2; } |
| 3742 '''); |
| 3743 AnalysisTarget secondSource = newSource( |
| 3744 '/test.dart', |
| 3745 ''' |
| 3746 import 'a.dart'; |
| 3747 var y = x; |
| 3748 class B { static var y = A.x; } |
| 3749 |
| 3750 test1() { |
| 3751 int t = 3; |
| 3752 t = x; |
| 3753 t = y; |
| 3754 t = A.x; |
| 3755 t = B.y; |
| 3756 } |
| 3757 '''); |
| 3758 computeResult( |
| 3759 new LibrarySpecificUnit(firstSource, firstSource), RESOLVED_UNIT9); |
| 3760 CompilationUnit unit1 = outputs[RESOLVED_UNIT9]; |
| 3761 computeResult( |
| 3762 new LibrarySpecificUnit(secondSource, secondSource), RESOLVED_UNIT9); |
| 3763 CompilationUnit unit2 = outputs[RESOLVED_UNIT9]; |
| 3764 |
| 3765 InterfaceType intType = context.typeProvider.intType; |
| 3766 |
| 3767 assertVariableDeclarationTypes( |
| 3768 getTopLevelVariable(unit1, "x"), intType, intType); |
| 3769 assertVariableDeclarationTypes( |
| 3770 getFieldInClass(unit1, "A", "x"), intType, intType); |
| 3771 |
| 3772 assertVariableDeclarationTypes( |
| 3773 getTopLevelVariable(unit2, "y"), intType, intType); |
| 3774 assertVariableDeclarationTypes( |
| 3775 getFieldInClass(unit2, "B", "y"), intType, intType); |
| 3776 |
| 3777 List<Statement> statements = |
| 3778 getStatementsInTopLevelFunction(unit2, "test1"); |
| 3779 |
| 3780 assertAssignmentStatementTypes(statements[1], intType, intType); |
| 3781 assertAssignmentStatementTypes(statements[2], intType, intType); |
| 3782 assertAssignmentStatementTypes(statements[3], intType, intType); |
| 3783 assertAssignmentStatementTypes(statements[4], intType, intType); |
| 3784 } |
| 3785 |
| 3786 // Test inference of instance fields across units |
| 3787 void test_perform_inference_cross_unit_instance() { |
| 3788 List<Source> sources = newSources({ |
| 3789 '/a.dart': ''' |
| 3790 import 'b.dart'; |
| 3791 class A { |
| 3792 final a2 = new B().b2; |
| 3793 } |
| 3794 ''', |
| 3795 '/b.dart': ''' |
| 3796 class B { |
| 3797 final b2 = 1; |
| 3798 } |
| 3799 ''', |
| 3800 '/main.dart': ''' |
| 3801 import "a.dart"; |
| 3802 |
| 3803 test1() { |
| 3804 int x = 0; |
| 3805 x = new A().a2; |
| 3806 } |
| 3807 ''' |
| 3808 }); |
| 3809 List<dynamic> units = |
| 3810 computeLibraryResults(sources, RESOLVED_UNIT9).toList(); |
| 3811 CompilationUnit unit0 = units[0]; |
| 3812 CompilationUnit unit1 = units[1]; |
| 3813 CompilationUnit unit2 = units[2]; |
| 3814 |
| 3815 InterfaceType intType = context.typeProvider.intType; |
| 3816 |
| 3817 assertVariableDeclarationTypes( |
| 3818 getFieldInClass(unit0, "A", "a2"), intType, intType); |
| 3819 |
| 3820 assertVariableDeclarationTypes( |
| 3821 getFieldInClass(unit1, "B", "b2"), intType, intType); |
| 3822 |
| 3823 List<Statement> statements = |
| 3824 getStatementsInTopLevelFunction(unit2, "test1"); |
| 3825 |
| 3826 assertAssignmentStatementTypes(statements[1], intType, intType); |
| 3827 } |
| 3828 |
3367 // Test inference between static and instance fields | 3829 // Test inference between static and instance fields |
3368 // TODO(leafp): Fix this | 3830 void test_perform_inference_cross_unit_static_instance() { |
3369 // https://github.com/dart-lang/dev_compiler/issues/354 | 3831 List<Source> sources = newSources({ |
3370 void test_perform_local_explicit_disabled() { | 3832 '/a.dart': ''' |
3371 AnalysisTarget source = newSource( | 3833 import 'b.dart'; |
3372 '/test.dart', | 3834 class A { |
3373 ''' | 3835 static final a1 = B.b1; |
3374 test() { | 3836 final a2 = new B().b2; |
3375 int x = 3; | 3837 } |
3376 x = "hi"; | 3838 ''', |
3377 } | 3839 '/b.dart': ''' |
3378 '''); | 3840 class B { |
3379 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT8); | 3841 static final b1 = 1; |
3380 CompilationUnit unit = outputs[RESOLVED_UNIT8]; | 3842 final b2 = 1; |
| 3843 } |
| 3844 ''', |
| 3845 '/main.dart': ''' |
| 3846 import "a.dart"; |
| 3847 |
| 3848 test1() { |
| 3849 int x = 0; |
| 3850 // inference in A now works. |
| 3851 x = A.a1; |
| 3852 x = new A().a2; |
| 3853 } |
| 3854 ''' |
| 3855 }); |
| 3856 List<dynamic> units = |
| 3857 computeLibraryResults(sources, RESOLVED_UNIT9).toList(); |
| 3858 CompilationUnit unit0 = units[0]; |
| 3859 CompilationUnit unit1 = units[1]; |
| 3860 CompilationUnit unit2 = units[2]; |
| 3861 |
| 3862 InterfaceType intType = context.typeProvider.intType; |
| 3863 |
| 3864 assertVariableDeclarationTypes( |
| 3865 getFieldInClass(unit0, "A", "a1"), intType, intType); |
| 3866 assertVariableDeclarationTypes( |
| 3867 getFieldInClass(unit0, "A", "a2"), intType, intType); |
| 3868 |
| 3869 assertVariableDeclarationTypes( |
| 3870 getFieldInClass(unit1, "B", "b1"), intType, intType); |
| 3871 assertVariableDeclarationTypes( |
| 3872 getFieldInClass(unit1, "B", "b2"), intType, intType); |
| 3873 |
| 3874 List<Statement> statements = |
| 3875 getStatementsInTopLevelFunction(unit2, "test1"); |
| 3876 |
| 3877 assertAssignmentStatementTypes(statements[1], intType, intType); |
| 3878 assertAssignmentStatementTypes(statements[2], intType, intType); |
| 3879 } |
| 3880 |
| 3881 // Test inference between fields and method bodies |
| 3882 void test_perform_inference_cross_unit_instance_member() { |
| 3883 List<Source> sources = newSources({ |
| 3884 '/a.dart': ''' |
| 3885 import 'b.dart'; |
| 3886 var bar = new B(); |
| 3887 void foo() { |
| 3888 String x = bar.f.z; |
| 3889 } |
| 3890 ''', |
| 3891 '/b.dart': ''' |
| 3892 class C { |
| 3893 var z = 3; |
| 3894 } |
| 3895 |
| 3896 class B { |
| 3897 var f = new C(); |
| 3898 } |
| 3899 ''', |
| 3900 '/c.dart': ''' |
| 3901 import 'b.dart'; |
| 3902 var bar = new B(); |
| 3903 void foo() { |
| 3904 String x = bar.f.z; |
| 3905 } |
| 3906 ''' |
| 3907 }); |
| 3908 List<dynamic> units = |
| 3909 computeLibraryResults(sources, RESOLVED_UNIT9).toList(); |
| 3910 CompilationUnit unit0 = units[0]; |
| 3911 CompilationUnit unit1 = units[1]; |
| 3912 CompilationUnit unit2 = units[2]; |
3381 | 3913 |
3382 InterfaceType intType = context.typeProvider.intType; | 3914 InterfaceType intType = context.typeProvider.intType; |
3383 InterfaceType stringType = context.typeProvider.stringType; | 3915 InterfaceType stringType = context.typeProvider.stringType; |
3384 | 3916 |
3385 List<Statement> statements = getStatementsInTopLevelFunction(unit, "test"); | 3917 assertVariableDeclarationStatementTypes( |
3386 VariableDeclaration decl = | 3918 getStatementsInTopLevelFunction(unit0, "foo")[0], stringType, intType); |
3387 (statements[0] as VariableDeclarationStatement).variables.variables[0]; | 3919 assertVariableDeclarationStatementTypes( |
3388 expect(decl.element.type, intType); | 3920 getStatementsInTopLevelFunction(unit2, "foo")[0], stringType, intType); |
3389 expect(decl.initializer.staticType, intType); | |
3390 | |
3391 ExpressionStatement statement = statements[1]; | |
3392 AssignmentExpression assgn = statement.expression; | |
3393 expect(assgn.leftHandSide.staticType, intType); | |
3394 expect(assgn.rightHandSide.staticType, stringType); | |
3395 } | 3921 } |
3396 } | 3922 } |
3397 | 3923 |
3398 @reflectiveTest | 3924 @reflectiveTest |
3399 class VerifyUnitTaskTest extends _AbstractDartTaskTest { | 3925 class VerifyUnitTaskTest extends _AbstractDartTaskTest { |
3400 test_perform_constantError() { | 3926 test_perform_constantError() { |
3401 Source source = newSource( | 3927 Source source = newSource( |
3402 '/test.dart', | 3928 '/test.dart', |
3403 ''' | 3929 ''' |
3404 main(int p) { | 3930 main(int p) { |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3462 errorListener.assertErrorsWithCodes( | 3988 errorListener.assertErrorsWithCodes( |
3463 <ErrorCode>[StaticTypeWarningCode.NON_BOOL_CONDITION]); | 3989 <ErrorCode>[StaticTypeWarningCode.NON_BOOL_CONDITION]); |
3464 } | 3990 } |
3465 } | 3991 } |
3466 | 3992 |
3467 class _AbstractDartTaskTest extends AbstractContextTest { | 3993 class _AbstractDartTaskTest extends AbstractContextTest { |
3468 Source emptySource; | 3994 Source emptySource; |
3469 | 3995 |
3470 GatheringErrorListener errorListener = new GatheringErrorListener(); | 3996 GatheringErrorListener errorListener = new GatheringErrorListener(); |
3471 | 3997 |
| 3998 void assertAssignmentStatementTypes( |
| 3999 Statement stmt, DartType leftType, DartType rightType) { |
| 4000 AssignmentExpression assgn = (stmt as ExpressionStatement).expression; |
| 4001 expect(assgn.leftHandSide.staticType, leftType); |
| 4002 expect(assgn.rightHandSide.staticType, rightType); |
| 4003 } |
| 4004 |
3472 void assertIsInvalid(AnalysisTarget target, ResultDescriptor descriptor) { | 4005 void assertIsInvalid(AnalysisTarget target, ResultDescriptor descriptor) { |
3473 CacheEntry entry = context.getCacheEntry(target); | 4006 CacheEntry entry = context.getCacheEntry(target); |
3474 expect(entry.isInvalid(descriptor), isTrue); | 4007 expect(entry.isInvalid(descriptor), isTrue); |
3475 } | 4008 } |
3476 | 4009 |
3477 void assertIsValid(AnalysisTarget target, ResultDescriptor descriptor) { | 4010 void assertIsValid(AnalysisTarget target, ResultDescriptor descriptor) { |
3478 CacheEntry entry = context.getCacheEntry(target); | 4011 CacheEntry entry = context.getCacheEntry(target); |
3479 expect(entry.isValid(descriptor), isTrue); | 4012 expect(entry.isValid(descriptor), isTrue); |
3480 } | 4013 } |
3481 | 4014 |
3482 void assertSameResults(List<ResultDescriptor> descriptors) { | 4015 void assertSameResults(List<ResultDescriptor> descriptors) { |
3483 descriptors.forEach((descriptor) { | 4016 descriptors.forEach((descriptor) { |
3484 var oldResult = oldOutputs[descriptor]; | 4017 var oldResult = oldOutputs[descriptor]; |
3485 var newResult = outputs[descriptor]; | 4018 var newResult = outputs[descriptor]; |
3486 expect(newResult, same(oldResult), reason: descriptor.name); | 4019 expect(newResult, same(oldResult), reason: descriptor.name); |
3487 }); | 4020 }); |
3488 } | 4021 } |
3489 | 4022 |
| 4023 void assertVariableDeclarationTypes( |
| 4024 VariableDeclaration decl, DartType varType, DartType initializerType) { |
| 4025 expect(decl.element.type, varType); |
| 4026 expect(decl.initializer.staticType, initializerType); |
| 4027 } |
| 4028 |
| 4029 void assertVariableDeclarationStatementTypes( |
| 4030 Statement stmt, DartType varType, DartType initializerType) { |
| 4031 VariableDeclaration decl = |
| 4032 (stmt as VariableDeclarationStatement).variables.variables[0]; |
| 4033 assertVariableDeclarationTypes(decl, varType, initializerType); |
| 4034 } |
| 4035 |
3490 List<dynamic> computeLibraryResults( | 4036 List<dynamic> computeLibraryResults( |
3491 List<Source> sources, ResultDescriptor result, | 4037 List<Source> sources, ResultDescriptor result, |
3492 {isInstanceOf matcher: null}) { | 4038 {isInstanceOf matcher: null}) { |
3493 dynamic compute(Source source) { | 4039 dynamic compute(Source source) { |
3494 computeResult(new LibrarySpecificUnit(source, source), result, | 4040 computeResult(new LibrarySpecificUnit(source, source), result, |
3495 matcher: matcher); | 4041 matcher: matcher); |
3496 return outputs[result]; | 4042 return outputs[result]; |
3497 } | 4043 } |
3498 return sources.map(compute).toList(); | 4044 return sources.map(compute).toList(); |
3499 } | 4045 } |
3500 | 4046 |
| 4047 List<Map<ResultDescriptor, dynamic>> computeLibraryResultsMap( |
| 4048 List<Source> sources, ResultDescriptor result, |
| 4049 {isInstanceOf matcher: null}) { |
| 4050 Map<ResultDescriptor, dynamic> compute(Source source) { |
| 4051 computeResult(new LibrarySpecificUnit(source, source), result, |
| 4052 matcher: matcher); |
| 4053 return outputs; |
| 4054 } |
| 4055 return sources.map(compute).toList(); |
| 4056 } |
| 4057 |
3501 /** | 4058 /** |
3502 * Create a script object with a single fragment containing the given | 4059 * Create a script object with a single fragment containing the given |
3503 * [scriptContent]. | 4060 * [scriptContent]. |
3504 */ | 4061 */ |
3505 DartScript createScript(String scriptContent) { | 4062 DartScript createScript(String scriptContent) { |
3506 String htmlContent = ''' | 4063 String htmlContent = ''' |
3507 <!DOCTYPE html> | 4064 <!DOCTYPE html> |
3508 <html> | 4065 <html> |
3509 <head> | 4066 <head> |
3510 <title>test page</title> | 4067 <title>test page</title> |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3643 /** | 4200 /** |
3644 * Fill [errorListener] with [result] errors in the current [task]. | 4201 * Fill [errorListener] with [result] errors in the current [task]. |
3645 */ | 4202 */ |
3646 void _fillErrorListener(ResultDescriptor<List<AnalysisError>> result) { | 4203 void _fillErrorListener(ResultDescriptor<List<AnalysisError>> result) { |
3647 List<AnalysisError> errors = task.outputs[result]; | 4204 List<AnalysisError> errors = task.outputs[result]; |
3648 expect(errors, isNotNull, reason: result.name); | 4205 expect(errors, isNotNull, reason: result.name); |
3649 errorListener = new GatheringErrorListener(); | 4206 errorListener = new GatheringErrorListener(); |
3650 errorListener.addAll(errors); | 4207 errorListener.addAll(errors); |
3651 } | 4208 } |
3652 } | 4209 } |
OLD | NEW |