| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 // This code was auto-generated, is not intended to be edited, and is subject to | 5 // This code was auto-generated, is not intended to be edited, and is subject to |
| 6 // significant change. Please see the README file for more information. | 6 // significant change. Please see the README file for more information. |
| 7 | 7 |
| 8 library engine.all_the_rest_test; | 8 library engine.all_the_rest_test; |
| 9 | 9 |
| 10 import 'dart:collection'; | 10 import 'dart:collection'; |
| (...skipping 947 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 958 void test_visitConstructorDeclaration_const() { | 958 void test_visitConstructorDeclaration_const() { |
| 959 ConstructorElement element = _setupConstructorDeclaration("A", true); | 959 ConstructorElement element = _setupConstructorDeclaration("A", true); |
| 960 expect(_findConstantDeclarations()[element], same(_node)); | 960 expect(_findConstantDeclarations()[element], same(_node)); |
| 961 } | 961 } |
| 962 | 962 |
| 963 void test_visitConstructorDeclaration_nonConst() { | 963 void test_visitConstructorDeclaration_nonConst() { |
| 964 _setupConstructorDeclaration("A", false); | 964 _setupConstructorDeclaration("A", false); |
| 965 expect(_findConstantDeclarations().isEmpty, isTrue); | 965 expect(_findConstantDeclarations().isEmpty, isTrue); |
| 966 } | 966 } |
| 967 | 967 |
| 968 void test_visitInstanceCreationExpression_const() { | |
| 969 _setupInstanceCreationExpression("A", true); | |
| 970 expect(_findConstructorInvocations().contains(_node), isTrue); | |
| 971 } | |
| 972 | |
| 973 void test_visitInstanceCreationExpression_nonConst() { | |
| 974 _setupInstanceCreationExpression("A", false); | |
| 975 expect(_findConstructorInvocations().isEmpty, isTrue); | |
| 976 } | |
| 977 | |
| 978 void test_visitVariableDeclaration_const() { | 968 void test_visitVariableDeclaration_const() { |
| 979 VariableElement element = _setupVariableDeclaration("v", true, true); | 969 VariableElement element = _setupVariableDeclaration("v", true, true); |
| 980 expect(_findVariableDeclarations()[element], same(_node)); | 970 expect(_findVariableDeclarations()[element], same(_node)); |
| 981 } | 971 } |
| 982 | 972 |
| 983 void test_visitVariableDeclaration_final_inClass() { | 973 void test_visitVariableDeclaration_final_inClass() { |
| 984 _setupFieldDeclaration('C', 'f', Keyword.FINAL); | 974 _setupFieldDeclaration('C', 'f', Keyword.FINAL); |
| 985 expect(_findVariableDeclarations(), isEmpty); | 975 expect(_findVariableDeclarations(), isEmpty); |
| 986 } | 976 } |
| 987 | 977 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1046 | 1036 |
| 1047 Map<ConstructorElement, ConstructorDeclaration> _findConstantDeclarations() { | 1037 Map<ConstructorElement, ConstructorDeclaration> _findConstantDeclarations() { |
| 1048 ConstantFinder finder = new ConstantFinder(); | 1038 ConstantFinder finder = new ConstantFinder(); |
| 1049 _node.accept(finder); | 1039 _node.accept(finder); |
| 1050 Map<ConstructorElement, ConstructorDeclaration> constructorMap = | 1040 Map<ConstructorElement, ConstructorDeclaration> constructorMap = |
| 1051 finder.constructorMap; | 1041 finder.constructorMap; |
| 1052 expect(constructorMap, isNotNull); | 1042 expect(constructorMap, isNotNull); |
| 1053 return constructorMap; | 1043 return constructorMap; |
| 1054 } | 1044 } |
| 1055 | 1045 |
| 1056 List<InstanceCreationExpression> _findConstructorInvocations() { | |
| 1057 ConstantFinder finder = new ConstantFinder(); | |
| 1058 _node.accept(finder); | |
| 1059 List<InstanceCreationExpression> constructorInvocations = | |
| 1060 finder.constructorInvocations; | |
| 1061 expect(constructorInvocations, isNotNull); | |
| 1062 return constructorInvocations; | |
| 1063 } | |
| 1064 | |
| 1065 Map<PotentiallyConstVariableElement, VariableDeclaration> _findVariableDeclara
tions() { | 1046 Map<PotentiallyConstVariableElement, VariableDeclaration> _findVariableDeclara
tions() { |
| 1066 ConstantFinder finder = new ConstantFinder(); | 1047 ConstantFinder finder = new ConstantFinder(); |
| 1067 _node.accept(finder); | 1048 _node.accept(finder); |
| 1068 Map<PotentiallyConstVariableElement, VariableDeclaration> variableMap = | 1049 Map<PotentiallyConstVariableElement, VariableDeclaration> variableMap = |
| 1069 finder.variableMap; | 1050 finder.variableMap; |
| 1070 expect(variableMap, isNotNull); | 1051 expect(variableMap, isNotNull); |
| 1071 return variableMap; | 1052 return variableMap; |
| 1072 } | 1053 } |
| 1073 | 1054 |
| 1074 ConstructorElement _setupConstructorDeclaration(String name, bool isConst) { | 1055 ConstructorElement _setupConstructorDeclaration(String name, bool isConst) { |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1113 AstFactory.blockFunctionBody2()); | 1094 AstFactory.blockFunctionBody2()); |
| 1114 classDeclaration.members.add(constructorDeclaration); | 1095 classDeclaration.members.add(constructorDeclaration); |
| 1115 ConstructorElement constructorElement = | 1096 ConstructorElement constructorElement = |
| 1116 ElementFactory.constructorElement(classElement, '', true); | 1097 ElementFactory.constructorElement(classElement, '', true); |
| 1117 constructorDeclaration.element = constructorElement; | 1098 constructorDeclaration.element = constructorElement; |
| 1118 classElement.constructors = <ConstructorElement>[constructorElement]; | 1099 classElement.constructors = <ConstructorElement>[constructorElement]; |
| 1119 } | 1100 } |
| 1120 return variableDeclaration; | 1101 return variableDeclaration; |
| 1121 } | 1102 } |
| 1122 | 1103 |
| 1123 void _setupInstanceCreationExpression(String name, bool isConst) { | |
| 1124 _node = AstFactory.instanceCreationExpression2( | |
| 1125 isConst ? Keyword.CONST : null, | |
| 1126 AstFactory.typeName3(AstFactory.identifier3(name))); | |
| 1127 } | |
| 1128 | |
| 1129 VariableElement _setupVariableDeclaration( | 1104 VariableElement _setupVariableDeclaration( |
| 1130 String name, bool isConst, bool isInitialized, {isFinal: false}) { | 1105 String name, bool isConst, bool isInitialized, {isFinal: false}) { |
| 1131 VariableDeclaration variableDeclaration = isInitialized | 1106 VariableDeclaration variableDeclaration = isInitialized |
| 1132 ? AstFactory.variableDeclaration2(name, AstFactory.integer(0)) | 1107 ? AstFactory.variableDeclaration2(name, AstFactory.integer(0)) |
| 1133 : AstFactory.variableDeclaration(name); | 1108 : AstFactory.variableDeclaration(name); |
| 1134 SimpleIdentifier identifier = variableDeclaration.name; | 1109 SimpleIdentifier identifier = variableDeclaration.name; |
| 1135 VariableElement element = ElementFactory.localVariableElement(identifier); | 1110 VariableElement element = ElementFactory.localVariableElement(identifier); |
| 1136 identifier.staticElement = element; | 1111 identifier.staticElement = element; |
| 1137 Keyword keyword = isConst ? Keyword.CONST : isFinal ? Keyword.FINAL : null; | 1112 Keyword keyword = isConst ? Keyword.CONST : isFinal ? Keyword.FINAL : null; |
| 1138 AstFactory.variableDeclarationList2(keyword, [variableDeclaration]); | 1113 AstFactory.variableDeclarationList2(keyword, [variableDeclaration]); |
| (...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1623 void test_final_initialized_at_declaration() { | 1598 void test_final_initialized_at_declaration() { |
| 1624 CompilationUnit compilationUnit = resolveSource(''' | 1599 CompilationUnit compilationUnit = resolveSource(''' |
| 1625 class A { | 1600 class A { |
| 1626 final int i = 123; | 1601 final int i = 123; |
| 1627 const A(); | 1602 const A(); |
| 1628 } | 1603 } |
| 1629 | 1604 |
| 1630 const A a = const A(); | 1605 const A a = const A(); |
| 1631 '''); | 1606 '''); |
| 1632 EvaluationResultImpl result = | 1607 EvaluationResultImpl result = |
| 1633 _evaluateInstanceCreationExpression(compilationUnit, 'a'); | 1608 _evaluateTopLevelVariable(compilationUnit, 'a'); |
| 1634 Map<String, DartObjectImpl> fields = _assertType(result, "A"); | 1609 Map<String, DartObjectImpl> fields = _assertType(result, "A"); |
| 1635 expect(fields, hasLength(1)); | 1610 expect(fields, hasLength(1)); |
| 1636 _assertIntField(fields, "i", 123); | 1611 _assertIntField(fields, "i", 123); |
| 1637 } | 1612 } |
| 1638 | 1613 |
| 1639 void test_fromEnvironment_bool_default_false() { | 1614 void test_fromEnvironment_bool_default_false() { |
| 1640 expect(_assertValidBool(_check_fromEnvironment_bool(null, "false")), false); | 1615 expect(_assertValidBool(_check_fromEnvironment_bool(null, "false")), false); |
| 1641 } | 1616 } |
| 1642 | 1617 |
| 1643 void test_fromEnvironment_bool_default_overridden() { | 1618 void test_fromEnvironment_bool_default_overridden() { |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1732 } | 1707 } |
| 1733 | 1708 |
| 1734 void test_instanceCreationExpression_computedField() { | 1709 void test_instanceCreationExpression_computedField() { |
| 1735 CompilationUnit compilationUnit = resolveSource(r''' | 1710 CompilationUnit compilationUnit = resolveSource(r''' |
| 1736 const foo = const A(4, 5); | 1711 const foo = const A(4, 5); |
| 1737 class A { | 1712 class A { |
| 1738 const A(int i, int j) : k = 2 * i + j; | 1713 const A(int i, int j) : k = 2 * i + j; |
| 1739 final int k; | 1714 final int k; |
| 1740 }'''); | 1715 }'''); |
| 1741 EvaluationResultImpl result = | 1716 EvaluationResultImpl result = |
| 1742 _evaluateInstanceCreationExpression(compilationUnit, "foo"); | 1717 _evaluateTopLevelVariable(compilationUnit, "foo"); |
| 1743 Map<String, DartObjectImpl> fields = _assertType(result, "A"); | 1718 Map<String, DartObjectImpl> fields = _assertType(result, "A"); |
| 1744 expect(fields, hasLength(1)); | 1719 expect(fields, hasLength(1)); |
| 1745 _assertIntField(fields, "k", 13); | 1720 _assertIntField(fields, "k", 13); |
| 1746 } | 1721 } |
| 1747 | 1722 |
| 1748 void test_instanceCreationExpression_computedField_namedOptionalWithDefault()
{ | 1723 void test_instanceCreationExpression_computedField_namedOptionalWithDefault()
{ |
| 1749 _checkInstanceCreationOptionalParams(false, true, true); | 1724 _checkInstanceCreationOptionalParams(false, true, true); |
| 1750 } | 1725 } |
| 1751 | 1726 |
| 1752 void test_instanceCreationExpression_computedField_namedOptionalWithoutDefault
() { | 1727 void test_instanceCreationExpression_computedField_namedOptionalWithoutDefault
() { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1766 const foo = const A(3); | 1741 const foo = const A(3); |
| 1767 class A { | 1742 class A { |
| 1768 const A(int i) : b = const B(4); | 1743 const A(int i) : b = const B(4); |
| 1769 final int b; | 1744 final int b; |
| 1770 } | 1745 } |
| 1771 class B { | 1746 class B { |
| 1772 const B(this.k); | 1747 const B(this.k); |
| 1773 final int k; | 1748 final int k; |
| 1774 }'''); | 1749 }'''); |
| 1775 EvaluationResultImpl result = | 1750 EvaluationResultImpl result = |
| 1776 _evaluateInstanceCreationExpression(compilationUnit, "foo"); | 1751 _evaluateTopLevelVariable(compilationUnit, "foo"); |
| 1777 Map<String, DartObjectImpl> fieldsOfA = _assertType(result, "A"); | 1752 Map<String, DartObjectImpl> fieldsOfA = _assertType(result, "A"); |
| 1778 expect(fieldsOfA, hasLength(1)); | 1753 expect(fieldsOfA, hasLength(1)); |
| 1779 Map<String, DartObjectImpl> fieldsOfB = | 1754 Map<String, DartObjectImpl> fieldsOfB = |
| 1780 _assertFieldType(fieldsOfA, "b", "B"); | 1755 _assertFieldType(fieldsOfA, "b", "B"); |
| 1781 expect(fieldsOfB, hasLength(1)); | 1756 expect(fieldsOfB, hasLength(1)); |
| 1782 _assertIntField(fieldsOfB, "k", 4); | 1757 _assertIntField(fieldsOfB, "k", 4); |
| 1783 } | 1758 } |
| 1784 | 1759 |
| 1785 void test_instanceCreationExpression_computedField_usesStaticConst() { | 1760 void test_instanceCreationExpression_computedField_usesStaticConst() { |
| 1786 CompilationUnit compilationUnit = resolveSource(r''' | 1761 CompilationUnit compilationUnit = resolveSource(r''' |
| 1787 const foo = const A(3); | 1762 const foo = const A(3); |
| 1788 class A { | 1763 class A { |
| 1789 const A(int i) : k = i + B.bar; | 1764 const A(int i) : k = i + B.bar; |
| 1790 final int k; | 1765 final int k; |
| 1791 } | 1766 } |
| 1792 class B { | 1767 class B { |
| 1793 static const bar = 4; | 1768 static const bar = 4; |
| 1794 }'''); | 1769 }'''); |
| 1795 EvaluationResultImpl result = | 1770 EvaluationResultImpl result = |
| 1796 _evaluateInstanceCreationExpression(compilationUnit, "foo"); | 1771 _evaluateTopLevelVariable(compilationUnit, "foo"); |
| 1797 Map<String, DartObjectImpl> fields = _assertType(result, "A"); | 1772 Map<String, DartObjectImpl> fields = _assertType(result, "A"); |
| 1798 expect(fields, hasLength(1)); | 1773 expect(fields, hasLength(1)); |
| 1799 _assertIntField(fields, "k", 7); | 1774 _assertIntField(fields, "k", 7); |
| 1800 } | 1775 } |
| 1801 | 1776 |
| 1802 void test_instanceCreationExpression_computedField_usesToplevelConst() { | 1777 void test_instanceCreationExpression_computedField_usesToplevelConst() { |
| 1803 CompilationUnit compilationUnit = resolveSource(r''' | 1778 CompilationUnit compilationUnit = resolveSource(r''' |
| 1804 const foo = const A(3); | 1779 const foo = const A(3); |
| 1805 const bar = 4; | 1780 const bar = 4; |
| 1806 class A { | 1781 class A { |
| 1807 const A(int i) : k = i + bar; | 1782 const A(int i) : k = i + bar; |
| 1808 final int k; | 1783 final int k; |
| 1809 }'''); | 1784 }'''); |
| 1810 EvaluationResultImpl result = | 1785 EvaluationResultImpl result = |
| 1811 _evaluateInstanceCreationExpression(compilationUnit, "foo"); | 1786 _evaluateTopLevelVariable(compilationUnit, "foo"); |
| 1812 Map<String, DartObjectImpl> fields = _assertType(result, "A"); | 1787 Map<String, DartObjectImpl> fields = _assertType(result, "A"); |
| 1813 expect(fields, hasLength(1)); | 1788 expect(fields, hasLength(1)); |
| 1814 _assertIntField(fields, "k", 7); | 1789 _assertIntField(fields, "k", 7); |
| 1815 } | 1790 } |
| 1816 | 1791 |
| 1817 void test_instanceCreationExpression_explicitSuper() { | 1792 void test_instanceCreationExpression_explicitSuper() { |
| 1818 CompilationUnit compilationUnit = resolveSource(r''' | 1793 CompilationUnit compilationUnit = resolveSource(r''' |
| 1819 const foo = const B(4, 5); | 1794 const foo = const B(4, 5); |
| 1820 class A { | 1795 class A { |
| 1821 const A(this.x); | 1796 const A(this.x); |
| 1822 final int x; | 1797 final int x; |
| 1823 } | 1798 } |
| 1824 class B extends A { | 1799 class B extends A { |
| 1825 const B(int x, this.y) : super(x * 2); | 1800 const B(int x, this.y) : super(x * 2); |
| 1826 final int y; | 1801 final int y; |
| 1827 }'''); | 1802 }'''); |
| 1828 EvaluationResultImpl result = | 1803 EvaluationResultImpl result = |
| 1829 _evaluateInstanceCreationExpression(compilationUnit, "foo"); | 1804 _evaluateTopLevelVariable(compilationUnit, "foo"); |
| 1830 Map<String, DartObjectImpl> fields = _assertType(result, "B"); | 1805 Map<String, DartObjectImpl> fields = _assertType(result, "B"); |
| 1831 expect(fields, hasLength(2)); | 1806 expect(fields, hasLength(2)); |
| 1832 _assertIntField(fields, "y", 5); | 1807 _assertIntField(fields, "y", 5); |
| 1833 Map<String, DartObjectImpl> superclassFields = | 1808 Map<String, DartObjectImpl> superclassFields = |
| 1834 _assertFieldType(fields, GenericState.SUPERCLASS_FIELD, "A"); | 1809 _assertFieldType(fields, GenericState.SUPERCLASS_FIELD, "A"); |
| 1835 expect(superclassFields, hasLength(1)); | 1810 expect(superclassFields, hasLength(1)); |
| 1836 _assertIntField(superclassFields, "x", 8); | 1811 _assertIntField(superclassFields, "x", 8); |
| 1837 } | 1812 } |
| 1838 | 1813 |
| 1839 void test_instanceCreationExpression_fieldFormalParameter() { | 1814 void test_instanceCreationExpression_fieldFormalParameter() { |
| 1840 CompilationUnit compilationUnit = resolveSource(r''' | 1815 CompilationUnit compilationUnit = resolveSource(r''' |
| 1841 const foo = const A(42); | 1816 const foo = const A(42); |
| 1842 class A { | 1817 class A { |
| 1843 int x; | 1818 int x; |
| 1844 const A(this.x) | 1819 const A(this.x) |
| 1845 }'''); | 1820 }'''); |
| 1846 EvaluationResultImpl result = | 1821 EvaluationResultImpl result = |
| 1847 _evaluateInstanceCreationExpression(compilationUnit, "foo"); | 1822 _evaluateTopLevelVariable(compilationUnit, "foo"); |
| 1848 Map<String, DartObjectImpl> fields = _assertType(result, "A"); | 1823 Map<String, DartObjectImpl> fields = _assertType(result, "A"); |
| 1849 expect(fields, hasLength(1)); | 1824 expect(fields, hasLength(1)); |
| 1850 _assertIntField(fields, "x", 42); | 1825 _assertIntField(fields, "x", 42); |
| 1851 } | 1826 } |
| 1852 | 1827 |
| 1853 void test_instanceCreationExpression_fieldFormalParameter_namedOptionalWithDef
ault() { | 1828 void test_instanceCreationExpression_fieldFormalParameter_namedOptionalWithDef
ault() { |
| 1854 _checkInstanceCreationOptionalParams(true, true, true); | 1829 _checkInstanceCreationOptionalParams(true, true, true); |
| 1855 } | 1830 } |
| 1856 | 1831 |
| 1857 void test_instanceCreationExpression_fieldFormalParameter_namedOptionalWithout
Default() { | 1832 void test_instanceCreationExpression_fieldFormalParameter_namedOptionalWithout
Default() { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1871 const foo = const B(4); | 1846 const foo = const B(4); |
| 1872 class A { | 1847 class A { |
| 1873 const A() : x = 3; | 1848 const A() : x = 3; |
| 1874 final int x; | 1849 final int x; |
| 1875 } | 1850 } |
| 1876 class B extends A { | 1851 class B extends A { |
| 1877 const B(this.y); | 1852 const B(this.y); |
| 1878 final int y; | 1853 final int y; |
| 1879 }'''); | 1854 }'''); |
| 1880 EvaluationResultImpl result = | 1855 EvaluationResultImpl result = |
| 1881 _evaluateInstanceCreationExpression(compilationUnit, "foo"); | 1856 _evaluateTopLevelVariable(compilationUnit, "foo"); |
| 1882 Map<String, DartObjectImpl> fields = _assertType(result, "B"); | 1857 Map<String, DartObjectImpl> fields = _assertType(result, "B"); |
| 1883 expect(fields, hasLength(2)); | 1858 expect(fields, hasLength(2)); |
| 1884 _assertIntField(fields, "y", 4); | 1859 _assertIntField(fields, "y", 4); |
| 1885 Map<String, DartObjectImpl> superclassFields = | 1860 Map<String, DartObjectImpl> superclassFields = |
| 1886 _assertFieldType(fields, GenericState.SUPERCLASS_FIELD, "A"); | 1861 _assertFieldType(fields, GenericState.SUPERCLASS_FIELD, "A"); |
| 1887 expect(superclassFields, hasLength(1)); | 1862 expect(superclassFields, hasLength(1)); |
| 1888 _assertIntField(superclassFields, "x", 3); | 1863 _assertIntField(superclassFields, "x", 3); |
| 1889 } | 1864 } |
| 1890 | 1865 |
| 1891 void test_instanceCreationExpression_nonFactoryRedirect() { | 1866 void test_instanceCreationExpression_nonFactoryRedirect() { |
| 1892 CompilationUnit compilationUnit = resolveSource(r''' | 1867 CompilationUnit compilationUnit = resolveSource(r''' |
| 1893 const foo = const A.a1(); | 1868 const foo = const A.a1(); |
| 1894 class A { | 1869 class A { |
| 1895 const A.a1() : this.a2(); | 1870 const A.a1() : this.a2(); |
| 1896 const A.a2() : x = 5; | 1871 const A.a2() : x = 5; |
| 1897 final int x; | 1872 final int x; |
| 1898 }'''); | 1873 }'''); |
| 1899 Map<String, DartObjectImpl> aFields = _assertType( | 1874 Map<String, DartObjectImpl> aFields = |
| 1900 _evaluateInstanceCreationExpression(compilationUnit, "foo"), "A"); | 1875 _assertType(_evaluateTopLevelVariable(compilationUnit, "foo"), "A"); |
| 1901 _assertIntField(aFields, 'x', 5); | 1876 _assertIntField(aFields, 'x', 5); |
| 1902 } | 1877 } |
| 1903 | 1878 |
| 1904 void test_instanceCreationExpression_nonFactoryRedirect_arg() { | 1879 void test_instanceCreationExpression_nonFactoryRedirect_arg() { |
| 1905 CompilationUnit compilationUnit = resolveSource(r''' | 1880 CompilationUnit compilationUnit = resolveSource(r''' |
| 1906 const foo = const A.a1(1); | 1881 const foo = const A.a1(1); |
| 1907 class A { | 1882 class A { |
| 1908 const A.a1(x) : this.a2(x + 100); | 1883 const A.a1(x) : this.a2(x + 100); |
| 1909 const A.a2(x) : y = x + 10; | 1884 const A.a2(x) : y = x + 10; |
| 1910 final int y; | 1885 final int y; |
| 1911 }'''); | 1886 }'''); |
| 1912 Map<String, DartObjectImpl> aFields = _assertType( | 1887 Map<String, DartObjectImpl> aFields = |
| 1913 _evaluateInstanceCreationExpression(compilationUnit, "foo"), "A"); | 1888 _assertType(_evaluateTopLevelVariable(compilationUnit, "foo"), "A"); |
| 1914 _assertIntField(aFields, 'y', 111); | 1889 _assertIntField(aFields, 'y', 111); |
| 1915 } | 1890 } |
| 1916 | 1891 |
| 1917 void test_instanceCreationExpression_nonFactoryRedirect_cycle() { | 1892 void test_instanceCreationExpression_nonFactoryRedirect_cycle() { |
| 1918 // It is an error to have a cycle in non-factory redirects; however, we | 1893 // It is an error to have a cycle in non-factory redirects; however, we |
| 1919 // need to make sure that even if the error occurs, attempting to evaluate | 1894 // need to make sure that even if the error occurs, attempting to evaluate |
| 1920 // the constant will terminate. | 1895 // the constant will terminate. |
| 1921 CompilationUnit compilationUnit = resolveSource(r''' | 1896 CompilationUnit compilationUnit = resolveSource(r''' |
| 1922 const foo = const A(); | 1897 const foo = const A(); |
| 1923 class A { | 1898 class A { |
| 1924 const A() : this.b(); | 1899 const A() : this.b(); |
| 1925 const A.b() : this(); | 1900 const A.b() : this(); |
| 1926 }'''); | 1901 }'''); |
| 1927 _assertValidUnknown( | 1902 _assertValidUnknown(_evaluateTopLevelVariable(compilationUnit, "foo")); |
| 1928 _evaluateInstanceCreationExpression(compilationUnit, "foo")); | |
| 1929 } | 1903 } |
| 1930 | 1904 |
| 1931 void test_instanceCreationExpression_nonFactoryRedirect_defaultArg() { | 1905 void test_instanceCreationExpression_nonFactoryRedirect_defaultArg() { |
| 1932 CompilationUnit compilationUnit = resolveSource(r''' | 1906 CompilationUnit compilationUnit = resolveSource(r''' |
| 1933 const foo = const A.a1(); | 1907 const foo = const A.a1(); |
| 1934 class A { | 1908 class A { |
| 1935 const A.a1() : this.a2(); | 1909 const A.a1() : this.a2(); |
| 1936 const A.a2([x = 100]) : y = x + 10; | 1910 const A.a2([x = 100]) : y = x + 10; |
| 1937 final int y; | 1911 final int y; |
| 1938 }'''); | 1912 }'''); |
| 1939 Map<String, DartObjectImpl> aFields = _assertType( | 1913 Map<String, DartObjectImpl> aFields = |
| 1940 _evaluateInstanceCreationExpression(compilationUnit, "foo"), "A"); | 1914 _assertType(_evaluateTopLevelVariable(compilationUnit, "foo"), "A"); |
| 1941 _assertIntField(aFields, 'y', 110); | 1915 _assertIntField(aFields, 'y', 110); |
| 1942 } | 1916 } |
| 1943 | 1917 |
| 1944 void test_instanceCreationExpression_nonFactoryRedirect_toMissing() { | 1918 void test_instanceCreationExpression_nonFactoryRedirect_toMissing() { |
| 1945 CompilationUnit compilationUnit = resolveSource(r''' | 1919 CompilationUnit compilationUnit = resolveSource(r''' |
| 1946 const foo = const A.a1(); | 1920 const foo = const A.a1(); |
| 1947 class A { | 1921 class A { |
| 1948 const A.a1() : this.a2(); | 1922 const A.a1() : this.a2(); |
| 1949 }'''); | 1923 }'''); |
| 1950 // We don't care what value foo evaluates to (since there is a compile | 1924 // We don't care what value foo evaluates to (since there is a compile |
| 1951 // error), but we shouldn't crash, and we should figure | 1925 // error), but we shouldn't crash, and we should figure |
| 1952 // out that it evaluates to an instance of class A. | 1926 // out that it evaluates to an instance of class A. |
| 1953 _assertType( | 1927 _assertType(_evaluateTopLevelVariable(compilationUnit, "foo"), "A"); |
| 1954 _evaluateInstanceCreationExpression(compilationUnit, "foo"), "A"); | |
| 1955 } | 1928 } |
| 1956 | 1929 |
| 1957 void test_instanceCreationExpression_nonFactoryRedirect_toNonConst() { | 1930 void test_instanceCreationExpression_nonFactoryRedirect_toNonConst() { |
| 1958 CompilationUnit compilationUnit = resolveSource(r''' | 1931 CompilationUnit compilationUnit = resolveSource(r''' |
| 1959 const foo = const A.a1(); | 1932 const foo = const A.a1(); |
| 1960 class A { | 1933 class A { |
| 1961 const A.a1() : this.a2(); | 1934 const A.a1() : this.a2(); |
| 1962 A.a2(); | 1935 A.a2(); |
| 1963 }'''); | 1936 }'''); |
| 1964 // We don't care what value foo evaluates to (since there is a compile | 1937 // We don't care what value foo evaluates to (since there is a compile |
| 1965 // error), but we shouldn't crash, and we should figure | 1938 // error), but we shouldn't crash, and we should figure |
| 1966 // out that it evaluates to an instance of class A. | 1939 // out that it evaluates to an instance of class A. |
| 1967 _assertType( | 1940 _assertType(_evaluateTopLevelVariable(compilationUnit, "foo"), "A"); |
| 1968 _evaluateInstanceCreationExpression(compilationUnit, "foo"), "A"); | |
| 1969 } | 1941 } |
| 1970 | 1942 |
| 1971 void test_instanceCreationExpression_nonFactoryRedirect_unnamed() { | 1943 void test_instanceCreationExpression_nonFactoryRedirect_unnamed() { |
| 1972 CompilationUnit compilationUnit = resolveSource(r''' | 1944 CompilationUnit compilationUnit = resolveSource(r''' |
| 1973 const foo = const A.a1(); | 1945 const foo = const A.a1(); |
| 1974 class A { | 1946 class A { |
| 1975 const A.a1() : this(); | 1947 const A.a1() : this(); |
| 1976 const A() : x = 5; | 1948 const A() : x = 5; |
| 1977 final int x; | 1949 final int x; |
| 1978 }'''); | 1950 }'''); |
| 1979 Map<String, DartObjectImpl> aFields = _assertType( | 1951 Map<String, DartObjectImpl> aFields = |
| 1980 _evaluateInstanceCreationExpression(compilationUnit, "foo"), "A"); | 1952 _assertType(_evaluateTopLevelVariable(compilationUnit, "foo"), "A"); |
| 1981 _assertIntField(aFields, 'x', 5); | 1953 _assertIntField(aFields, 'x', 5); |
| 1982 } | 1954 } |
| 1983 | 1955 |
| 1984 void test_instanceCreationExpression_redirect() { | 1956 void test_instanceCreationExpression_redirect() { |
| 1985 CompilationUnit compilationUnit = resolveSource(r''' | 1957 CompilationUnit compilationUnit = resolveSource(r''' |
| 1986 const foo = const A(); | 1958 const foo = const A(); |
| 1987 class A { | 1959 class A { |
| 1988 const factory A() = B; | 1960 const factory A() = B; |
| 1989 } | 1961 } |
| 1990 class B implements A { | 1962 class B implements A { |
| 1991 const B(); | 1963 const B(); |
| 1992 }'''); | 1964 }'''); |
| 1993 _assertType( | 1965 _assertType(_evaluateTopLevelVariable(compilationUnit, "foo"), "B"); |
| 1994 _evaluateInstanceCreationExpression(compilationUnit, "foo"), "B"); | |
| 1995 } | 1966 } |
| 1996 | 1967 |
| 1997 void test_instanceCreationExpression_redirect_cycle() { | 1968 void test_instanceCreationExpression_redirect_cycle() { |
| 1998 // It is an error to have a cycle in factory redirects; however, we need | 1969 // It is an error to have a cycle in factory redirects; however, we need |
| 1999 // to make sure that even if the error occurs, attempting to evaluate the | 1970 // to make sure that even if the error occurs, attempting to evaluate the |
| 2000 // constant will terminate. | 1971 // constant will terminate. |
| 2001 CompilationUnit compilationUnit = resolveSource(r''' | 1972 CompilationUnit compilationUnit = resolveSource(r''' |
| 2002 const foo = const A(); | 1973 const foo = const A(); |
| 2003 class A { | 1974 class A { |
| 2004 const factory A() = A.b; | 1975 const factory A() = A.b; |
| 2005 const factory A.b() = A; | 1976 const factory A.b() = A; |
| 2006 }'''); | 1977 }'''); |
| 2007 _assertValidUnknown( | 1978 _assertValidUnknown(_evaluateTopLevelVariable(compilationUnit, "foo")); |
| 2008 _evaluateInstanceCreationExpression(compilationUnit, "foo")); | |
| 2009 } | 1979 } |
| 2010 | 1980 |
| 2011 void test_instanceCreationExpression_redirect_extern() { | 1981 void test_instanceCreationExpression_redirect_extern() { |
| 2012 CompilationUnit compilationUnit = resolveSource(r''' | 1982 CompilationUnit compilationUnit = resolveSource(r''' |
| 2013 const foo = const A(); | 1983 const foo = const A(); |
| 2014 class A { | 1984 class A { |
| 2015 external const factory A(); | 1985 external const factory A(); |
| 2016 }'''); | 1986 }'''); |
| 2017 _assertValidUnknown( | 1987 _assertValidUnknown(_evaluateTopLevelVariable(compilationUnit, "foo")); |
| 2018 _evaluateInstanceCreationExpression(compilationUnit, "foo")); | |
| 2019 } | 1988 } |
| 2020 | 1989 |
| 2021 void test_instanceCreationExpression_redirect_nonConst() { | 1990 void test_instanceCreationExpression_redirect_nonConst() { |
| 2022 // It is an error for a const factory constructor redirect to a non-const | 1991 // It is an error for a const factory constructor redirect to a non-const |
| 2023 // constructor; however, we need to make sure that even if the error | 1992 // constructor; however, we need to make sure that even if the error |
| 2024 // attempting to evaluate the constant won't cause a crash. | 1993 // attempting to evaluate the constant won't cause a crash. |
| 2025 CompilationUnit compilationUnit = resolveSource(r''' | 1994 CompilationUnit compilationUnit = resolveSource(r''' |
| 2026 const foo = const A(); | 1995 const foo = const A(); |
| 2027 class A { | 1996 class A { |
| 2028 const factory A() = A.b; | 1997 const factory A() = A.b; |
| 2029 A.b(); | 1998 A.b(); |
| 2030 }'''); | 1999 }'''); |
| 2031 _assertValidUnknown( | 2000 _assertValidUnknown(_evaluateTopLevelVariable(compilationUnit, "foo")); |
| 2032 _evaluateInstanceCreationExpression(compilationUnit, "foo")); | |
| 2033 } | 2001 } |
| 2034 | 2002 |
| 2035 void test_instanceCreationExpression_redirectWithTypeParams() { | 2003 void test_instanceCreationExpression_redirectWithTypeParams() { |
| 2036 CompilationUnit compilationUnit = resolveSource(r''' | 2004 CompilationUnit compilationUnit = resolveSource(r''' |
| 2037 class A { | 2005 class A { |
| 2038 const factory A(var a) = B<int>; | 2006 const factory A(var a) = B<int>; |
| 2039 } | 2007 } |
| 2040 | 2008 |
| 2041 class B<T> implements A { | 2009 class B<T> implements A { |
| 2042 final T x; | 2010 final T x; |
| 2043 const B(this.x); | 2011 const B(this.x); |
| 2044 } | 2012 } |
| 2045 | 2013 |
| 2046 const A a = const A(10);'''); | 2014 const A a = const A(10);'''); |
| 2047 EvaluationResultImpl result = | 2015 EvaluationResultImpl result = |
| 2048 _evaluateInstanceCreationExpression(compilationUnit, "a"); | 2016 _evaluateTopLevelVariable(compilationUnit, "a"); |
| 2049 Map<String, DartObjectImpl> fields = _assertType(result, "B<int>"); | 2017 Map<String, DartObjectImpl> fields = _assertType(result, "B<int>"); |
| 2050 expect(fields, hasLength(1)); | 2018 expect(fields, hasLength(1)); |
| 2051 _assertIntField(fields, "x", 10); | 2019 _assertIntField(fields, "x", 10); |
| 2052 } | 2020 } |
| 2053 | 2021 |
| 2054 void test_instanceCreationExpression_redirectWithTypeSubstitution() { | 2022 void test_instanceCreationExpression_redirectWithTypeSubstitution() { |
| 2055 // To evaluate the redirection of A<int>, | 2023 // To evaluate the redirection of A<int>, |
| 2056 // A's template argument (T=int) must be substituted | 2024 // A's template argument (T=int) must be substituted |
| 2057 // into B's template argument (B<U> where U=T) to get B<int>. | 2025 // into B's template argument (B<U> where U=T) to get B<int>. |
| 2058 CompilationUnit compilationUnit = resolveSource(r''' | 2026 CompilationUnit compilationUnit = resolveSource(r''' |
| 2059 class A<T> { | 2027 class A<T> { |
| 2060 const factory A(var a) = B<T>; | 2028 const factory A(var a) = B<T>; |
| 2061 } | 2029 } |
| 2062 | 2030 |
| 2063 class B<U> implements A { | 2031 class B<U> implements A { |
| 2064 final U x; | 2032 final U x; |
| 2065 const B(this.x); | 2033 const B(this.x); |
| 2066 } | 2034 } |
| 2067 | 2035 |
| 2068 const A<int> a = const A<int>(10);'''); | 2036 const A<int> a = const A<int>(10);'''); |
| 2069 EvaluationResultImpl result = | 2037 EvaluationResultImpl result = |
| 2070 _evaluateInstanceCreationExpression(compilationUnit, "a"); | 2038 _evaluateTopLevelVariable(compilationUnit, "a"); |
| 2071 Map<String, DartObjectImpl> fields = _assertType(result, "B<int>"); | 2039 Map<String, DartObjectImpl> fields = _assertType(result, "B<int>"); |
| 2072 expect(fields, hasLength(1)); | 2040 expect(fields, hasLength(1)); |
| 2073 _assertIntField(fields, "x", 10); | 2041 _assertIntField(fields, "x", 10); |
| 2074 } | 2042 } |
| 2075 | 2043 |
| 2076 void test_instanceCreationExpression_symbol() { | 2044 void test_instanceCreationExpression_symbol() { |
| 2077 CompilationUnit compilationUnit = | 2045 CompilationUnit compilationUnit = |
| 2078 resolveSource("const foo = const Symbol('a');"); | 2046 resolveSource("const foo = const Symbol('a');"); |
| 2079 EvaluationResultImpl evaluationResult = | 2047 EvaluationResultImpl evaluationResult = |
| 2080 _evaluateInstanceCreationExpression(compilationUnit, "foo"); | 2048 _evaluateTopLevelVariable(compilationUnit, "foo"); |
| 2081 expect(evaluationResult.value, isNotNull); | 2049 expect(evaluationResult.value, isNotNull); |
| 2082 DartObjectImpl value = evaluationResult.value; | 2050 DartObjectImpl value = evaluationResult.value; |
| 2083 expect(value.type, typeProvider.symbolType); | 2051 expect(value.type, typeProvider.symbolType); |
| 2084 expect(value.value, "a"); | 2052 expect(value.value, "a"); |
| 2085 } | 2053 } |
| 2086 | 2054 |
| 2087 void test_instanceCreationExpression_withSupertypeParams_explicit() { | 2055 void test_instanceCreationExpression_withSupertypeParams_explicit() { |
| 2088 _checkInstanceCreation_withSupertypeParams(true); | 2056 _checkInstanceCreation_withSupertypeParams(true); |
| 2089 } | 2057 } |
| 2090 | 2058 |
| 2091 void test_instanceCreationExpression_withSupertypeParams_implicit() { | 2059 void test_instanceCreationExpression_withSupertypeParams_implicit() { |
| 2092 _checkInstanceCreation_withSupertypeParams(false); | 2060 _checkInstanceCreation_withSupertypeParams(false); |
| 2093 } | 2061 } |
| 2094 | 2062 |
| 2095 void test_instanceCreationExpression_withTypeParams() { | 2063 void test_instanceCreationExpression_withTypeParams() { |
| 2096 CompilationUnit compilationUnit = resolveSource(r''' | 2064 CompilationUnit compilationUnit = resolveSource(r''' |
| 2097 class C<E> { | 2065 class C<E> { |
| 2098 const C(); | 2066 const C(); |
| 2099 } | 2067 } |
| 2100 const c_int = const C<int>(); | 2068 const c_int = const C<int>(); |
| 2101 const c_num = const C<num>();'''); | 2069 const c_num = const C<num>();'''); |
| 2102 EvaluationResultImpl c_int = | 2070 EvaluationResultImpl c_int = |
| 2103 _evaluateInstanceCreationExpression(compilationUnit, "c_int"); | 2071 _evaluateTopLevelVariable(compilationUnit, "c_int"); |
| 2104 _assertType(c_int, "C<int>"); | 2072 _assertType(c_int, "C<int>"); |
| 2105 DartObjectImpl c_int_value = c_int.value; | 2073 DartObjectImpl c_int_value = c_int.value; |
| 2106 EvaluationResultImpl c_num = | 2074 EvaluationResultImpl c_num = |
| 2107 _evaluateInstanceCreationExpression(compilationUnit, "c_num"); | 2075 _evaluateTopLevelVariable(compilationUnit, "c_num"); |
| 2108 _assertType(c_num, "C<num>"); | 2076 _assertType(c_num, "C<num>"); |
| 2109 DartObjectImpl c_num_value = c_num.value; | 2077 DartObjectImpl c_num_value = c_num.value; |
| 2110 expect(c_int_value == c_num_value, isFalse); | 2078 expect(c_int_value == c_num_value, isFalse); |
| 2111 } | 2079 } |
| 2112 | 2080 |
| 2113 void test_isValidSymbol() { | 2081 void test_isValidSymbol() { |
| 2114 expect(ConstantEvaluationEngine.isValidPublicSymbol(""), isTrue); | 2082 expect(ConstantEvaluationEngine.isValidPublicSymbol(""), isTrue); |
| 2115 expect(ConstantEvaluationEngine.isValidPublicSymbol("foo"), isTrue); | 2083 expect(ConstantEvaluationEngine.isValidPublicSymbol("foo"), isTrue); |
| 2116 expect(ConstantEvaluationEngine.isValidPublicSymbol("foo.bar"), isTrue); | 2084 expect(ConstantEvaluationEngine.isValidPublicSymbol("foo.bar"), isTrue); |
| 2117 expect(ConstantEvaluationEngine.isValidPublicSymbol("foo\$"), isTrue); | 2085 expect(ConstantEvaluationEngine.isValidPublicSymbol("foo\$"), isTrue); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2170 // to handle them for error recovery purposes. | 2138 // to handle them for error recovery purposes. |
| 2171 CompilationUnit compilationUnit = resolveSource(''' | 2139 CompilationUnit compilationUnit = resolveSource(''' |
| 2172 class A { | 2140 class A { |
| 2173 const int i = 123; | 2141 const int i = 123; |
| 2174 const A(); | 2142 const A(); |
| 2175 } | 2143 } |
| 2176 | 2144 |
| 2177 const A a = const A(); | 2145 const A a = const A(); |
| 2178 '''); | 2146 '''); |
| 2179 EvaluationResultImpl result = | 2147 EvaluationResultImpl result = |
| 2180 _evaluateInstanceCreationExpression(compilationUnit, 'a'); | 2148 _evaluateTopLevelVariable(compilationUnit, 'a'); |
| 2181 Map<String, DartObjectImpl> fields = _assertType(result, "A"); | 2149 Map<String, DartObjectImpl> fields = _assertType(result, "A"); |
| 2182 expect(fields, hasLength(1)); | 2150 expect(fields, hasLength(1)); |
| 2183 _assertIntField(fields, "i", 123); | 2151 _assertIntField(fields, "i", 123); |
| 2184 } | 2152 } |
| 2185 | 2153 |
| 2186 void test_symbolLiteral_void() { | 2154 void test_symbolLiteral_void() { |
| 2187 CompilationUnit compilationUnit = | 2155 CompilationUnit compilationUnit = |
| 2188 resolveSource("const voidSymbol = #void;"); | 2156 resolveSource("const voidSymbol = #void;"); |
| 2189 VariableDeclaration voidSymbol = | 2157 VariableDeclaration voidSymbol = |
| 2190 findTopLevelDeclaration(compilationUnit, "voidSymbol"); | 2158 findTopLevelDeclaration(compilationUnit, "voidSymbol"); |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2275 String valueInEnvironment, String defaultExpr) { | 2243 String valueInEnvironment, String defaultExpr) { |
| 2276 String envVarName = "x"; | 2244 String envVarName = "x"; |
| 2277 String varName = "foo"; | 2245 String varName = "foo"; |
| 2278 if (valueInEnvironment != null) { | 2246 if (valueInEnvironment != null) { |
| 2279 analysisContext2.declaredVariables.define(envVarName, valueInEnvironment); | 2247 analysisContext2.declaredVariables.define(envVarName, valueInEnvironment); |
| 2280 } | 2248 } |
| 2281 String defaultArg = | 2249 String defaultArg = |
| 2282 defaultExpr == null ? "" : ", defaultValue: $defaultExpr"; | 2250 defaultExpr == null ? "" : ", defaultValue: $defaultExpr"; |
| 2283 CompilationUnit compilationUnit = resolveSource( | 2251 CompilationUnit compilationUnit = resolveSource( |
| 2284 "const $varName = const bool.fromEnvironment('$envVarName'$defaultArg);"
); | 2252 "const $varName = const bool.fromEnvironment('$envVarName'$defaultArg);"
); |
| 2285 return _evaluateInstanceCreationExpression(compilationUnit, varName); | 2253 return _evaluateTopLevelVariable(compilationUnit, varName); |
| 2286 } | 2254 } |
| 2287 | 2255 |
| 2288 EvaluationResultImpl _check_fromEnvironment_int( | 2256 EvaluationResultImpl _check_fromEnvironment_int( |
| 2289 String valueInEnvironment, String defaultExpr) { | 2257 String valueInEnvironment, String defaultExpr) { |
| 2290 String envVarName = "x"; | 2258 String envVarName = "x"; |
| 2291 String varName = "foo"; | 2259 String varName = "foo"; |
| 2292 if (valueInEnvironment != null) { | 2260 if (valueInEnvironment != null) { |
| 2293 analysisContext2.declaredVariables.define(envVarName, valueInEnvironment); | 2261 analysisContext2.declaredVariables.define(envVarName, valueInEnvironment); |
| 2294 } | 2262 } |
| 2295 String defaultArg = | 2263 String defaultArg = |
| 2296 defaultExpr == null ? "" : ", defaultValue: $defaultExpr"; | 2264 defaultExpr == null ? "" : ", defaultValue: $defaultExpr"; |
| 2297 CompilationUnit compilationUnit = resolveSource( | 2265 CompilationUnit compilationUnit = resolveSource( |
| 2298 "const $varName = const int.fromEnvironment('$envVarName'$defaultArg);")
; | 2266 "const $varName = const int.fromEnvironment('$envVarName'$defaultArg);")
; |
| 2299 return _evaluateInstanceCreationExpression(compilationUnit, varName); | 2267 return _evaluateTopLevelVariable(compilationUnit, varName); |
| 2300 } | 2268 } |
| 2301 | 2269 |
| 2302 EvaluationResultImpl _check_fromEnvironment_string( | 2270 EvaluationResultImpl _check_fromEnvironment_string( |
| 2303 String valueInEnvironment, String defaultExpr) { | 2271 String valueInEnvironment, String defaultExpr) { |
| 2304 String envVarName = "x"; | 2272 String envVarName = "x"; |
| 2305 String varName = "foo"; | 2273 String varName = "foo"; |
| 2306 if (valueInEnvironment != null) { | 2274 if (valueInEnvironment != null) { |
| 2307 analysisContext2.declaredVariables.define(envVarName, valueInEnvironment); | 2275 analysisContext2.declaredVariables.define(envVarName, valueInEnvironment); |
| 2308 } | 2276 } |
| 2309 String defaultArg = | 2277 String defaultArg = |
| 2310 defaultExpr == null ? "" : ", defaultValue: $defaultExpr"; | 2278 defaultExpr == null ? "" : ", defaultValue: $defaultExpr"; |
| 2311 CompilationUnit compilationUnit = resolveSource( | 2279 CompilationUnit compilationUnit = resolveSource( |
| 2312 "const $varName = const String.fromEnvironment('$envVarName'$defaultArg)
;"); | 2280 "const $varName = const String.fromEnvironment('$envVarName'$defaultArg)
;"); |
| 2313 return _evaluateInstanceCreationExpression(compilationUnit, varName); | 2281 return _evaluateTopLevelVariable(compilationUnit, varName); |
| 2314 } | 2282 } |
| 2315 | 2283 |
| 2316 void _checkInstanceCreation_withSupertypeParams(bool isExplicit) { | 2284 void _checkInstanceCreation_withSupertypeParams(bool isExplicit) { |
| 2317 String superCall = isExplicit ? " : super()" : ""; | 2285 String superCall = isExplicit ? " : super()" : ""; |
| 2318 CompilationUnit compilationUnit = resolveSource(""" | 2286 CompilationUnit compilationUnit = resolveSource(""" |
| 2319 class A<T> { | 2287 class A<T> { |
| 2320 const A(); | 2288 const A(); |
| 2321 } | 2289 } |
| 2322 class B<T, U> extends A<T> { | 2290 class B<T, U> extends A<T> { |
| 2323 const B()$superCall; | 2291 const B()$superCall; |
| 2324 } | 2292 } |
| 2325 class C<T, U> extends A<U> { | 2293 class C<T, U> extends A<U> { |
| 2326 const C()$superCall; | 2294 const C()$superCall; |
| 2327 } | 2295 } |
| 2328 const b_int_num = const B<int, num>(); | 2296 const b_int_num = const B<int, num>(); |
| 2329 const c_int_num = const C<int, num>();"""); | 2297 const c_int_num = const C<int, num>();"""); |
| 2330 EvaluationResultImpl b_int_num = | 2298 EvaluationResultImpl b_int_num = |
| 2331 _evaluateInstanceCreationExpression(compilationUnit, "b_int_num"); | 2299 _evaluateTopLevelVariable(compilationUnit, "b_int_num"); |
| 2332 Map<String, DartObjectImpl> b_int_num_fields = | 2300 Map<String, DartObjectImpl> b_int_num_fields = |
| 2333 _assertType(b_int_num, "B<int, num>"); | 2301 _assertType(b_int_num, "B<int, num>"); |
| 2334 _assertFieldType(b_int_num_fields, GenericState.SUPERCLASS_FIELD, "A<int>"); | 2302 _assertFieldType(b_int_num_fields, GenericState.SUPERCLASS_FIELD, "A<int>"); |
| 2335 EvaluationResultImpl c_int_num = | 2303 EvaluationResultImpl c_int_num = |
| 2336 _evaluateInstanceCreationExpression(compilationUnit, "c_int_num"); | 2304 _evaluateTopLevelVariable(compilationUnit, "c_int_num"); |
| 2337 Map<String, DartObjectImpl> c_int_num_fields = | 2305 Map<String, DartObjectImpl> c_int_num_fields = |
| 2338 _assertType(c_int_num, "C<int, num>"); | 2306 _assertType(c_int_num, "C<int, num>"); |
| 2339 _assertFieldType(c_int_num_fields, GenericState.SUPERCLASS_FIELD, "A<num>"); | 2307 _assertFieldType(c_int_num_fields, GenericState.SUPERCLASS_FIELD, "A<num>"); |
| 2340 } | 2308 } |
| 2341 | 2309 |
| 2342 void _checkInstanceCreationOptionalParams( | 2310 void _checkInstanceCreationOptionalParams( |
| 2343 bool isFieldFormal, bool isNamed, bool hasDefault) { | 2311 bool isFieldFormal, bool isNamed, bool hasDefault) { |
| 2344 String fieldName = "j"; | 2312 String fieldName = "j"; |
| 2345 String paramName = isFieldFormal ? fieldName : "i"; | 2313 String paramName = isFieldFormal ? fieldName : "i"; |
| 2346 String formalParam = | 2314 String formalParam = |
| 2347 "${isFieldFormal ? "this." : "int "}$paramName${hasDefault ? " = 3" : ""
}"; | 2315 "${isFieldFormal ? "this." : "int "}$paramName${hasDefault ? " = 3" : ""
}"; |
| 2348 CompilationUnit compilationUnit = resolveSource(""" | 2316 CompilationUnit compilationUnit = resolveSource(""" |
| 2349 const x = const A(); | 2317 const x = const A(); |
| 2350 const y = const A(${isNamed ? '$paramName: ' : ''}10); | 2318 const y = const A(${isNamed ? '$paramName: ' : ''}10); |
| 2351 class A { | 2319 class A { |
| 2352 const A(${isNamed ? "{$formalParam}" : "[$formalParam]"})${isFieldFormal ? ""
: " : $fieldName = $paramName"}; | 2320 const A(${isNamed ? "{$formalParam}" : "[$formalParam]"})${isFieldFormal ? ""
: " : $fieldName = $paramName"}; |
| 2353 final int $fieldName; | 2321 final int $fieldName; |
| 2354 }"""); | 2322 }"""); |
| 2355 EvaluationResultImpl x = | 2323 EvaluationResultImpl x = _evaluateTopLevelVariable(compilationUnit, "x"); |
| 2356 _evaluateInstanceCreationExpression(compilationUnit, "x"); | |
| 2357 Map<String, DartObjectImpl> fieldsOfX = _assertType(x, "A"); | 2324 Map<String, DartObjectImpl> fieldsOfX = _assertType(x, "A"); |
| 2358 expect(fieldsOfX, hasLength(1)); | 2325 expect(fieldsOfX, hasLength(1)); |
| 2359 if (hasDefault) { | 2326 if (hasDefault) { |
| 2360 _assertIntField(fieldsOfX, fieldName, 3); | 2327 _assertIntField(fieldsOfX, fieldName, 3); |
| 2361 } else { | 2328 } else { |
| 2362 _assertNullField(fieldsOfX, fieldName); | 2329 _assertNullField(fieldsOfX, fieldName); |
| 2363 } | 2330 } |
| 2364 EvaluationResultImpl y = | 2331 EvaluationResultImpl y = _evaluateTopLevelVariable(compilationUnit, "y"); |
| 2365 _evaluateInstanceCreationExpression(compilationUnit, "y"); | |
| 2366 Map<String, DartObjectImpl> fieldsOfY = _assertType(y, "A"); | 2332 Map<String, DartObjectImpl> fieldsOfY = _assertType(y, "A"); |
| 2367 expect(fieldsOfY, hasLength(1)); | 2333 expect(fieldsOfY, hasLength(1)); |
| 2368 _assertIntField(fieldsOfY, fieldName, 10); | 2334 _assertIntField(fieldsOfY, fieldName, 10); |
| 2369 } | 2335 } |
| 2370 | 2336 |
| 2371 /** | 2337 /** |
| 2372 * Search [compilationUnit] for a class named [className], containing a | 2338 * Search [compilationUnit] for a class named [className], containing a |
| 2373 * method [methodName], with exactly one annotation. Return the constant | 2339 * method [methodName], with exactly one annotation. Return the constant |
| 2374 * value of the annotation. | 2340 * value of the annotation. |
| 2375 */ | 2341 */ |
| 2376 EvaluationResultImpl _evaluateAnnotation( | 2342 EvaluationResultImpl _evaluateAnnotation( |
| 2377 CompilationUnit compilationUnit, String className, String memberName) { | 2343 CompilationUnit compilationUnit, String className, String memberName) { |
| 2378 for (CompilationUnitMember member in compilationUnit.declarations) { | 2344 for (CompilationUnitMember member in compilationUnit.declarations) { |
| 2379 if (member is ClassDeclaration && member.name.name == className) { | 2345 if (member is ClassDeclaration && member.name.name == className) { |
| 2380 for (ClassMember classMember in member.members) { | 2346 for (ClassMember classMember in member.members) { |
| 2381 if (classMember is MethodDeclaration && | 2347 if (classMember is MethodDeclaration && |
| 2382 classMember.name.name == memberName) { | 2348 classMember.name.name == memberName) { |
| 2383 expect(classMember.metadata, hasLength(1)); | 2349 expect(classMember.metadata, hasLength(1)); |
| 2384 ElementAnnotationImpl elementAnnotation = | 2350 ElementAnnotationImpl elementAnnotation = |
| 2385 classMember.metadata[0].elementAnnotation; | 2351 classMember.metadata[0].elementAnnotation; |
| 2386 return elementAnnotation.evaluationResult; | 2352 return elementAnnotation.evaluationResult; |
| 2387 } | 2353 } |
| 2388 } | 2354 } |
| 2389 } | 2355 } |
| 2390 } | 2356 } |
| 2391 fail('Class member not found'); | 2357 fail('Class member not found'); |
| 2392 return null; | 2358 return null; |
| 2393 } | 2359 } |
| 2394 | 2360 |
| 2395 EvaluationResultImpl _evaluateInstanceCreationExpression( | 2361 EvaluationResultImpl _evaluateTopLevelVariable( |
| 2396 CompilationUnit compilationUnit, String name) { | 2362 CompilationUnit compilationUnit, String name) { |
| 2397 Expression expression = | 2363 VariableDeclaration varDecl = |
| 2398 findTopLevelConstantExpression(compilationUnit, name); | 2364 findTopLevelDeclaration(compilationUnit, name); |
| 2399 return (expression as InstanceCreationExpression).evaluationResult; | 2365 ConstTopLevelVariableElementImpl varElement = varDecl.element; |
| 2366 return varElement.evaluationResult; |
| 2400 } | 2367 } |
| 2401 | 2368 |
| 2402 ConstantValueComputer _makeConstantValueComputer() { | 2369 ConstantValueComputer _makeConstantValueComputer() { |
| 2403 ConstantEvaluationValidator_ForTest validator = | 2370 ConstantEvaluationValidator_ForTest validator = |
| 2404 new ConstantEvaluationValidator_ForTest(); | 2371 new ConstantEvaluationValidator_ForTest(); |
| 2405 validator.computer = new ConstantValueComputer( | 2372 validator.computer = new ConstantValueComputer( |
| 2406 analysisContext2.typeProvider, analysisContext2.declaredVariables, | 2373 analysisContext2.typeProvider, analysisContext2.declaredVariables, |
| 2407 validator); | 2374 validator); |
| 2408 return validator.computer; | 2375 return validator.computer; |
| 2409 } | 2376 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 2431 AstFactory.booleanLiteral(false), thenExpression, elseExpression); | 2398 AstFactory.booleanLiteral(false), thenExpression, elseExpression); |
| 2432 GatheringErrorListener errorListener = new GatheringErrorListener(); | 2399 GatheringErrorListener errorListener = new GatheringErrorListener(); |
| 2433 ErrorReporter errorReporter = | 2400 ErrorReporter errorReporter = |
| 2434 new ErrorReporter(errorListener, _dummySource()); | 2401 new ErrorReporter(errorListener, _dummySource()); |
| 2435 _assertValue(0, expression.accept(new ConstantVisitor( | 2402 _assertValue(0, expression.accept(new ConstantVisitor( |
| 2436 new ConstantEvaluationEngine( | 2403 new ConstantEvaluationEngine( |
| 2437 new TestTypeProvider(), new DeclaredVariables()), errorReporter))); | 2404 new TestTypeProvider(), new DeclaredVariables()), errorReporter))); |
| 2438 errorListener.assertNoErrors(); | 2405 errorListener.assertNoErrors(); |
| 2439 } | 2406 } |
| 2440 | 2407 |
| 2441 void test_visitConditionalExpression_instanceCreation_invalidFieldInitializer(
) { | |
| 2442 TestTypeProvider typeProvider = new TestTypeProvider(); | |
| 2443 LibraryElementImpl libraryElement = ElementFactory.library(null, "lib"); | |
| 2444 String className = "C"; | |
| 2445 ClassElementImpl classElement = ElementFactory.classElement2(className); | |
| 2446 (libraryElement.definingCompilationUnit as CompilationUnitElementImpl).types
= | |
| 2447 <ClassElement>[classElement]; | |
| 2448 ConstructorElementImpl constructorElement = ElementFactory | |
| 2449 .constructorElement(classElement, null, true, [typeProvider.intType]); | |
| 2450 constructorElement.parameters[0] = | |
| 2451 new FieldFormalParameterElementImpl(AstFactory.identifier3("x")); | |
| 2452 InstanceCreationExpression expression = AstFactory | |
| 2453 .instanceCreationExpression2(Keyword.CONST, | |
| 2454 AstFactory.typeName4(className), [AstFactory.integer(0)]); | |
| 2455 expression.staticElement = constructorElement; | |
| 2456 GatheringErrorListener errorListener = new GatheringErrorListener(); | |
| 2457 ErrorReporter errorReporter = | |
| 2458 new ErrorReporter(errorListener, _dummySource()); | |
| 2459 expression.accept(new ConstantVisitor( | |
| 2460 new ConstantEvaluationEngine(typeProvider, new DeclaredVariables()), | |
| 2461 errorReporter)); | |
| 2462 errorListener | |
| 2463 .assertErrorsWithCodes([CompileTimeErrorCode.INVALID_CONSTANT]); | |
| 2464 } | |
| 2465 | |
| 2466 void test_visitConditionalExpression_nonBooleanCondition() { | 2408 void test_visitConditionalExpression_nonBooleanCondition() { |
| 2467 Expression thenExpression = AstFactory.integer(1); | 2409 Expression thenExpression = AstFactory.integer(1); |
| 2468 Expression elseExpression = AstFactory.integer(0); | 2410 Expression elseExpression = AstFactory.integer(0); |
| 2469 NullLiteral conditionExpression = AstFactory.nullLiteral(); | 2411 NullLiteral conditionExpression = AstFactory.nullLiteral(); |
| 2470 ConditionalExpression expression = AstFactory.conditionalExpression( | 2412 ConditionalExpression expression = AstFactory.conditionalExpression( |
| 2471 conditionExpression, thenExpression, elseExpression); | 2413 conditionExpression, thenExpression, elseExpression); |
| 2472 GatheringErrorListener errorListener = new GatheringErrorListener(); | 2414 GatheringErrorListener errorListener = new GatheringErrorListener(); |
| 2473 ErrorReporter errorReporter = | 2415 ErrorReporter errorReporter = |
| 2474 new ErrorReporter(errorListener, _dummySource()); | 2416 new ErrorReporter(errorListener, _dummySource()); |
| 2475 DartObjectImpl result = expression.accept(new ConstantVisitor( | 2417 DartObjectImpl result = expression.accept(new ConstantVisitor( |
| (...skipping 5628 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8104 AstNode _tail; | 8046 AstNode _tail; |
| 8105 @override | 8047 @override |
| 8106 void setUp() { | 8048 void setUp() { |
| 8107 _referenceGraph = new DirectedGraph<AstNode>(); | 8049 _referenceGraph = new DirectedGraph<AstNode>(); |
| 8108 _variableDeclarationMap = | 8050 _variableDeclarationMap = |
| 8109 new HashMap<PotentiallyConstVariableElement, VariableDeclaration>(); | 8051 new HashMap<PotentiallyConstVariableElement, VariableDeclaration>(); |
| 8110 _constructorDeclarationMap = | 8052 _constructorDeclarationMap = |
| 8111 new HashMap<ConstructorElement, ConstructorDeclaration>(); | 8053 new HashMap<ConstructorElement, ConstructorDeclaration>(); |
| 8112 _head = AstFactory.variableDeclaration("v1"); | 8054 _head = AstFactory.variableDeclaration("v1"); |
| 8113 } | 8055 } |
| 8114 void test_visitInstanceCreationExpression_const() { | |
| 8115 _visitNode(_makeTailConstructor("A", true, true, true)); | |
| 8116 _assertOneArc(_tail); | |
| 8117 } | |
| 8118 void test_visitInstanceCreationExpression_nonConstDeclaration() { | |
| 8119 // In the source: | |
| 8120 // const x = const A(); | |
| 8121 // x depends on "const A()" even if the A constructor | |
| 8122 // isn't declared as const. | |
| 8123 _visitNode(_makeTailConstructor("A", false, true, true)); | |
| 8124 _assertOneArc(_tail); | |
| 8125 } | |
| 8126 void test_visitInstanceCreationExpression_nonConstUsage() { | |
| 8127 _visitNode(_makeTailConstructor("A", true, false, true)); | |
| 8128 _assertNoArcs(); | |
| 8129 } | |
| 8130 void test_visitInstanceCreationExpression_notInMap() { | |
| 8131 // In the source: | |
| 8132 // const x = const A(); | |
| 8133 // x depends on "const A()" even if the AST for the A constructor | |
| 8134 // isn't available. | |
| 8135 _visitNode(_makeTailConstructor("A", true, true, false)); | |
| 8136 _assertOneArc(_tail); | |
| 8137 } | |
| 8138 void test_visitSimpleIdentifier_const() { | 8056 void test_visitSimpleIdentifier_const() { |
| 8139 _visitNode(_makeTailVariable("v2", true, true)); | 8057 _visitNode(_makeTailVariable("v2", true, true)); |
| 8140 _assertOneArc(_tail); | 8058 _assertOneArc(_tail); |
| 8141 } | 8059 } |
| 8142 void test_visitSimpleIdentifier_nonConst() { | 8060 void test_visitSimpleIdentifier_nonConst() { |
| 8143 _visitNode(_makeTailVariable("v2", false, true)); | 8061 _visitNode(_makeTailVariable("v2", false, true)); |
| 8144 _assertNoArcs(); | 8062 _assertNoArcs(); |
| 8145 } | 8063 } |
| 8146 void test_visitSimpleIdentifier_notInMap() { | 8064 void test_visitSimpleIdentifier_notInMap() { |
| 8147 _visitNode(_makeTailVariable("v2", true, false)); | 8065 _visitNode(_makeTailVariable("v2", true, false)); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 8171 expect(tails, hasLength(0)); | 8089 expect(tails, hasLength(0)); |
| 8172 } | 8090 } |
| 8173 void _assertOneArc(AstNode tail) { | 8091 void _assertOneArc(AstNode tail) { |
| 8174 Set<AstNode> tails = _referenceGraph.getTails(_head); | 8092 Set<AstNode> tails = _referenceGraph.getTails(_head); |
| 8175 expect(tails, hasLength(1)); | 8093 expect(tails, hasLength(1)); |
| 8176 expect(tails.first, same(tail)); | 8094 expect(tails.first, same(tail)); |
| 8177 } | 8095 } |
| 8178 ReferenceFinder _createReferenceFinder(AstNode source) => new ReferenceFinder( | 8096 ReferenceFinder _createReferenceFinder(AstNode source) => new ReferenceFinder( |
| 8179 source, _referenceGraph, _variableDeclarationMap, | 8097 source, _referenceGraph, _variableDeclarationMap, |
| 8180 _constructorDeclarationMap); | 8098 _constructorDeclarationMap); |
| 8181 InstanceCreationExpression _makeTailConstructor( | |
| 8182 String name, bool isConstDeclaration, bool isConstUsage, bool inMap) { | |
| 8183 List<ConstructorInitializer> initializers = | |
| 8184 new List<ConstructorInitializer>(); | |
| 8185 ConstructorDeclaration constructorDeclaration = AstFactory | |
| 8186 .constructorDeclaration(AstFactory.identifier3(name), null, | |
| 8187 AstFactory.formalParameterList(), initializers); | |
| 8188 if (isConstDeclaration) { | |
| 8189 constructorDeclaration.constKeyword = new KeywordToken(Keyword.CONST, 0); | |
| 8190 } | |
| 8191 ClassElementImpl classElement = ElementFactory.classElement2(name); | |
| 8192 SimpleIdentifier identifier = AstFactory.identifier3(name); | |
| 8193 TypeName type = AstFactory.typeName3(identifier); | |
| 8194 InstanceCreationExpression instanceCreationExpression = AstFactory | |
| 8195 .instanceCreationExpression2( | |
| 8196 isConstUsage ? Keyword.CONST : Keyword.NEW, type); | |
| 8197 _tail = instanceCreationExpression; | |
| 8198 ConstructorElementImpl constructorElement = ElementFactory | |
| 8199 .constructorElement(classElement, name, isConstDeclaration); | |
| 8200 if (inMap) { | |
| 8201 _constructorDeclarationMap[constructorElement] = constructorDeclaration; | |
| 8202 } | |
| 8203 instanceCreationExpression.staticElement = constructorElement; | |
| 8204 return instanceCreationExpression; | |
| 8205 } | |
| 8206 SuperConstructorInvocation _makeTailSuperConstructorInvocation( | 8099 SuperConstructorInvocation _makeTailSuperConstructorInvocation( |
| 8207 String name, bool isConst, bool inMap) { | 8100 String name, bool isConst, bool inMap) { |
| 8208 List<ConstructorInitializer> initializers = | 8101 List<ConstructorInitializer> initializers = |
| 8209 new List<ConstructorInitializer>(); | 8102 new List<ConstructorInitializer>(); |
| 8210 ConstructorDeclaration constructorDeclaration = AstFactory | 8103 ConstructorDeclaration constructorDeclaration = AstFactory |
| 8211 .constructorDeclaration(AstFactory.identifier3(name), null, | 8104 .constructorDeclaration(AstFactory.identifier3(name), null, |
| 8212 AstFactory.formalParameterList(), initializers); | 8105 AstFactory.formalParameterList(), initializers); |
| 8213 _tail = constructorDeclaration; | 8106 _tail = constructorDeclaration; |
| 8214 if (isConst) { | 8107 if (isConst) { |
| 8215 constructorDeclaration.constKeyword = new KeywordToken(Keyword.CONST, 0); | 8108 constructorDeclaration.constKeyword = new KeywordToken(Keyword.CONST, 0); |
| (...skipping 595 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8811 if (_expectedExternalScriptName == null) { | 8704 if (_expectedExternalScriptName == null) { |
| 8812 expect(scriptSource, isNull, reason: "script $scriptIndex"); | 8705 expect(scriptSource, isNull, reason: "script $scriptIndex"); |
| 8813 } else { | 8706 } else { |
| 8814 expect(scriptSource, isNotNull, reason: "script $scriptIndex"); | 8707 expect(scriptSource, isNotNull, reason: "script $scriptIndex"); |
| 8815 String actualExternalScriptName = scriptSource.shortName; | 8708 String actualExternalScriptName = scriptSource.shortName; |
| 8816 expect(actualExternalScriptName, _expectedExternalScriptName, | 8709 expect(actualExternalScriptName, _expectedExternalScriptName, |
| 8817 reason: "script $scriptIndex"); | 8710 reason: "script $scriptIndex"); |
| 8818 } | 8711 } |
| 8819 } | 8712 } |
| 8820 } | 8713 } |
| OLD | NEW |