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

Side by Side Diff: pkg/analyzer/lib/src/generated/resolver.dart

Issue 263913003: New analyzer snapshot. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « pkg/analyzer/lib/src/generated/parser.dart ('k') | pkg/analyzer/lib/src/generated/sdk_io.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 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.resolver; 8 library engine.resolver;
9 9
10 import 'dart:collection'; 10 import 'dart:collection';
(...skipping 726 matching lines...) Expand 10 before | Expand all | Expand 10 after
737 737
738 @override 738 @override
739 Object visitFunctionDeclaration(FunctionDeclaration node) { 739 Object visitFunctionDeclaration(FunctionDeclaration node) {
740 _checkForMissingReturn(node.returnType, node.functionExpression.body); 740 _checkForMissingReturn(node.returnType, node.functionExpression.body);
741 return super.visitFunctionDeclaration(node); 741 return super.visitFunctionDeclaration(node);
742 } 742 }
743 743
744 @override 744 @override
745 Object visitImportDirective(ImportDirective node) { 745 Object visitImportDirective(ImportDirective node) {
746 _checkForDeprecatedMemberUse(node.uriElement, node); 746 _checkForDeprecatedMemberUse(node.uriElement, node);
747 ImportElement importElement = node.element;
748 if (importElement != null) {
749 if (importElement.isDeferred) {
750 _checkForLoadLibraryFunction(node, importElement);
751 }
752 }
747 return super.visitImportDirective(node); 753 return super.visitImportDirective(node);
748 } 754 }
749 755
750 @override 756 @override
751 Object visitIndexExpression(IndexExpression node) { 757 Object visitIndexExpression(IndexExpression node) {
752 _checkForDeprecatedMemberUse(node.bestElement, node); 758 _checkForDeprecatedMemberUse(node.bestElement, node);
753 return super.visitIndexExpression(node); 759 return super.visitIndexExpression(node);
754 } 760 }
755 761
756 @override 762 @override
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
1058 * 1064 *
1059 * @param lhs the left hand side expression 1065 * @param lhs the left hand side expression
1060 * @param rhs the right hand side expression 1066 * @param rhs the right hand side expression
1061 * @return `true` if and only if an error code is generated on the passed node 1067 * @return `true` if and only if an error code is generated on the passed node
1062 * @see HintCode#INVALID_ASSIGNMENT 1068 * @see HintCode#INVALID_ASSIGNMENT
1063 */ 1069 */
1064 bool _checkForInvalidAssignment(Expression lhs, Expression rhs) { 1070 bool _checkForInvalidAssignment(Expression lhs, Expression rhs) {
1065 if (lhs == null || rhs == null) { 1071 if (lhs == null || rhs == null) {
1066 return false; 1072 return false;
1067 } 1073 }
1068 VariableElement leftElement = ErrorVerifier.getVariableElement(lhs); 1074 VariableElement leftVariableElement = ErrorVerifier.getVariableElement(lhs);
1069 DartType leftType = (leftElement == null) ? ErrorVerifier.getStaticType(lhs) : leftElement.type; 1075 DartType leftType = (leftVariableElement == null) ? ErrorVerifier.getStaticT ype(lhs) : leftVariableElement.type;
1070 DartType staticRightType = ErrorVerifier.getStaticType(rhs); 1076 DartType staticRightType = ErrorVerifier.getStaticType(rhs);
1071 if (!staticRightType.isAssignableTo(leftType)) { 1077 if (!staticRightType.isAssignableTo(leftType)) {
1072 // The warning was generated on this rhs 1078 // The warning was generated on this rhs
1073 return false; 1079 return false;
1074 } 1080 }
1075 // Test for, and then generate the hint 1081 // Test for, and then generate the hint
1076 DartType bestRightType = rhs.bestType; 1082 DartType bestRightType = rhs.bestType;
1077 if (leftType != null && bestRightType != null) { 1083 if (leftType != null && bestRightType != null) {
1078 if (!bestRightType.isAssignableTo(leftType)) { 1084 if (!bestRightType.isAssignableTo(leftType)) {
1079 String leftName = leftType.displayName; 1085 String leftName = leftType.displayName;
1080 String rightName = bestRightType.displayName; 1086 String rightName = bestRightType.displayName;
1081 if (leftName == rightName) { 1087 if (leftName == rightName) {
1082 leftName = ErrorVerifier.getExtendedDisplayName(leftType); 1088 Element leftElement = leftType.element;
1083 rightName = ErrorVerifier.getExtendedDisplayName(bestRightType); 1089 Element rightElement = bestRightType.element;
1090 if (leftElement != null && rightElement != null) {
1091 leftName = leftElement.extendedDisplayName;
1092 rightName = rightElement.extendedDisplayName;
1093 }
1084 } 1094 }
1085 _errorReporter.reportErrorForNode(HintCode.INVALID_ASSIGNMENT, rhs, [rig htName, leftName]); 1095 _errorReporter.reportErrorForNode(HintCode.INVALID_ASSIGNMENT, rhs, [rig htName, leftName]);
1086 return true; 1096 return true;
1087 } 1097 }
1088 } 1098 }
1089 return false; 1099 return false;
1090 } 1100 }
1091 1101
1092 /** 1102 /**
1103 * Check that the imported library does not define a loadLibrary function. The import has already
1104 * been determined to be deferred when this is called.
1105 *
1106 * @param node the import directive to evaluate
1107 * @param importElement the [ImportElement] retrieved from the node
1108 * @return `true` if and only if an error code is generated on the passed node
1109 * @see CompileTimeErrorCode#IMPORT_DEFERRED_LIBRARY_WITH_LOAD_FUNCTION
1110 */
1111 bool _checkForLoadLibraryFunction(ImportDirective node, ImportElement importEl ement) {
1112 LibraryElement importedLibrary = importElement.importedLibrary;
1113 if (importedLibrary == null) {
1114 return false;
1115 }
1116 if (importedLibrary.hasLoadLibraryFunction) {
1117 _errorReporter.reportErrorForNode(HintCode.IMPORT_DEFERRED_LIBRARY_WITH_LO AD_FUNCTION, node, [importedLibrary.name]);
1118 return true;
1119 }
1120 return false;
1121 }
1122
1123 /**
1093 * Generate a hint for functions or methods that have a return type, but do no t have a return 1124 * Generate a hint for functions or methods that have a return type, but do no t have a return
1094 * statement on all branches. At the end of blocks with no return, Dart implic itly returns 1125 * statement on all branches. At the end of blocks with no return, Dart implic itly returns
1095 * `null`, avoiding these implicit returns is considered a best practice. 1126 * `null`, avoiding these implicit returns is considered a best practice.
1096 * 1127 *
1097 * @param node the binary expression to check 1128 * @param node the binary expression to check
1098 * @param body the function body 1129 * @param body the function body
1099 * @return `true` if and only if a hint code is generated on the passed node 1130 * @return `true` if and only if a hint code is generated on the passed node
1100 * @see HintCode#MISSING_RETURN 1131 * @see HintCode#MISSING_RETURN
1101 */ 1132 */
1102 bool _checkForMissingReturn(TypeName returnType, FunctionBody body) { 1133 bool _checkForMissingReturn(TypeName returnType, FunctionBody body) {
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after
1455 VariableElementImpl element = node.element as VariableElementImpl; 1486 VariableElementImpl element = node.element as VariableElementImpl;
1456 EvaluationResultImpl result = element.evaluationResult; 1487 EvaluationResultImpl result = element.evaluationResult;
1457 if (result == null) { 1488 if (result == null) {
1458 // 1489 //
1459 // Normally we don't need to visit const variable declarations because w e have already 1490 // Normally we don't need to visit const variable declarations because w e have already
1460 // computed their values. But if we missed it for some reason, this give s us a second 1491 // computed their values. But if we missed it for some reason, this give s us a second
1461 // chance. 1492 // chance.
1462 // 1493 //
1463 result = _validate(initializer, CompileTimeErrorCode.CONST_INITIALIZED_W ITH_NON_CONSTANT_VALUE); 1494 result = _validate(initializer, CompileTimeErrorCode.CONST_INITIALIZED_W ITH_NON_CONSTANT_VALUE);
1464 element.evaluationResult = result; 1495 element.evaluationResult = result;
1496 return null;
1465 } else if (result is ErrorResult) { 1497 } else if (result is ErrorResult) {
1466 _reportErrors(result, CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CO NSTANT_VALUE); 1498 _reportErrors(result, CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CO NSTANT_VALUE);
1499 return null;
1500 }
1501 DeferredLibraryReferenceDetector referenceDetector = new DeferredLibraryRe ferenceDetector();
1502 initializer.accept(referenceDetector);
1503 if (referenceDetector.result) {
1504 _errorReporter.reportErrorForNode(CompileTimeErrorCode.CONST_INITIALIZED _WITH_NON_CONSTANT_VALUE_FROM_DEFERRED_LIBRARY, initializer, []);
1505 return null;
1467 } 1506 }
1468 } 1507 }
1469 return null; 1508 return null;
1470 } 1509 }
1471 1510
1472 /** 1511 /**
1473 * If the given result represents one or more errors, report those errors. Exc ept for special 1512 * If the given result represents one or more errors, report those errors. Exc ept for special
1474 * cases, use the given error code rather than the one reported in the error. 1513 * cases, use the given error code rather than the one reported in the error.
1475 * 1514 *
1476 * @param result the result containing any errors that need to be reported 1515 * @param result the result containing any errors that need to be reported
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1530 return; 1569 return;
1531 } 1570 }
1532 for (FormalParameter parameter in parameters.parameters) { 1571 for (FormalParameter parameter in parameters.parameters) {
1533 if (parameter is DefaultFormalParameter) { 1572 if (parameter is DefaultFormalParameter) {
1534 DefaultFormalParameter defaultParameter = parameter; 1573 DefaultFormalParameter defaultParameter = parameter;
1535 Expression defaultValue = defaultParameter.defaultValue; 1574 Expression defaultValue = defaultParameter.defaultValue;
1536 if (defaultValue != null) { 1575 if (defaultValue != null) {
1537 EvaluationResultImpl result = _validate(defaultValue, CompileTimeError Code.NON_CONSTANT_DEFAULT_VALUE); 1576 EvaluationResultImpl result = _validate(defaultValue, CompileTimeError Code.NON_CONSTANT_DEFAULT_VALUE);
1538 VariableElementImpl element = parameter.element as VariableElementImpl ; 1577 VariableElementImpl element = parameter.element as VariableElementImpl ;
1539 element.evaluationResult = result; 1578 element.evaluationResult = result;
1579 DeferredLibraryReferenceDetector referenceDetector = new DeferredLibra ryReferenceDetector();
1580 defaultValue.accept(referenceDetector);
1581 if (result is ValidResult && referenceDetector.result) {
1582 _errorReporter.reportErrorForNode(CompileTimeErrorCode.NON_CONSTANT_ DEFAULT_VALUE_FROM_DEFERRED_LIBRARY, defaultValue, []);
1583 }
1540 } 1584 }
1541 } 1585 }
1542 } 1586 }
1543 } 1587 }
1544 1588
1545 /** 1589 /**
1546 * Validates that the given expression is a compile time constant. 1590 * Validates that the given expression is a compile time constant.
1547 * 1591 *
1548 * @param parameterElements the elements of parameters of constant constructor , they are 1592 * @param parameterElements the elements of parameters of constant constructor , they are
1549 * considered as a valid potentially constant expressions 1593 * considered as a valid potentially constant expressions
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
1764 1808
1765 /** 1809 /**
1766 * For each [Block], this method reports and error on all statements between t he end of the 1810 * For each [Block], this method reports and error on all statements between t he end of the
1767 * block and the first return statement (assuming there it is not at the end o f the block.) 1811 * block and the first return statement (assuming there it is not at the end o f the block.)
1768 * 1812 *
1769 * @param node the block to evaluate 1813 * @param node the block to evaluate
1770 */ 1814 */
1771 @override 1815 @override
1772 Object visitBlock(Block node) { 1816 Object visitBlock(Block node) {
1773 NodeList<Statement> statements = node.statements; 1817 NodeList<Statement> statements = node.statements;
1774 int size = statements.length; 1818 _checkForDeadStatementsInNodeList(statements);
1775 for (int i = 0; i < size; i++) {
1776 Statement currentStatement = statements[i];
1777 _safelyVisit(currentStatement);
1778 if (currentStatement is ReturnStatement && i != size - 1) {
1779 Statement nextStatement = statements[i + 1];
1780 Statement lastStatement = statements[size - 1];
1781 int offset = nextStatement.offset;
1782 int length = lastStatement.end - offset;
1783 _errorReporter.reportErrorForOffset(HintCode.DEAD_CODE, offset, length, []);
1784 return null;
1785 }
1786 }
1787 return null; 1819 return null;
1788 } 1820 }
1789 1821
1790 @override 1822 @override
1791 Object visitConditionalExpression(ConditionalExpression node) { 1823 Object visitConditionalExpression(ConditionalExpression node) {
1792 Expression conditionExpression = node.condition; 1824 Expression conditionExpression = node.condition;
1793 _safelyVisit(conditionExpression); 1825 _safelyVisit(conditionExpression);
1794 if (!_isDebugConstant(conditionExpression)) { 1826 if (!_isDebugConstant(conditionExpression)) {
1795 ValidResult result = _getConstantBooleanValue(conditionExpression); 1827 ValidResult result = _getConstantBooleanValue(conditionExpression);
1796 if (result != null) { 1828 if (result != null) {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1830 _errorReporter.reportErrorForNode(HintCode.DEAD_CODE, node.thenStateme nt, []); 1862 _errorReporter.reportErrorForNode(HintCode.DEAD_CODE, node.thenStateme nt, []);
1831 _safelyVisit(node.elseStatement); 1863 _safelyVisit(node.elseStatement);
1832 return null; 1864 return null;
1833 } 1865 }
1834 } 1866 }
1835 } 1867 }
1836 return super.visitIfStatement(node); 1868 return super.visitIfStatement(node);
1837 } 1869 }
1838 1870
1839 @override 1871 @override
1872 Object visitSwitchCase(SwitchCase node) {
1873 _checkForDeadStatementsInNodeList(node.statements);
1874 return super.visitSwitchCase(node);
1875 }
1876
1877 @override
1878 Object visitSwitchDefault(SwitchDefault node) {
1879 _checkForDeadStatementsInNodeList(node.statements);
1880 return super.visitSwitchDefault(node);
1881 }
1882
1883 @override
1840 Object visitTryStatement(TryStatement node) { 1884 Object visitTryStatement(TryStatement node) {
1841 _safelyVisit(node.body); 1885 _safelyVisit(node.body);
1842 _safelyVisit(node.finallyBlock); 1886 _safelyVisit(node.finallyBlock);
1843 NodeList<CatchClause> catchClauses = node.catchClauses; 1887 NodeList<CatchClause> catchClauses = node.catchClauses;
1844 int numOfCatchClauses = catchClauses.length; 1888 int numOfCatchClauses = catchClauses.length;
1845 List<DartType> visitedTypes = new List<DartType>(); 1889 List<DartType> visitedTypes = new List<DartType>();
1846 for (int i = 0; i < numOfCatchClauses; i++) { 1890 for (int i = 0; i < numOfCatchClauses; i++) {
1847 CatchClause catchClause = catchClauses[i]; 1891 CatchClause catchClause = catchClauses[i];
1848 if (catchClause.onKeyword != null) { 1892 if (catchClause.onKeyword != null) {
1849 // on-catch clause found, verify that the exception type is not a subtyp e of a previous 1893 // on-catch clause found, verify that the exception type is not a subtyp e of a previous
1850 // on-catch exception type 1894 // on-catch exception type
1851 TypeName typeName = catchClause.exceptionType; 1895 TypeName typeName = catchClause.exceptionType;
1852 if (typeName != null && typeName.type != null) { 1896 if (typeName != null && typeName.type != null) {
1853 DartType currentType = typeName.type; 1897 DartType currentType = typeName.type;
1854 if (currentType.isObject) { 1898 if (currentType.isObject) {
1855 // Found catch clause clause that has Object as an exception type, t his is equivalent to 1899 // Found catch clause clause that has Object as an exception type, t his is equivalent to
1856 // having a catch clause that doesn't have an exception type, visit the block, but 1900 // having a catch clause that doesn't have an exception type, visit the block, but
1857 // generate an error on any following catch clauses (and don't visit them). 1901 // generate an error on any following catch clauses (and don't visi t them).
1858 _safelyVisit(catchClause); 1902 _safelyVisit(catchClause);
1859 if (i + 1 != numOfCatchClauses) { 1903 if (i + 1 != numOfCatchClauses) {
1860 // this catch clause is not the last in the try statement 1904 // this catch clause is not the last in the try statement
1861 CatchClause nextCatchClause = catchClauses[i + 1]; 1905 CatchClause nextCatchClause = catchClauses[i + 1];
1862 CatchClause lastCatchClause = catchClauses[numOfCatchClauses - 1]; 1906 CatchClause lastCatchClause = catchClauses[numOfCatchClauses - 1];
1863 int offset = nextCatchClause.offset; 1907 int offset = nextCatchClause.offset;
1864 int length = lastCatchClause.end - offset; 1908 int length = lastCatchClause.end - offset;
1865 _errorReporter.reportErrorForOffset(HintCode.DEAD_CODE_CATCH_FOLLO WING_CATCH, offset, length, []); 1909 _errorReporter.reportErrorForOffset(HintCode.DEAD_CODE_CATCH_FOLLO WING_CATCH, offset, length, []);
1866 return null; 1910 return null;
1867 } 1911 }
1868 } 1912 }
1869 for (DartType type in visitedTypes) { 1913 for (DartType type in visitedTypes) {
1870 if (currentType.isSubtypeOf(type)) { 1914 if (currentType.isSubtypeOf(type)) {
1871 CatchClause lastCatchClause = catchClauses[numOfCatchClauses - 1]; 1915 CatchClause lastCatchClause = catchClauses[numOfCatchClauses - 1];
1872 int offset = catchClause.offset; 1916 int offset = catchClause.offset;
1873 int length = lastCatchClause.end - offset; 1917 int length = lastCatchClause.end - offset;
1874 _errorReporter.reportErrorForOffset(HintCode.DEAD_CODE_ON_CATCH_SU BTYPE, offset, length, [currentType.displayName, type.displayName]); 1918 _errorReporter.reportErrorForOffset(HintCode.DEAD_CODE_ON_CATCH_SU BTYPE, offset, length, [currentType.displayName, type.displayName]);
1875 return null; 1919 return null;
1876 } 1920 }
1877 } 1921 }
1878 visitedTypes.add(currentType); 1922 visitedTypes.add(currentType);
1879 } 1923 }
1880 _safelyVisit(catchClause); 1924 _safelyVisit(catchClause);
1881 } else { 1925 } else {
1882 // Found catch clause clause that doesn't have an exception type, visit the block, but 1926 // Found catch clause clause that doesn't have an exception type, visit the block, but
1883 // generate an error on any following catch clauses (and don't visit the m). 1927 // generate an error on any following catch clauses (and don't visit the m).
1884 _safelyVisit(catchClause); 1928 _safelyVisit(catchClause);
1885 if (i + 1 != numOfCatchClauses) { 1929 if (i + 1 != numOfCatchClauses) {
1886 // this catch clause is not the last in the try statement 1930 // this catch clause is not the last in the try statement
1887 CatchClause nextCatchClause = catchClauses[i + 1]; 1931 CatchClause nextCatchClause = catchClauses[i + 1];
1888 CatchClause lastCatchClause = catchClauses[numOfCatchClauses - 1]; 1932 CatchClause lastCatchClause = catchClauses[numOfCatchClauses - 1];
1889 int offset = nextCatchClause.offset; 1933 int offset = nextCatchClause.offset;
1890 int length = lastCatchClause.end - offset; 1934 int length = lastCatchClause.end - offset;
1891 _errorReporter.reportErrorForOffset(HintCode.DEAD_CODE_CATCH_FOLLOWING _CATCH, offset, length, []); 1935 _errorReporter.reportErrorForOffset(HintCode.DEAD_CODE_CATCH_FOLLOWING _CATCH, offset, length, []);
1892 return null; 1936 return null;
(...skipping 15 matching lines...) Expand all
1908 _errorReporter.reportErrorForNode(HintCode.DEAD_CODE, node.body, []); 1952 _errorReporter.reportErrorForNode(HintCode.DEAD_CODE, node.body, []);
1909 return null; 1953 return null;
1910 } 1954 }
1911 } 1955 }
1912 } 1956 }
1913 _safelyVisit(node.body); 1957 _safelyVisit(node.body);
1914 return null; 1958 return null;
1915 } 1959 }
1916 1960
1917 /** 1961 /**
1962 * Given some [NodeList] of [Statement]s, from either a [Block] or
1963 * [SwitchMember], this loops through the list in reverse order searching for statements
1964 * after a return, unlabeled break or unlabeled continue statement to mark the m as dead code.
1965 *
1966 * @param statements some ordered list of statements in a [Block] or [SwitchMe mber]
1967 */
1968 void _checkForDeadStatementsInNodeList(NodeList<Statement> statements) {
1969 int size = statements.length;
1970 for (int i = 0; i < size; i++) {
1971 Statement currentStatement = statements[i];
1972 _safelyVisit(currentStatement);
1973 bool returnOrBreakingStatement = currentStatement is ReturnStatement || (c urrentStatement is BreakStatement && currentStatement.label == null) || (current Statement is ContinueStatement && currentStatement.label == null);
1974 if (returnOrBreakingStatement && i != size - 1) {
1975 Statement nextStatement = statements[i + 1];
1976 Statement lastStatement = statements[size - 1];
1977 int offset = nextStatement.offset;
1978 int length = lastStatement.end - offset;
1979 _errorReporter.reportErrorForOffset(HintCode.DEAD_CODE, offset, length, []);
1980 return;
1981 }
1982 }
1983 }
1984
1985 /**
1918 * Given some [Expression], this method returns [ValidResult#RESULT_TRUE] if i t is 1986 * Given some [Expression], this method returns [ValidResult#RESULT_TRUE] if i t is
1919 * `true`, [ValidResult#RESULT_FALSE] if it is `false`, or `null` if the 1987 * `true`, [ValidResult#RESULT_FALSE] if it is `false`, or `null` if the
1920 * expression is not a constant boolean value. 1988 * expression is not a constant boolean value.
1921 * 1989 *
1922 * @param expression the expression to evaluate 1990 * @param expression the expression to evaluate
1923 * @return [ValidResult#RESULT_TRUE] if it is `true`, [ValidResult#RESULT_FALS E] 1991 * @return [ValidResult#RESULT_TRUE] if it is `true`, [ValidResult#RESULT_FALS E]
1924 * if it is `false`, or `null` if the expression is not a constant boo lean 1992 * if it is `false`, or `null` if the expression is not a constant boo lean
1925 * value 1993 * value
1926 */ 1994 */
1927 ValidResult _getConstantBooleanValue(Expression expression) { 1995 ValidResult _getConstantBooleanValue(Expression expression) {
1928 if (expression is BooleanLiteral) { 1996 if (expression is BooleanLiteral) {
1929 if (expression.value) { 1997 if (expression.value) {
1930 return new ValidResult(new DartObjectImpl(null, BoolState.from(true))); 1998 return new ValidResult(new DartObjectImpl(null, BoolState.from(true)));
1931 } else { 1999 } else {
1932 return new ValidResult(new DartObjectImpl(null, BoolState.from(false))); 2000 return new ValidResult(new DartObjectImpl(null, BoolState.from(false)));
1933 } 2001 }
1934 } 2002 }
1935 // Don't consider situations where we could evaluate to a constant boolean e xpression with the 2003 // Don't consider situations where we could evaluate to a constant boolean e xpression with the
1936 // ConstantVisitor 2004 // ConstantVisitor
1937 // else { 2005 //
1938 // EvaluationResultImpl result = expression.accept(new ConstantVisitor( )); 2006 // else {
1939 // if (result == ValidResult.RESULT_TRUE) { 2007 //
1940 // return ValidResult.RESULT_TRUE; 2008 // EvaluationResultImpl result = expression.accept(new ConstantVisitor( ));
1941 // } else if (result == ValidResult.RESULT_FALSE) { 2009 //
1942 // return ValidResult.RESULT_FALSE; 2010 // if (result == ValidResult.RESULT_TRUE) {
1943 // } 2011 //
1944 // return null; 2012 // return ValidResult.RESULT_TRUE;
1945 // } 2013 //
2014 // } else if (result == ValidResult.RESULT_FALSE) {
2015 //
2016 // return ValidResult.RESULT_FALSE;
2017 //
2018 // }
2019 //
2020 // return null;
2021 //
2022 // }
1946 return null; 2023 return null;
1947 } 2024 }
1948 2025
1949 /** 2026 /**
1950 * Return `true` if and only if the passed expression is resolved to a constan t variable. 2027 * Return `true` if and only if the passed expression is resolved to a constan t variable.
1951 * 2028 *
1952 * @param expression some conditional expression 2029 * @param expression some conditional expression
1953 * @return `true` if and only if the passed expression is resolved to a consta nt variable 2030 * @return `true` if and only if the passed expression is resolved to a consta nt variable
1954 */ 2031 */
1955 bool _isDebugConstant(Expression expression) { 2032 bool _isDebugConstant(Expression expression) {
(...skipping 2468 matching lines...) Expand 10 before | Expand all | Expand 10 after
4424 * A utility class for the resolver to answer the question of "what are my sub types?". 4501 * A utility class for the resolver to answer the question of "what are my sub types?".
4425 */ 4502 */
4426 SubtypeManager _subtypeManager; 4503 SubtypeManager _subtypeManager;
4427 4504
4428 /** 4505 /**
4429 * The object keeping track of which elements have had their types promoted. 4506 * The object keeping track of which elements have had their types promoted.
4430 */ 4507 */
4431 TypePromotionManager _promoteManager; 4508 TypePromotionManager _promoteManager;
4432 4509
4433 /** 4510 /**
4434 * The name of the method that can be implemented by a class to allow its inst ances to be invoked
4435 * as if they were a function.
4436 */
4437 static String CALL_METHOD_NAME = "call";
4438
4439 /**
4440 * The name of the method that will be invoked if an attempt is made to invoke an undefined method
4441 * on an object.
4442 */
4443 static String NO_SUCH_METHOD_METHOD_NAME = "noSuchMethod";
4444
4445 /**
4446 * Initialize a newly created visitor to resolve the nodes in a compilation un it. 4511 * Initialize a newly created visitor to resolve the nodes in a compilation un it.
4447 * 4512 *
4448 * @param resolver the resolver driving this participant 4513 * @param resolver the resolver driving this participant
4449 */ 4514 */
4450 ElementResolver(this._resolver) { 4515 ElementResolver(this._resolver) {
4451 this._definingLibrary = _resolver.definingLibrary; 4516 this._definingLibrary = _resolver.definingLibrary;
4452 AnalysisOptions options = _definingLibrary.context.analysisOptions; 4517 AnalysisOptions options = _definingLibrary.context.analysisOptions;
4453 _enableHints = options.hint; 4518 _enableHints = options.hint;
4454 _dynamicType = _resolver.typeProvider.dynamicType; 4519 _dynamicType = _resolver.typeProvider.dynamicType;
4455 _typeType = _resolver.typeProvider.typeType; 4520 _typeType = _resolver.typeProvider.typeType;
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after
4858 // 4923 //
4859 Expression target = node.realTarget; 4924 Expression target = node.realTarget;
4860 if (target is SuperExpression && !_isSuperInValidContext(target)) { 4925 if (target is SuperExpression && !_isSuperInValidContext(target)) {
4861 return null; 4926 return null;
4862 } 4927 }
4863 Element staticElement; 4928 Element staticElement;
4864 Element propagatedElement; 4929 Element propagatedElement;
4865 if (target == null) { 4930 if (target == null) {
4866 staticElement = _resolveInvokedElement(methodName); 4931 staticElement = _resolveInvokedElement(methodName);
4867 propagatedElement = null; 4932 propagatedElement = null;
4868 } else if (_isDeferredPrefix(target) && methodName.name == FunctionElement.L OAD_LIBRARY_NAME) { 4933 } else if (methodName.name == FunctionElement.LOAD_LIBRARY_NAME && _isDeferr edPrefix(target)) {
4869 LibraryElement importedLibrary = _getImportedLibrary(target); 4934 LibraryElement importedLibrary = _getImportedLibrary(target);
4870 methodName.staticElement = importedLibrary.loadLibraryFunction; 4935 methodName.staticElement = importedLibrary.loadLibraryFunction;
4871 return null; 4936 return null;
4872 } else { 4937 } else {
4873 DartType staticType = _getStaticType(target); 4938 DartType staticType = _getStaticType(target);
4874 // 4939 //
4875 // If this method invocation is of the form 'C.m' where 'C' is a class, th en we don't call 4940 // If this method invocation is of the form 'C.m' where 'C' is a class, th en we don't call
4876 // resolveInvokedElement(..) which walks up the class hierarchy, instead w e just look for the 4941 // resolveInvokedElement(..) which walks up the class hierarchy, instead w e just look for the
4877 // member in the type only. 4942 // member in the type only.
4878 // 4943 //
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
4958 DartType targetType = null; 5023 DartType targetType = null;
4959 if (!generatedWithTypePropagation) { 5024 if (!generatedWithTypePropagation) {
4960 targetType = _getStaticType(target); 5025 targetType = _getStaticType(target);
4961 } else { 5026 } else {
4962 // choose the best type 5027 // choose the best type
4963 targetType = _getPropagatedType(target); 5028 targetType = _getPropagatedType(target);
4964 if (targetType == null) { 5029 if (targetType == null) {
4965 targetType = _getStaticType(target); 5030 targetType = _getStaticType(target);
4966 } 5031 }
4967 } 5032 }
4968 if (targetType != null && targetType.isDartCoreFunction && methodName.na me == CALL_METHOD_NAME) { 5033 if (targetType != null && targetType.isDartCoreFunction && methodName.na me == FunctionElement.CALL_METHOD_NAME) {
4969 // TODO(brianwilkerson) Can we ever resolve the function being invoked ? 5034 // TODO(brianwilkerson) Can we ever resolve the function being invoked ?
4970 //resolveArgumentsToParameters(node.getArgumentList(), invokedFunction ); 5035 //resolveArgumentsToParameters(node.getArgumentList(), invokedFunction );
4971 return null; 5036 return null;
4972 } 5037 }
4973 targetTypeName = targetType == null ? null : targetType.displayName; 5038 targetTypeName = targetType == null ? null : targetType.displayName;
4974 ErrorCode proxyErrorCode = (generatedWithTypePropagation ? HintCode.UNDE FINED_METHOD : StaticTypeWarningCode.UNDEFINED_METHOD); 5039 ErrorCode proxyErrorCode = (generatedWithTypePropagation ? HintCode.UNDE FINED_METHOD : StaticTypeWarningCode.UNDEFINED_METHOD);
4975 if (_doesClassElementHaveProxy(targetType.element)) { 5040 if (_doesClassElementHaveProxy(targetType.element)) {
4976 _resolver.reportErrorForNode(proxyErrorCode, methodName, [methodName.n ame, targetTypeName]); 5041 _resolver.reportErrorForNode(proxyErrorCode, methodName, [methodName.n ame, targetTypeName]);
4977 } 5042 }
4978 } 5043 }
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
5018 } 5083 }
5019 } 5084 }
5020 return null; 5085 return null;
5021 } 5086 }
5022 5087
5023 @override 5088 @override
5024 Object visitPrefixedIdentifier(PrefixedIdentifier node) { 5089 Object visitPrefixedIdentifier(PrefixedIdentifier node) {
5025 SimpleIdentifier prefix = node.prefix; 5090 SimpleIdentifier prefix = node.prefix;
5026 SimpleIdentifier identifier = node.identifier; 5091 SimpleIdentifier identifier = node.identifier;
5027 // 5092 //
5028 // First, check to see whether the prefix is really a prefix. 5093 // First, check the "lib.loadLibrary" case
5094 //
5095 if (identifier.name == FunctionElement.LOAD_LIBRARY_NAME && _isDeferredPrefi x(prefix)) {
5096 LibraryElement importedLibrary = _getImportedLibrary(prefix);
5097 identifier.staticElement = importedLibrary.loadLibraryFunction;
5098 return null;
5099 }
5100 //
5101 // Check to see whether the prefix is really a prefix.
5029 // 5102 //
5030 Element prefixElement = prefix.staticElement; 5103 Element prefixElement = prefix.staticElement;
5031 if (prefixElement is PrefixElement) { 5104 if (prefixElement is PrefixElement) {
5032 Element element = _resolver.nameScope.lookup(node, _definingLibrary); 5105 Element element = _resolver.nameScope.lookup(node, _definingLibrary);
5033 if (element == null && identifier.inSetterContext()) { 5106 if (element == null && identifier.inSetterContext()) {
5034 element = _resolver.nameScope.lookup(new ElementResolver_SyntheticIdenti fier("${node.name}="), _definingLibrary); 5107 element = _resolver.nameScope.lookup(new ElementResolver_SyntheticIdenti fier("${node.name}="), _definingLibrary);
5035 } 5108 }
5036 if (element == null) { 5109 if (element == null) {
5037 if (identifier.inSetterContext()) { 5110 if (identifier.inSetterContext()) {
5038 _resolver.reportErrorForNode(StaticWarningCode.UNDEFINED_SETTER, ident ifier, [identifier.name, prefixElement.name]); 5111 _resolver.reportErrorForNode(StaticWarningCode.UNDEFINED_SETTER, ident ifier, [identifier.name, prefixElement.name]);
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after
5424 */ 5497 */
5425 List<ParameterElement> _computeCorrespondingParameters(ArgumentList argumentLi st, Element element) { 5498 List<ParameterElement> _computeCorrespondingParameters(ArgumentList argumentLi st, Element element) {
5426 if (element is PropertyAccessorElement) { 5499 if (element is PropertyAccessorElement) {
5427 // 5500 //
5428 // This is an invocation of the call method defined on the value returned by the getter. 5501 // This is an invocation of the call method defined on the value returned by the getter.
5429 // 5502 //
5430 FunctionType getterType = element.type; 5503 FunctionType getterType = element.type;
5431 if (getterType != null) { 5504 if (getterType != null) {
5432 DartType getterReturnType = getterType.returnType; 5505 DartType getterReturnType = getterType.returnType;
5433 if (getterReturnType is InterfaceType) { 5506 if (getterReturnType is InterfaceType) {
5434 MethodElement callMethod = getterReturnType.lookUpMethod(CALL_METHOD_N AME, _definingLibrary); 5507 MethodElement callMethod = getterReturnType.lookUpMethod(FunctionEleme nt.CALL_METHOD_NAME, _definingLibrary);
5435 if (callMethod != null) { 5508 if (callMethod != null) {
5436 return _resolveArgumentsToFunction(false, argumentList, callMethod); 5509 return _resolveArgumentsToFunction(false, argumentList, callMethod);
5437 } 5510 }
5438 } else if (getterReturnType is FunctionType) { 5511 } else if (getterReturnType is FunctionType) {
5439 Element functionElement = getterReturnType.element; 5512 Element functionElement = getterReturnType.element;
5440 if (functionElement is ExecutableElement) { 5513 if (functionElement is ExecutableElement) {
5441 return _resolveArgumentsToFunction(false, argumentList, functionElem ent); 5514 return _resolveArgumentsToFunction(false, argumentList, functionElem ent);
5442 } 5515 }
5443 } 5516 }
5444 } 5517 }
5445 } else if (element is ExecutableElement) { 5518 } else if (element is ExecutableElement) {
5446 return _resolveArgumentsToFunction(false, argumentList, element); 5519 return _resolveArgumentsToFunction(false, argumentList, element);
5447 } else if (element is VariableElement) { 5520 } else if (element is VariableElement) {
5448 VariableElement variable = element; 5521 VariableElement variable = element;
5449 DartType type = _promoteManager.getStaticType(variable); 5522 DartType type = _promoteManager.getStaticType(variable);
5450 if (type is FunctionType) { 5523 if (type is FunctionType) {
5451 FunctionType functionType = type; 5524 FunctionType functionType = type;
5452 List<ParameterElement> parameters = functionType.parameters; 5525 List<ParameterElement> parameters = functionType.parameters;
5453 return _resolveArgumentsToParameters(false, argumentList, parameters); 5526 return _resolveArgumentsToParameters(false, argumentList, parameters);
5454 } else if (type is InterfaceType) { 5527 } else if (type is InterfaceType) {
5455 // "call" invocation 5528 // "call" invocation
5456 MethodElement callMethod = type.lookUpMethod(CALL_METHOD_NAME, _defining Library); 5529 MethodElement callMethod = type.lookUpMethod(FunctionElement.CALL_METHOD _NAME, _definingLibrary);
5457 if (callMethod != null) { 5530 if (callMethod != null) {
5458 List<ParameterElement> parameters = callMethod.parameters; 5531 List<ParameterElement> parameters = callMethod.parameters;
5459 return _resolveArgumentsToParameters(false, argumentList, parameters); 5532 return _resolveArgumentsToParameters(false, argumentList, parameters);
5460 } 5533 }
5461 } 5534 }
5462 } 5535 }
5463 return null; 5536 return null;
5464 } 5537 }
5465 5538
5466 /** 5539 /**
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
5632 if (type.isDynamic || (type is FunctionType) || type.isDartCoreFunction || t ype.isObject) { 5705 if (type.isDynamic || (type is FunctionType) || type.isDartCoreFunction || t ype.isObject) {
5633 return true; 5706 return true;
5634 } else if (type is InterfaceType) { 5707 } else if (type is InterfaceType) {
5635 ClassElement classElement = type.element; 5708 ClassElement classElement = type.element;
5636 // 16078 from Gilad: If the type is a Functor with the @proxy annotation, treat it as an 5709 // 16078 from Gilad: If the type is a Functor with the @proxy annotation, treat it as an
5637 // executable type. 5710 // executable type.
5638 // example code: NonErrorResolverTest.test_invocationOfNonFunction_proxyOn FunctionClass() 5711 // example code: NonErrorResolverTest.test_invocationOfNonFunction_proxyOn FunctionClass()
5639 if (classElement.isProxy && type.isSubtypeOf(_resolver.typeProvider.functi onType)) { 5712 if (classElement.isProxy && type.isSubtypeOf(_resolver.typeProvider.functi onType)) {
5640 return true; 5713 return true;
5641 } 5714 }
5642 MethodElement methodElement = classElement.lookUpMethod(CALL_METHOD_NAME, _definingLibrary); 5715 MethodElement methodElement = classElement.lookUpMethod(FunctionElement.CA LL_METHOD_NAME, _definingLibrary);
5643 return methodElement != null; 5716 return methodElement != null;
5644 } 5717 }
5645 return false; 5718 return false;
5646 } 5719 }
5647 5720
5648 /** 5721 /**
5649 * @return `true` iff current enclosing function is constant constructor decla ration. 5722 * @return `true` iff current enclosing function is constant constructor decla ration.
5650 */ 5723 */
5651 bool get isInConstConstructor { 5724 bool get isInConstConstructor {
5652 ExecutableElement function = _resolver.enclosingFunction; 5725 ExecutableElement function = _resolver.enclosingFunction;
(...skipping 1151 matching lines...) Expand 10 before | Expand all | Expand 10 after
6804 return enclosingScope.internalLookup(identifier, name, referencingLibrary); 6877 return enclosingScope.internalLookup(identifier, name, referencingLibrary);
6805 } 6878 }
6806 } 6879 }
6807 6880
6808 /** 6881 /**
6809 * Instances of the class `ErrorVerifier` traverse an AST structure looking for additional 6882 * Instances of the class `ErrorVerifier` traverse an AST structure looking for additional
6810 * errors and warnings not covered by the parser and resolver. 6883 * errors and warnings not covered by the parser and resolver.
6811 */ 6884 */
6812 class ErrorVerifier extends RecursiveAstVisitor<Object> { 6885 class ErrorVerifier extends RecursiveAstVisitor<Object> {
6813 /** 6886 /**
6814 * Return a display name for the given type that includes the path to the comp ilation unit in
6815 * which the type is defined.
6816 *
6817 * @param type the type for which an extended display name is to be returned
6818 * @return a display name that can help distiguish between two types with the same name
6819 */
6820 static String getExtendedDisplayName(DartType type) {
6821 Element element = type.element;
6822 if (element != null) {
6823 Source source = element.source;
6824 if (source != null) {
6825 return "${type.displayName} (${source.fullName})";
6826 }
6827 }
6828 return type.displayName;
6829 }
6830
6831 /**
6832 * Return the static type of the given expression that is to be used for type analysis. 6887 * Return the static type of the given expression that is to be used for type analysis.
6833 * 6888 *
6834 * @param expression the expression whose type is to be returned 6889 * @param expression the expression whose type is to be returned
6835 * @return the static type of the given expression 6890 * @return the static type of the given expression
6836 */ 6891 */
6837 static DartType getStaticType(Expression expression) { 6892 static DartType getStaticType(Expression expression) {
6838 DartType type = expression.staticType; 6893 DartType type = expression.staticType;
6839 if (type == null) { 6894 if (type == null) {
6840 // TODO(brianwilkerson) This should never happen. 6895 // TODO(brianwilkerson) This should never happen.
6841 return DynamicTypeImpl.instance; 6896 return DynamicTypeImpl.instance;
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
7083 _DISALLOWED_TYPES_TO_EXTEND_OR_IMPLEMENT = <InterfaceType> [ 7138 _DISALLOWED_TYPES_TO_EXTEND_OR_IMPLEMENT = <InterfaceType> [
7084 _typeProvider.nullType, 7139 _typeProvider.nullType,
7085 _typeProvider.numType, 7140 _typeProvider.numType,
7086 _intType, 7141 _intType,
7087 _typeProvider.doubleType, 7142 _typeProvider.doubleType,
7088 _boolType, 7143 _boolType,
7089 _typeProvider.stringType]; 7144 _typeProvider.stringType];
7090 } 7145 }
7091 7146
7092 @override 7147 @override
7148 Object visitAnnotation(Annotation node) {
7149 _checkForInvalidAnnotationFromDeferredLibrary(node);
7150 return super.visitAnnotation(node);
7151 }
7152
7153 @override
7093 Object visitArgumentList(ArgumentList node) { 7154 Object visitArgumentList(ArgumentList node) {
7094 _checkForArgumentTypesNotAssignableInList(node); 7155 _checkForArgumentTypesNotAssignableInList(node);
7095 return super.visitArgumentList(node); 7156 return super.visitArgumentList(node);
7096 } 7157 }
7097 7158
7098 @override 7159 @override
7099 Object visitAssertStatement(AssertStatement node) { 7160 Object visitAssertStatement(AssertStatement node) {
7100 _checkForNonBoolExpression(node); 7161 _checkForNonBoolExpression(node);
7101 return super.visitAssertStatement(node); 7162 return super.visitAssertStatement(node);
7102 } 7163 }
7103 7164
7104 @override 7165 @override
7105 Object visitAssignmentExpression(AssignmentExpression node) { 7166 Object visitAssignmentExpression(AssignmentExpression node) {
7106 sc.TokenType operatorType = node.operator.type; 7167 sc.TokenType operatorType = node.operator.type;
7168 Expression lhs = node.leftHandSide;
7169 Expression rhs = node.rightHandSide;
7107 if (operatorType == sc.TokenType.EQ) { 7170 if (operatorType == sc.TokenType.EQ) {
7108 _checkForInvalidAssignment(node.leftHandSide, node.rightHandSide); 7171 _checkForInvalidAssignment(lhs, rhs);
7109 } else { 7172 } else {
7110 _checkForInvalidCompoundAssignment(node); 7173 _checkForInvalidCompoundAssignment(node, lhs, rhs);
7111 } 7174 }
7112 _checkForAssignmentToFinal(node.leftHandSide); 7175 _checkForAssignmentToFinal(lhs);
7113 _checkForArgumentTypeNotAssignableForArgument(node.rightHandSide); 7176 _checkForArgumentTypeNotAssignableForArgument(rhs);
7114 return super.visitAssignmentExpression(node); 7177 return super.visitAssignmentExpression(node);
7115 } 7178 }
7116 7179
7117 @override 7180 @override
7118 Object visitBinaryExpression(BinaryExpression node) { 7181 Object visitBinaryExpression(BinaryExpression node) {
7119 _checkForArgumentTypeNotAssignableForArgument(node.rightOperand); 7182 _checkForArgumentTypeNotAssignableForArgument(node.rightOperand);
7120 return super.visitBinaryExpression(node); 7183 return super.visitBinaryExpression(node);
7121 } 7184 }
7122 7185
7123 @override 7186 @override
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
7185 _checkForNonAbstractClassInheritsAbstractMember(node.name); 7248 _checkForNonAbstractClassInheritsAbstractMember(node.name);
7186 _checkForInconsistentMethodInheritance(); 7249 _checkForInconsistentMethodInheritance();
7187 _checkForRecursiveInterfaceInheritance(_enclosingClass); 7250 _checkForRecursiveInterfaceInheritance(_enclosingClass);
7188 _checkForConflictingGetterAndMethod(); 7251 _checkForConflictingGetterAndMethod();
7189 _checkForConflictingInstanceGetterAndSuperclassMember(); 7252 _checkForConflictingInstanceGetterAndSuperclassMember();
7190 _checkImplementsSuperClass(node); 7253 _checkImplementsSuperClass(node);
7191 _checkImplementsFunctionWithoutCall(node); 7254 _checkImplementsFunctionWithoutCall(node);
7192 } 7255 }
7193 } 7256 }
7194 // initialize initialFieldElementsMap 7257 // initialize initialFieldElementsMap
7195 ClassElement classElement = node.element; 7258 if (_enclosingClass != null) {
7196 if (classElement != null) { 7259 List<FieldElement> fieldElements = _enclosingClass.fields;
7197 List<FieldElement> fieldElements = classElement.fields;
7198 _initialFieldElementsMap = new Map<FieldElement, INIT_STATE>(); 7260 _initialFieldElementsMap = new Map<FieldElement, INIT_STATE>();
7199 for (FieldElement fieldElement in fieldElements) { 7261 for (FieldElement fieldElement in fieldElements) {
7200 if (!fieldElement.isSynthetic) { 7262 if (!fieldElement.isSynthetic) {
7201 _initialFieldElementsMap[fieldElement] = fieldElement.initializer == null ? INIT_STATE.NOT_INIT : INIT_STATE.INIT_IN_DECLARATION; 7263 _initialFieldElementsMap[fieldElement] = fieldElement.initializer == null ? INIT_STATE.NOT_INIT : INIT_STATE.INIT_IN_DECLARATION;
7202 } 7264 }
7203 } 7265 }
7204 } 7266 }
7205 _checkForFinalNotInitializedInClass(node); 7267 _checkForFinalNotInitializedInClass(node);
7206 _checkForDuplicateDefinitionInheritance(); 7268 _checkForDuplicateDefinitionInheritance();
7207 _checkForConflictingInstanceMethodSetter(node); 7269 _checkForConflictingInstanceMethodSetter(node);
7208 return super.visitClassDeclaration(node); 7270 return super.visitClassDeclaration(node);
7209 } finally { 7271 } finally {
7210 _isInNativeClass = false; 7272 _isInNativeClass = false;
7211 _initialFieldElementsMap = null; 7273 _initialFieldElementsMap = null;
7212 _enclosingClass = outerClass; 7274 _enclosingClass = outerClass;
7213 } 7275 }
7214 } 7276 }
7215 7277
7216 @override 7278 @override
7217 Object visitClassTypeAlias(ClassTypeAlias node) { 7279 Object visitClassTypeAlias(ClassTypeAlias node) {
7218 _checkForBuiltInIdentifierAsName(node.name, CompileTimeErrorCode.BUILT_IN_ID ENTIFIER_AS_TYPEDEF_NAME); 7280 _checkForBuiltInIdentifierAsName(node.name, CompileTimeErrorCode.BUILT_IN_ID ENTIFIER_AS_TYPEDEF_NAME);
7219 ClassElement outerClassElement = _enclosingClass; 7281 ClassElement outerClassElement = _enclosingClass;
7220 try { 7282 try {
7221 _enclosingClass = node.element; 7283 _enclosingClass = node.element;
7284 ImplementsClause implementsClause = node.implementsClause;
7222 // Only check for all of the inheritance logic around clauses if there isn 't an error code 7285 // Only check for all of the inheritance logic around clauses if there isn 't an error code
7223 // such as "Cannot extend double" already on the class. 7286 // such as "Cannot extend double" already on the class.
7224 if (!_checkForExtendsDisallowedClassInTypeAlias(node) && !_checkForImpleme ntsDisallowedClass(node.implementsClause) && !_checkForAllMixinErrorCodes(node.w ithClause)) { 7287 if (!_checkForExtendsDisallowedClassInTypeAlias(node) && !_checkForImpleme ntsDisallowedClass(implementsClause) && !_checkForAllMixinErrorCodes(node.withCl ause)) {
7225 _checkForExtendsDeferredClassInTypeAlias(node); 7288 _checkForExtendsDeferredClassInTypeAlias(node);
7226 _checkForImplementsDeferredClass(node.implementsClause); 7289 _checkForImplementsDeferredClass(implementsClause);
7227 _checkForRecursiveInterfaceInheritance(node.element); 7290 _checkForRecursiveInterfaceInheritance(_enclosingClass);
7228 _checkForTypeAliasCannotReferenceItself_mixin(node); 7291 _checkForTypeAliasCannotReferenceItself_mixin(node);
7229 _checkForNonAbstractClassInheritsAbstractMember(node.name); 7292 _checkForNonAbstractClassInheritsAbstractMember(node.name);
7230 } 7293 }
7231 } finally { 7294 } finally {
7232 _enclosingClass = outerClassElement; 7295 _enclosingClass = outerClassElement;
7233 } 7296 }
7234 return super.visitClassTypeAlias(node); 7297 return super.visitClassTypeAlias(node);
7235 } 7298 }
7236 7299
7237 @override 7300 @override
(...skipping 15 matching lines...) Expand all
7253 @override 7316 @override
7254 Object visitConditionalExpression(ConditionalExpression node) { 7317 Object visitConditionalExpression(ConditionalExpression node) {
7255 _checkForNonBoolCondition(node.condition); 7318 _checkForNonBoolCondition(node.condition);
7256 return super.visitConditionalExpression(node); 7319 return super.visitConditionalExpression(node);
7257 } 7320 }
7258 7321
7259 @override 7322 @override
7260 Object visitConstructorDeclaration(ConstructorDeclaration node) { 7323 Object visitConstructorDeclaration(ConstructorDeclaration node) {
7261 ExecutableElement outerFunction = _enclosingFunction; 7324 ExecutableElement outerFunction = _enclosingFunction;
7262 try { 7325 try {
7263 _enclosingFunction = node.element; 7326 ConstructorElement constructorElement = node.element;
7327 _enclosingFunction = constructorElement;
7264 _isEnclosingConstructorConst = node.constKeyword != null; 7328 _isEnclosingConstructorConst = node.constKeyword != null;
7265 _checkForConstConstructorWithNonFinalField(node); 7329 _checkForConstConstructorWithNonFinalField(node, constructorElement);
7266 _checkForConstConstructorWithNonConstSuper(node); 7330 _checkForConstConstructorWithNonConstSuper(node);
7267 _checkForConflictingConstructorNameAndMember(node); 7331 _checkForConflictingConstructorNameAndMember(node, constructorElement);
7268 _checkForAllFinalInitializedErrorCodes(node); 7332 _checkForAllFinalInitializedErrorCodes(node);
7269 _checkForRedirectingConstructorErrorCodes(node); 7333 _checkForRedirectingConstructorErrorCodes(node);
7270 _checkForMultipleSuperInitializers(node); 7334 _checkForMultipleSuperInitializers(node);
7271 _checkForRecursiveConstructorRedirect(node); 7335 _checkForRecursiveConstructorRedirect(node, constructorElement);
7272 if (!_checkForRecursiveFactoryRedirect(node)) { 7336 if (!_checkForRecursiveFactoryRedirect(node, constructorElement)) {
7273 _checkForAllRedirectConstructorErrorCodes(node); 7337 _checkForAllRedirectConstructorErrorCodes(node);
7274 } 7338 }
7275 _checkForUndefinedConstructorInInitializerImplicit(node); 7339 _checkForUndefinedConstructorInInitializerImplicit(node);
7276 _checkForRedirectToNonConstConstructor(node); 7340 _checkForRedirectToNonConstConstructor(node, constructorElement);
7277 _checkForReturnInGenerativeConstructor(node); 7341 _checkForReturnInGenerativeConstructor(node);
7278 return super.visitConstructorDeclaration(node); 7342 return super.visitConstructorDeclaration(node);
7279 } finally { 7343 } finally {
7280 _isEnclosingConstructorConst = false; 7344 _isEnclosingConstructorConst = false;
7281 _enclosingFunction = outerFunction; 7345 _enclosingFunction = outerFunction;
7282 } 7346 }
7283 } 7347 }
7284 7348
7285 @override 7349 @override
7286 Object visitConstructorFieldInitializer(ConstructorFieldInitializer node) { 7350 Object visitConstructorFieldInitializer(ConstructorFieldInitializer node) {
7287 _isInConstructorInitializer = true; 7351 _isInConstructorInitializer = true;
7288 try { 7352 try {
7289 _checkForInvalidField(node); 7353 SimpleIdentifier fieldName = node.fieldName;
7290 _checkForFieldInitializerNotAssignable(node); 7354 Element staticElement = fieldName.staticElement;
7355 _checkForInvalidField(node, fieldName, staticElement);
7356 _checkForFieldInitializerNotAssignable(node, staticElement);
7291 return super.visitConstructorFieldInitializer(node); 7357 return super.visitConstructorFieldInitializer(node);
7292 } finally { 7358 } finally {
7293 _isInConstructorInitializer = false; 7359 _isInConstructorInitializer = false;
7294 } 7360 }
7295 } 7361 }
7296 7362
7297 @override 7363 @override
7298 Object visitContinueStatement(ContinueStatement node) { 7364 Object visitContinueStatement(ContinueStatement node) {
7299 SimpleIdentifier labelNode = node.label; 7365 SimpleIdentifier labelNode = node.label;
7300 if (labelNode != null) { 7366 if (labelNode != null) {
(...skipping 15 matching lines...) Expand all
7316 @override 7382 @override
7317 Object visitDoStatement(DoStatement node) { 7383 Object visitDoStatement(DoStatement node) {
7318 _checkForNonBoolCondition(node.condition); 7384 _checkForNonBoolCondition(node.condition);
7319 return super.visitDoStatement(node); 7385 return super.visitDoStatement(node);
7320 } 7386 }
7321 7387
7322 @override 7388 @override
7323 Object visitExportDirective(ExportDirective node) { 7389 Object visitExportDirective(ExportDirective node) {
7324 ExportElement exportElement = node.element; 7390 ExportElement exportElement = node.element;
7325 if (exportElement != null) { 7391 if (exportElement != null) {
7326 _checkForAmbiguousExport(node, exportElement); 7392 LibraryElement exportedLibrary = exportElement.exportedLibrary;
7327 _checkForExportDuplicateLibraryName(node, exportElement); 7393 _checkForAmbiguousExport(node, exportElement, exportedLibrary);
7394 _checkForExportDuplicateLibraryName(node, exportElement, exportedLibrary);
7328 _checkForExportInternalLibrary(node, exportElement); 7395 _checkForExportInternalLibrary(node, exportElement);
7329 } 7396 }
7330 return super.visitExportDirective(node); 7397 return super.visitExportDirective(node);
7331 } 7398 }
7332 7399
7333 @override 7400 @override
7334 Object visitExpressionFunctionBody(ExpressionFunctionBody node) { 7401 Object visitExpressionFunctionBody(ExpressionFunctionBody node) {
7335 FunctionType functionType = _enclosingFunction == null ? null : _enclosingFu nction.type; 7402 FunctionType functionType = _enclosingFunction == null ? null : _enclosingFu nction.type;
7336 DartType expectedReturnType = functionType == null ? DynamicTypeImpl.instanc e : functionType.returnType; 7403 DartType expectedReturnType = functionType == null ? DynamicTypeImpl.instanc e : functionType.returnType;
7337 _checkForReturnOfInvalidType(node.expression, expectedReturnType); 7404 _checkForReturnOfInvalidType(node.expression, expectedReturnType);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
7370 @override 7437 @override
7371 Object visitFunctionDeclaration(FunctionDeclaration node) { 7438 Object visitFunctionDeclaration(FunctionDeclaration node) {
7372 ExecutableElement outerFunction = _enclosingFunction; 7439 ExecutableElement outerFunction = _enclosingFunction;
7373 try { 7440 try {
7374 SimpleIdentifier identifier = node.name; 7441 SimpleIdentifier identifier = node.name;
7375 String methodName = ""; 7442 String methodName = "";
7376 if (identifier != null) { 7443 if (identifier != null) {
7377 methodName = identifier.name; 7444 methodName = identifier.name;
7378 } 7445 }
7379 _enclosingFunction = node.element; 7446 _enclosingFunction = node.element;
7447 TypeName returnType = node.returnType;
7380 if (node.isSetter || node.isGetter) { 7448 if (node.isSetter || node.isGetter) {
7381 _checkForMismatchedAccessorTypes(node, methodName); 7449 _checkForMismatchedAccessorTypes(node, methodName);
7382 if (node.isSetter) { 7450 if (node.isSetter) {
7383 FunctionExpression functionExpression = node.functionExpression; 7451 FunctionExpression functionExpression = node.functionExpression;
7384 if (functionExpression != null) { 7452 if (functionExpression != null) {
7385 _checkForWrongNumberOfParametersForSetter(node.name, functionExpress ion.parameters); 7453 _checkForWrongNumberOfParametersForSetter(identifier, functionExpres sion.parameters);
7386 } 7454 }
7387 TypeName returnType = node.returnType;
7388 _checkForNonVoidReturnTypeForSetter(returnType); 7455 _checkForNonVoidReturnTypeForSetter(returnType);
7389 } 7456 }
7390 } 7457 }
7391 _checkForTypeAnnotationDeferredClass(node.returnType); 7458 _checkForTypeAnnotationDeferredClass(returnType);
7392 return super.visitFunctionDeclaration(node); 7459 return super.visitFunctionDeclaration(node);
7393 } finally { 7460 } finally {
7394 _enclosingFunction = outerFunction; 7461 _enclosingFunction = outerFunction;
7395 } 7462 }
7396 } 7463 }
7397 7464
7398 @override 7465 @override
7399 Object visitFunctionExpression(FunctionExpression node) { 7466 Object visitFunctionExpression(FunctionExpression node) {
7400 // If this function expression is wrapped in a function declaration, don't c hange the 7467 // If this function expression is wrapped in a function declaration, don't c hange the
7401 // enclosingFunction field. 7468 // enclosingFunction field.
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
7447 _checkForNonBoolCondition(node.condition); 7514 _checkForNonBoolCondition(node.condition);
7448 return super.visitIfStatement(node); 7515 return super.visitIfStatement(node);
7449 } 7516 }
7450 7517
7451 @override 7518 @override
7452 Object visitImportDirective(ImportDirective node) { 7519 Object visitImportDirective(ImportDirective node) {
7453 ImportElement importElement = node.element; 7520 ImportElement importElement = node.element;
7454 if (importElement != null) { 7521 if (importElement != null) {
7455 _checkForImportDuplicateLibraryName(node, importElement); 7522 _checkForImportDuplicateLibraryName(node, importElement);
7456 _checkForImportInternalLibrary(node, importElement); 7523 _checkForImportInternalLibrary(node, importElement);
7457 if (importElement.isDeferred) {
7458 _checkForLoadLibraryFunction(node, importElement);
7459 }
7460 } 7524 }
7461 return super.visitImportDirective(node); 7525 return super.visitImportDirective(node);
7462 } 7526 }
7463 7527
7464 @override 7528 @override
7465 Object visitIndexExpression(IndexExpression node) { 7529 Object visitIndexExpression(IndexExpression node) {
7466 _checkForArgumentTypeNotAssignableForArgument(node.index); 7530 _checkForArgumentTypeNotAssignableForArgument(node.index);
7467 return super.visitIndexExpression(node); 7531 return super.visitIndexExpression(node);
7468 } 7532 }
7469 7533
7470 @override 7534 @override
7471 Object visitInstanceCreationExpression(InstanceCreationExpression node) { 7535 Object visitInstanceCreationExpression(InstanceCreationExpression node) {
7472 _isInConstInstanceCreation = node.isConst; 7536 _isInConstInstanceCreation = node.isConst;
7473 try { 7537 try {
7474 ConstructorName constructorName = node.constructorName; 7538 ConstructorName constructorName = node.constructorName;
7475 TypeName typeName = constructorName.type; 7539 TypeName typeName = constructorName.type;
7476 DartType type = typeName.type; 7540 DartType type = typeName.type;
7477 if (type is InterfaceType) { 7541 if (type is InterfaceType) {
7478 InterfaceType interfaceType = type; 7542 InterfaceType interfaceType = type;
7479 _checkForConstOrNewWithAbstractClass(node, typeName, interfaceType); 7543 _checkForConstOrNewWithAbstractClass(node, typeName, interfaceType);
7480 if (_isInConstInstanceCreation) { 7544 if (_isInConstInstanceCreation) {
7481 _checkForConstWithNonConst(node); 7545 _checkForConstWithNonConst(node);
7482 _checkForConstWithUndefinedConstructor(node); 7546 _checkForConstWithUndefinedConstructor(node, constructorName, typeName );
7483 _checkForConstWithTypeParametersInCreation(node); 7547 _checkForConstWithTypeParameters(typeName);
7484 _checkForConstDeferredClass(node, constructorName, typeName); 7548 _checkForConstDeferredClass(node, constructorName, typeName);
7485 } else { 7549 } else {
7486 _checkForNewWithUndefinedConstructor(node); 7550 _checkForNewWithUndefinedConstructor(node, constructorName, typeName);
7487 } 7551 }
7488 } 7552 }
7489 return super.visitInstanceCreationExpression(node); 7553 return super.visitInstanceCreationExpression(node);
7490 } finally { 7554 } finally {
7491 _isInConstInstanceCreation = false; 7555 _isInConstInstanceCreation = false;
7492 } 7556 }
7493 } 7557 }
7494 7558
7495 @override 7559 @override
7496 Object visitListLiteral(ListLiteral node) { 7560 Object visitListLiteral(ListLiteral node) {
7497 if (node.constKeyword != null) { 7561 TypeArgumentList typeArguments = node.typeArguments;
7498 TypeArgumentList typeArguments = node.typeArguments; 7562 if (typeArguments != null) {
7499 if (typeArguments != null) { 7563 if (node.constKeyword != null) {
7500 NodeList<TypeName> arguments = typeArguments.arguments; 7564 NodeList<TypeName> arguments = typeArguments.arguments;
7501 if (arguments.length != 0) { 7565 if (arguments.length != 0) {
7502 _checkForInvalidTypeArgumentInConstTypedLiteral(arguments, CompileTime ErrorCode.INVALID_TYPE_ARGUMENT_IN_CONST_LIST); 7566 _checkForInvalidTypeArgumentInConstTypedLiteral(arguments, CompileTime ErrorCode.INVALID_TYPE_ARGUMENT_IN_CONST_LIST);
7503 } 7567 }
7504 } 7568 }
7569 _checkForExpectedOneListTypeArgument(node, typeArguments);
7570 _checkForListElementTypeNotAssignable(node, typeArguments);
7505 } 7571 }
7506 _checkForExpectedOneListTypeArgument(node);
7507 _checkForListElementTypeNotAssignable(node);
7508 return super.visitListLiteral(node); 7572 return super.visitListLiteral(node);
7509 } 7573 }
7510 7574
7511 @override 7575 @override
7512 Object visitMapLiteral(MapLiteral node) { 7576 Object visitMapLiteral(MapLiteral node) {
7513 TypeArgumentList typeArguments = node.typeArguments; 7577 TypeArgumentList typeArguments = node.typeArguments;
7514 if (typeArguments != null) { 7578 if (typeArguments != null) {
7515 NodeList<TypeName> arguments = typeArguments.arguments; 7579 NodeList<TypeName> arguments = typeArguments.arguments;
7516 if (arguments.length != 0) { 7580 if (arguments.length != 0) {
7517 if (node.constKeyword != null) { 7581 if (node.constKeyword != null) {
7518 _checkForInvalidTypeArgumentInConstTypedLiteral(arguments, CompileTime ErrorCode.INVALID_TYPE_ARGUMENT_IN_CONST_MAP); 7582 _checkForInvalidTypeArgumentInConstTypedLiteral(arguments, CompileTime ErrorCode.INVALID_TYPE_ARGUMENT_IN_CONST_MAP);
7519 } 7583 }
7520 } 7584 }
7585 _checkExpectedTwoMapTypeArguments(typeArguments);
7586 _checkForMapTypeNotAssignable(node, typeArguments);
7521 } 7587 }
7522 _checkExpectedTwoMapTypeArguments(typeArguments);
7523 _checkForNonConstMapAsExpressionStatement(node); 7588 _checkForNonConstMapAsExpressionStatement(node);
7524 _checkForMapTypeNotAssignable(node);
7525 _checkForConstMapKeyExpressionTypeImplementsEquals(node); 7589 _checkForConstMapKeyExpressionTypeImplementsEquals(node);
7526 return super.visitMapLiteral(node); 7590 return super.visitMapLiteral(node);
7527 } 7591 }
7528 7592
7529 @override 7593 @override
7530 Object visitMethodDeclaration(MethodDeclaration node) { 7594 Object visitMethodDeclaration(MethodDeclaration node) {
7531 ExecutableElement previousFunction = _enclosingFunction; 7595 ExecutableElement previousFunction = _enclosingFunction;
7532 try { 7596 try {
7533 _isInStaticMethod = node.isStatic; 7597 _isInStaticMethod = node.isStatic;
7534 _enclosingFunction = node.element; 7598 _enclosingFunction = node.element;
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
7706 return super.visitThrowExpression(node); 7770 return super.visitThrowExpression(node);
7707 } 7771 }
7708 7772
7709 @override 7773 @override
7710 Object visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) { 7774 Object visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) {
7711 _checkForFinalNotInitialized(node.variables); 7775 _checkForFinalNotInitialized(node.variables);
7712 return super.visitTopLevelVariableDeclaration(node); 7776 return super.visitTopLevelVariableDeclaration(node);
7713 } 7777 }
7714 7778
7715 @override 7779 @override
7780 Object visitTypeArgumentList(TypeArgumentList node) {
7781 NodeList<TypeName> list = node.arguments;
7782 for (TypeName typeName in list) {
7783 _checkForTypeAnnotationDeferredClass(typeName);
7784 }
7785 return super.visitTypeArgumentList(node);
7786 }
7787
7788 @override
7716 Object visitTypeName(TypeName node) { 7789 Object visitTypeName(TypeName node) {
7717 _checkForTypeArgumentNotMatchingBounds(node); 7790 _checkForTypeArgumentNotMatchingBounds(node);
7718 _checkForTypeParameterReferencedByStatic(node); 7791 _checkForTypeParameterReferencedByStatic(node);
7719 return super.visitTypeName(node); 7792 return super.visitTypeName(node);
7720 } 7793 }
7721 7794
7722 @override 7795 @override
7723 Object visitTypeParameter(TypeParameter node) { 7796 Object visitTypeParameter(TypeParameter node) {
7724 _checkForBuiltInIdentifierAsName(node.name, CompileTimeErrorCode.BUILT_IN_ID ENTIFIER_AS_TYPE_PARAMETER_NAME); 7797 _checkForBuiltInIdentifierAsName(node.name, CompileTimeErrorCode.BUILT_IN_ID ENTIFIER_AS_TYPE_PARAMETER_NAME);
7725 _checkForTypeParameterSupertypeOfItsBound(node); 7798 _checkForTypeParameterSupertypeOfItsBound(node);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
7765 7838
7766 @override 7839 @override
7767 Object visitWhileStatement(WhileStatement node) { 7840 Object visitWhileStatement(WhileStatement node) {
7768 _checkForNonBoolCondition(node.condition); 7841 _checkForNonBoolCondition(node.condition);
7769 return super.visitWhileStatement(node); 7842 return super.visitWhileStatement(node);
7770 } 7843 }
7771 7844
7772 /** 7845 /**
7773 * This verifies if the passed map literal has type arguments then there is ex actly two. 7846 * This verifies if the passed map literal has type arguments then there is ex actly two.
7774 * 7847 *
7775 * @param node the map literal to evaluate 7848 * @param typeArguments the type arguments, always non-`null`
7776 * @return `true` if and only if an error code is generated on the passed node 7849 * @return `true` if and only if an error code is generated on the passed node
7777 * @see StaticTypeWarningCode#EXPECTED_TWO_MAP_TYPE_ARGUMENTS 7850 * @see StaticTypeWarningCode#EXPECTED_TWO_MAP_TYPE_ARGUMENTS
7778 */ 7851 */
7779 bool _checkExpectedTwoMapTypeArguments(TypeArgumentList typeArguments) { 7852 bool _checkExpectedTwoMapTypeArguments(TypeArgumentList typeArguments) {
7780 // has type arguments
7781 if (typeArguments == null) {
7782 return false;
7783 }
7784 // check number of type arguments 7853 // check number of type arguments
7785 int num = typeArguments.arguments.length; 7854 int num = typeArguments.arguments.length;
7786 if (num == 2) { 7855 if (num == 2) {
7787 return false; 7856 return false;
7788 } 7857 }
7789 // report problem 7858 // report problem
7790 _errorReporter.reportErrorForNode(StaticTypeWarningCode.EXPECTED_TWO_MAP_TYP E_ARGUMENTS, typeArguments, [num]); 7859 _errorReporter.reportErrorForNode(StaticTypeWarningCode.EXPECTED_TWO_MAP_TYP E_ARGUMENTS, typeArguments, [num]);
7791 return true; 7860 return true;
7792 } 7861 }
7793 7862
(...skipping 593 matching lines...) Expand 10 before | Expand all | Expand 10 after
8387 return _checkForReturnOfInvalidType(returnExpression, expectedReturnType); 8456 return _checkForReturnOfInvalidType(returnExpression, expectedReturnType);
8388 } 8457 }
8389 8458
8390 /** 8459 /**
8391 * This verifies that the export namespace of the passed export directive does not export any name 8460 * This verifies that the export namespace of the passed export directive does not export any name
8392 * already exported by other export directive. 8461 * already exported by other export directive.
8393 * 8462 *
8394 * @param node the export directive node to report problem on 8463 * @param node the export directive node to report problem on
8395 * @param exportElement the [ExportElement] retrieved from the node, if the el ement in the 8464 * @param exportElement the [ExportElement] retrieved from the node, if the el ement in the
8396 * node was `null`, then this method is not called 8465 * node was `null`, then this method is not called
8466 * @param exportedLibrary the library element containing the exported element
8397 * @return `true` if and only if an error code is generated on the passed node 8467 * @return `true` if and only if an error code is generated on the passed node
8398 * @see CompileTimeErrorCode#AMBIGUOUS_EXPORT 8468 * @see CompileTimeErrorCode#AMBIGUOUS_EXPORT
8399 */ 8469 */
8400 bool _checkForAmbiguousExport(ExportDirective node, ExportElement exportElemen t) { 8470 bool _checkForAmbiguousExport(ExportDirective node, ExportElement exportElemen t, LibraryElement exportedLibrary) {
8401 // prepare exported library
8402 LibraryElement exportedLibrary = exportElement.exportedLibrary;
8403 if (exportedLibrary == null) { 8471 if (exportedLibrary == null) {
8404 return false; 8472 return false;
8405 } 8473 }
8406 // check exported names 8474 // check exported names
8407 Namespace namespace = new NamespaceBuilder().createExportNamespaceForDirecti ve(exportElement); 8475 Namespace namespace = new NamespaceBuilder().createExportNamespaceForDirecti ve(exportElement);
8408 Map<String, Element> definedNames = namespace.definedNames; 8476 Map<String, Element> definedNames = namespace.definedNames;
8409 for (MapEntry<String, Element> definedEntry in getMapEntrySet(definedNames)) { 8477 for (MapEntry<String, Element> definedEntry in getMapEntrySet(definedNames)) {
8410 String name = definedEntry.getKey(); 8478 String name = definedEntry.getKey();
8411 Element element = definedEntry.getValue(); 8479 Element element = definedEntry.getValue();
8412 Element prevElement = _exportedElements[name]; 8480 Element prevElement = _exportedElements[name];
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
8681 return true; 8749 return true;
8682 } 8750 }
8683 return false; 8751 return false;
8684 } 8752 }
8685 8753
8686 /** 8754 /**
8687 * This verifies all possible conflicts of the constructor name with other con structors and 8755 * This verifies all possible conflicts of the constructor name with other con structors and
8688 * members of the same class. 8756 * members of the same class.
8689 * 8757 *
8690 * @param node the constructor declaration to evaluate 8758 * @param node the constructor declaration to evaluate
8759 * @param constructorElement the constructor element
8691 * @return `true` if and only if an error code is generated on the passed node 8760 * @return `true` if and only if an error code is generated on the passed node
8692 * @see CompileTimeErrorCode#DUPLICATE_CONSTRUCTOR_DEFAULT 8761 * @see CompileTimeErrorCode#DUPLICATE_CONSTRUCTOR_DEFAULT
8693 * @see CompileTimeErrorCode#DUPLICATE_CONSTRUCTOR_NAME 8762 * @see CompileTimeErrorCode#DUPLICATE_CONSTRUCTOR_NAME
8694 * @see CompileTimeErrorCode#CONFLICTING_CONSTRUCTOR_NAME_AND_FIELD 8763 * @see CompileTimeErrorCode#CONFLICTING_CONSTRUCTOR_NAME_AND_FIELD
8695 * @see CompileTimeErrorCode#CONFLICTING_CONSTRUCTOR_NAME_AND_METHOD 8764 * @see CompileTimeErrorCode#CONFLICTING_CONSTRUCTOR_NAME_AND_METHOD
8696 */ 8765 */
8697 bool _checkForConflictingConstructorNameAndMember(ConstructorDeclaration node) { 8766 bool _checkForConflictingConstructorNameAndMember(ConstructorDeclaration node, ConstructorElement constructorElement) {
8698 ConstructorElement constructorElement = node.element;
8699 SimpleIdentifier constructorName = node.name; 8767 SimpleIdentifier constructorName = node.name;
8700 String name = constructorElement.name; 8768 String name = constructorElement.name;
8701 ClassElement classElement = constructorElement.enclosingElement; 8769 ClassElement classElement = constructorElement.enclosingElement;
8702 // constructors 8770 // constructors
8703 List<ConstructorElement> constructors = classElement.constructors; 8771 List<ConstructorElement> constructors = classElement.constructors;
8704 for (ConstructorElement otherConstructor in constructors) { 8772 for (ConstructorElement otherConstructor in constructors) {
8705 if (identical(otherConstructor, constructorElement)) { 8773 if (identical(otherConstructor, constructorElement)) {
8706 continue; 8774 continue;
8707 } 8775 }
8708 if (name == otherConstructor.name) { 8776 if (name == otherConstructor.name) {
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after
9084 // default constructor is not 'const', report problem 9152 // default constructor is not 'const', report problem
9085 _errorReporter.reportErrorForNode(CompileTimeErrorCode.CONST_CONSTRUCTOR_WIT H_NON_CONST_SUPER, node.returnType, []); 9153 _errorReporter.reportErrorForNode(CompileTimeErrorCode.CONST_CONSTRUCTOR_WIT H_NON_CONST_SUPER, node.returnType, []);
9086 return true; 9154 return true;
9087 } 9155 }
9088 9156
9089 /** 9157 /**
9090 * This verifies that if the passed constructor declaration is 'const' then th ere are no non-final 9158 * This verifies that if the passed constructor declaration is 'const' then th ere are no non-final
9091 * instance variable. 9159 * instance variable.
9092 * 9160 *
9093 * @param node the constructor declaration to evaluate 9161 * @param node the constructor declaration to evaluate
9162 * @param constructorElement the constructor element
9094 * @return `true` if and only if an error code is generated on the passed node 9163 * @return `true` if and only if an error code is generated on the passed node
9095 * @see CompileTimeErrorCode#CONST_CONSTRUCTOR_WITH_NON_FINAL_FIELD 9164 * @see CompileTimeErrorCode#CONST_CONSTRUCTOR_WITH_NON_FINAL_FIELD
9096 */ 9165 */
9097 bool _checkForConstConstructorWithNonFinalField(ConstructorDeclaration node) { 9166 bool _checkForConstConstructorWithNonFinalField(ConstructorDeclaration node, C onstructorElement constructorElement) {
9098 if (!_isEnclosingConstructorConst) { 9167 if (!_isEnclosingConstructorConst) {
9099 return false; 9168 return false;
9100 } 9169 }
9101 // check if there is non-final field 9170 // check if there is non-final field
9102 ConstructorElement constructorElement = node.element;
9103 ClassElement classElement = constructorElement.enclosingElement; 9171 ClassElement classElement = constructorElement.enclosingElement;
9104 if (!classElement.hasNonFinalField) { 9172 if (!classElement.hasNonFinalField) {
9105 return false; 9173 return false;
9106 } 9174 }
9107 // report problem 9175 // report problem
9108 _errorReporter.reportErrorForNode(CompileTimeErrorCode.CONST_CONSTRUCTOR_WIT H_NON_FINAL_FIELD, node, []); 9176 _errorReporter.reportErrorForNode(CompileTimeErrorCode.CONST_CONSTRUCTOR_WIT H_NON_FINAL_FIELD, node, []);
9109 return true; 9177 return true;
9110 } 9178 }
9111 9179
9112 /** 9180 /**
9113 * This verifies that the passed 'const' instance creation expression is not c reating a deferred 9181 * This verifies that the passed 'const' instance creation expression is not c reating a deferred
9114 * type. 9182 * type.
9115 * 9183 *
9116 * @param node the instance creation expression to evaluate 9184 * @param node the instance creation expression to evaluate
9117 * @param constructorName the constructor name from the instance creation expr ession 9185 * @param constructorName the constructor name, always non-`null`
9118 * @param typeName the type name off of the constructor name 9186 * @param typeName the name of the type defining the constructor, always non-` null`
9119 * @return `true` if and only if an error code is generated on the passed node 9187 * @return `true` if and only if an error code is generated on the passed node
9120 * @see CompileTimeErrorCode#CONST_DEFERRED_CLASS 9188 * @see CompileTimeErrorCode#CONST_DEFERRED_CLASS
9121 */ 9189 */
9122 bool _checkForConstDeferredClass(InstanceCreationExpression node, ConstructorN ame constructorName, TypeName typeName) { 9190 bool _checkForConstDeferredClass(InstanceCreationExpression node, ConstructorN ame constructorName, TypeName typeName) {
9123 if (typeName.isDeferred) { 9191 if (typeName.isDeferred) {
9124 _errorReporter.reportErrorForNode(CompileTimeErrorCode.CONST_DEFERRED_CLAS S, constructorName, [typeName.name.name]); 9192 _errorReporter.reportErrorForNode(CompileTimeErrorCode.CONST_DEFERRED_CLAS S, constructorName, [typeName.name.name]);
9125 return true; 9193 return true;
9126 } 9194 }
9127 return false; 9195 return false;
9128 } 9196 }
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
9257 for (TypeName argument in typeArguments.arguments) { 9325 for (TypeName argument in typeArguments.arguments) {
9258 hasError = javaBooleanOr(hasError, _checkForConstWithTypeParameters(argu ment)); 9326 hasError = javaBooleanOr(hasError, _checkForConstWithTypeParameters(argu ment));
9259 } 9327 }
9260 return hasError; 9328 return hasError;
9261 } 9329 }
9262 // OK 9330 // OK
9263 return false; 9331 return false;
9264 } 9332 }
9265 9333
9266 /** 9334 /**
9267 * This verifies that the passed 'const' instance creation expression does not reference any type
9268 * parameters.
9269 *
9270 * This method assumes that the instance creation was tested to be 'const' bef ore being called.
9271 *
9272 * @param node the instance creation expression to evaluate
9273 * @return `true` if and only if an error code is generated on the passed node
9274 * @see CompileTimeErrorCode#CONST_WITH_TYPE_PARAMETERS
9275 */
9276 bool _checkForConstWithTypeParametersInCreation(InstanceCreationExpression nod e) {
9277 ConstructorName constructorName = node.constructorName;
9278 if (constructorName == null) {
9279 return false;
9280 }
9281 TypeName typeName = constructorName.type;
9282 return _checkForConstWithTypeParameters(typeName);
9283 }
9284
9285 /**
9286 * This verifies that if the passed 'const' instance creation expression is be ing invoked on the 9335 * This verifies that if the passed 'const' instance creation expression is be ing invoked on the
9287 * resolved constructor. 9336 * resolved constructor.
9288 * 9337 *
9289 * This method assumes that the instance creation was tested to be 'const' bef ore being called. 9338 * This method assumes that the instance creation was tested to be 'const' bef ore being called.
9290 * 9339 *
9291 * @param node the instance creation expression to evaluate 9340 * @param node the instance creation expression to evaluate
9341 * @param constructorName the constructor name, always non-`null`
9342 * @param typeName the name of the type defining the constructor, always non-` null`
9292 * @return `true` if and only if an error code is generated on the passed node 9343 * @return `true` if and only if an error code is generated on the passed node
9293 * @see CompileTimeErrorCode#CONST_WITH_UNDEFINED_CONSTRUCTOR 9344 * @see CompileTimeErrorCode#CONST_WITH_UNDEFINED_CONSTRUCTOR
9294 * @see CompileTimeErrorCode#CONST_WITH_UNDEFINED_CONSTRUCTOR_DEFAULT 9345 * @see CompileTimeErrorCode#CONST_WITH_UNDEFINED_CONSTRUCTOR_DEFAULT
9295 */ 9346 */
9296 bool _checkForConstWithUndefinedConstructor(InstanceCreationExpression node) { 9347 bool _checkForConstWithUndefinedConstructor(InstanceCreationExpression node, C onstructorName constructorName, TypeName typeName) {
9297 // OK if resolved 9348 // OK if resolved
9298 if (node.staticElement != null) { 9349 if (node.staticElement != null) {
9299 return false; 9350 return false;
9300 } 9351 }
9301 // prepare constructor name 9352 Identifier className = typeName.name;
9302 ConstructorName constructorName = node.constructorName;
9303 if (constructorName == null) {
9304 return false;
9305 }
9306 // prepare class name
9307 TypeName type = constructorName.type;
9308 if (type == null) {
9309 return false;
9310 }
9311 Identifier className = type.name;
9312 // report as named or default constructor absence 9353 // report as named or default constructor absence
9313 SimpleIdentifier name = constructorName.name; 9354 SimpleIdentifier name = constructorName.name;
9314 if (name != null) { 9355 if (name != null) {
9315 _errorReporter.reportErrorForNode(CompileTimeErrorCode.CONST_WITH_UNDEFINE D_CONSTRUCTOR, name, [className, name]); 9356 _errorReporter.reportErrorForNode(CompileTimeErrorCode.CONST_WITH_UNDEFINE D_CONSTRUCTOR, name, [className, name]);
9316 } else { 9357 } else {
9317 _errorReporter.reportErrorForNode(CompileTimeErrorCode.CONST_WITH_UNDEFINE D_CONSTRUCTOR_DEFAULT, constructorName, [className]); 9358 _errorReporter.reportErrorForNode(CompileTimeErrorCode.CONST_WITH_UNDEFINE D_CONSTRUCTOR_DEFAULT, constructorName, [className]);
9318 } 9359 }
9319 return true; 9360 return true;
9320 } 9361 }
9321 9362
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
9448 } 9489 }
9449 // try to find member 9490 // try to find member
9450 ExecutableElement inheritedMember = _inheritanceManager.lookupInheritance(_e nclosingClass, name); 9491 ExecutableElement inheritedMember = _inheritanceManager.lookupInheritance(_e nclosingClass, name);
9451 if (inheritedMember == null) { 9492 if (inheritedMember == null) {
9452 return false; 9493 return false;
9453 } 9494 }
9454 // OK, also static 9495 // OK, also static
9455 if (inheritedMember.isStatic) { 9496 if (inheritedMember.isStatic) {
9456 return false; 9497 return false;
9457 } 9498 }
9499 // determine the display name, use the extended display name if the enclosin g class of the
9500 // inherited member is in a different source
9501 String displayName;
9502 Element enclosingElement = inheritedMember.enclosingElement;
9503 if (enclosingElement.source == _enclosingClass.source) {
9504 displayName = enclosingElement.displayName;
9505 } else {
9506 displayName = enclosingElement.extendedDisplayName;
9507 }
9458 // report problem 9508 // report problem
9459 _errorReporter.reportErrorForOffset(CompileTimeErrorCode.DUPLICATE_DEFINITIO N_INHERITANCE, staticMember.nameOffset, name.length, [name, inheritedMember.encl osingElement.displayName]); 9509 _errorReporter.reportErrorForOffset(CompileTimeErrorCode.DUPLICATE_DEFINITIO N_INHERITANCE, staticMember.nameOffset, name.length, [name, displayName]);
9460 return true; 9510 return true;
9461 } 9511 }
9462 9512
9463 /** 9513 /**
9464 * This verifies if the passed list literal has type arguments then there is e xactly one. 9514 * This verifies if the passed list literal has type arguments then there is e xactly one.
9465 * 9515 *
9466 * @param node the list literal to evaluate 9516 * @param node the list literal to evaluate
9517 * @param typeArguments the type arguments, always non-`null`
9467 * @return `true` if and only if an error code is generated on the passed node 9518 * @return `true` if and only if an error code is generated on the passed node
9468 * @see StaticTypeWarningCode#EXPECTED_ONE_LIST_TYPE_ARGUMENTS 9519 * @see StaticTypeWarningCode#EXPECTED_ONE_LIST_TYPE_ARGUMENTS
9469 */ 9520 */
9470 bool _checkForExpectedOneListTypeArgument(ListLiteral node) { 9521 bool _checkForExpectedOneListTypeArgument(ListLiteral node, TypeArgumentList t ypeArguments) {
9471 // prepare type arguments
9472 TypeArgumentList typeArguments = node.typeArguments;
9473 if (typeArguments == null) {
9474 return false;
9475 }
9476 // check number of type arguments 9522 // check number of type arguments
9477 int num = typeArguments.arguments.length; 9523 int num = typeArguments.arguments.length;
9478 if (num == 1) { 9524 if (num == 1) {
9479 return false; 9525 return false;
9480 } 9526 }
9481 // report problem 9527 // report problem
9482 _errorReporter.reportErrorForNode(StaticTypeWarningCode.EXPECTED_ONE_LIST_TY PE_ARGUMENTS, typeArguments, [num]); 9528 _errorReporter.reportErrorForNode(StaticTypeWarningCode.EXPECTED_ONE_LIST_TY PE_ARGUMENTS, typeArguments, [num]);
9483 return true; 9529 return true;
9484 } 9530 }
9485 9531
9486 /** 9532 /**
9487 * This verifies the passed import has unique name among other exported librar ies. 9533 * This verifies the passed import has unique name among other exported librar ies.
9488 * 9534 *
9489 * @param node the export directive to evaluate 9535 * @param node the export directive to evaluate
9490 * @param exportElement the [ExportElement] retrieved from the node, if the el ement in the 9536 * @param exportElement the [ExportElement] retrieved from the node, if the el ement in the
9491 * node was `null`, then this method is not called 9537 * node was `null`, then this method is not called
9538 * @param exportedLibrary the library element containing the exported element
9492 * @return `true` if and only if an error code is generated on the passed node 9539 * @return `true` if and only if an error code is generated on the passed node
9493 * @see CompileTimeErrorCode#EXPORT_DUPLICATED_LIBRARY_NAME 9540 * @see CompileTimeErrorCode#EXPORT_DUPLICATED_LIBRARY_NAME
9494 */ 9541 */
9495 bool _checkForExportDuplicateLibraryName(ExportDirective node, ExportElement e xportElement) { 9542 bool _checkForExportDuplicateLibraryName(ExportDirective node, ExportElement e xportElement, LibraryElement exportedLibrary) {
9496 // prepare exported library 9543 if (exportedLibrary == null) {
9497 LibraryElement nodeLibrary = exportElement.exportedLibrary;
9498 if (nodeLibrary == null) {
9499 return false; 9544 return false;
9500 } 9545 }
9501 String name = nodeLibrary.name; 9546 String name = exportedLibrary.name;
9502 // check if there is other exported library with the same name 9547 // check if there is other exported library with the same name
9503 LibraryElement prevLibrary = _nameToExportElement[name]; 9548 LibraryElement prevLibrary = _nameToExportElement[name];
9504 if (prevLibrary != null) { 9549 if (prevLibrary != null) {
9505 if (prevLibrary != nodeLibrary) { 9550 if (prevLibrary != exportedLibrary) {
9506 _errorReporter.reportErrorForNode(StaticWarningCode.EXPORT_DUPLICATED_LI BRARY_NAME, node, [ 9551 _errorReporter.reportErrorForNode(StaticWarningCode.EXPORT_DUPLICATED_LI BRARY_NAME, node, [
9507 prevLibrary.definingCompilationUnit.displayName, 9552 prevLibrary.definingCompilationUnit.displayName,
9508 nodeLibrary.definingCompilationUnit.displayName, 9553 exportedLibrary.definingCompilationUnit.displayName,
9509 name]); 9554 name]);
9510 return true; 9555 return true;
9511 } 9556 }
9512 } else { 9557 } else {
9513 _nameToExportElement[name] = nodeLibrary; 9558 _nameToExportElement[name] = exportedLibrary;
9514 } 9559 }
9515 // OK 9560 // OK
9516 return false; 9561 return false;
9517 } 9562 }
9518 9563
9519 /** 9564 /**
9520 * Check that if the visiting library is not system, then any passed library s hould not be SDK 9565 * Check that if the visiting library is not system, then any passed library s hould not be SDK
9521 * internal library. 9566 * internal library.
9522 * 9567 *
9523 * @param node the export directive to evaluate 9568 * @param node the export directive to evaluate
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
9669 } 9714 }
9670 } 9715 }
9671 return false; 9716 return false;
9672 } 9717 }
9673 9718
9674 /** 9719 /**
9675 * This verifies that the passed constructor field initializer has compatible field and 9720 * This verifies that the passed constructor field initializer has compatible field and
9676 * initializer expression types. 9721 * initializer expression types.
9677 * 9722 *
9678 * @param node the constructor field initializer to test 9723 * @param node the constructor field initializer to test
9724 * @param staticElement the static element from the name in the
9725 * [ConstructorFieldInitializer]
9679 * @return `true` if and only if an error code is generated on the passed node 9726 * @return `true` if and only if an error code is generated on the passed node
9680 * @see CompileTimeErrorCode#CONST_FIELD_INITIALIZER_NOT_ASSIGNABLE 9727 * @see CompileTimeErrorCode#CONST_FIELD_INITIALIZER_NOT_ASSIGNABLE
9681 * @see StaticWarningCode#FIELD_INITIALIZER_NOT_ASSIGNABLE 9728 * @see StaticWarningCode#FIELD_INITIALIZER_NOT_ASSIGNABLE
9682 */ 9729 */
9683 bool _checkForFieldInitializerNotAssignable(ConstructorFieldInitializer node) { 9730 bool _checkForFieldInitializerNotAssignable(ConstructorFieldInitializer node, Element staticElement) {
9684 // prepare field element 9731 // prepare field element
9685 Element staticElement = node.fieldName.staticElement;
9686 if (staticElement is! FieldElement) { 9732 if (staticElement is! FieldElement) {
9687 return false; 9733 return false;
9688 } 9734 }
9689 FieldElement fieldElement = staticElement as FieldElement; 9735 FieldElement fieldElement = staticElement as FieldElement;
9690 // prepare field type 9736 // prepare field type
9691 DartType fieldType = fieldElement.type; 9737 DartType fieldType = fieldElement.type;
9692 // prepare expression type 9738 // prepare expression type
9693 Expression expression = node.expression; 9739 Expression expression = node.expression;
9694 if (expression == null) { 9740 if (expression == null) {
9695 return false; 9741 return false;
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after
10069 bool _checkForIntNotAssignable(Expression argument) { 10115 bool _checkForIntNotAssignable(Expression argument) {
10070 if (argument == null) { 10116 if (argument == null) {
10071 return false; 10117 return false;
10072 } 10118 }
10073 ParameterElement staticParameterElement = argument.staticParameterElement; 10119 ParameterElement staticParameterElement = argument.staticParameterElement;
10074 DartType staticParameterType = staticParameterElement == null ? null : stati cParameterElement.type; 10120 DartType staticParameterType = staticParameterElement == null ? null : stati cParameterElement.type;
10075 return _checkForArgumentTypeNotAssignable(argument, staticParameterType, _in tType, StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE); 10121 return _checkForArgumentTypeNotAssignable(argument, staticParameterType, _in tType, StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE);
10076 } 10122 }
10077 10123
10078 /** 10124 /**
10125 * This verifies that the passed [Annotation] isn't defined in a deferred libr ary.
10126 *
10127 * @param node the [Annotation]
10128 * @return `true` if and only if an error code is generated on the passed node
10129 * @see CompileTimeErrorCode.INVALID_ANNOTATION_FROM_DEFERRED_LIBRARY
10130 */
10131 bool _checkForInvalidAnnotationFromDeferredLibrary(Annotation node) {
10132 Identifier nameIdentifier = node.name;
10133 if (nameIdentifier is PrefixedIdentifier) {
10134 if (nameIdentifier.isDeferred) {
10135 _errorReporter.reportErrorForNode(CompileTimeErrorCode.INVALID_ANNOTATIO N_FROM_DEFERRED_LIBRARY, node.name, []);
10136 return true;
10137 }
10138 }
10139 return false;
10140 }
10141
10142 /**
10079 * This verifies that the passed left hand side and right hand side represent a valid assignment. 10143 * This verifies that the passed left hand side and right hand side represent a valid assignment.
10080 * 10144 *
10081 * @param lhs the left hand side expression 10145 * @param lhs the left hand side expression
10082 * @param rhs the right hand side expression 10146 * @param rhs the right hand side expression
10083 * @return `true` if and only if an error code is generated on the passed node 10147 * @return `true` if and only if an error code is generated on the passed node
10084 * @see StaticTypeWarningCode#INVALID_ASSIGNMENT 10148 * @see StaticTypeWarningCode#INVALID_ASSIGNMENT
10085 */ 10149 */
10086 bool _checkForInvalidAssignment(Expression lhs, Expression rhs) { 10150 bool _checkForInvalidAssignment(Expression lhs, Expression rhs) {
10087 if (lhs == null || rhs == null) { 10151 if (lhs == null || rhs == null) {
10088 return false; 10152 return false;
10089 } 10153 }
10090 VariableElement leftElement = getVariableElement(lhs); 10154 VariableElement leftVariableElement = getVariableElement(lhs);
10091 DartType leftType = (leftElement == null) ? getStaticType(lhs) : leftElement .type; 10155 DartType leftType = (leftVariableElement == null) ? getStaticType(lhs) : lef tVariableElement.type;
10092 DartType staticRightType = getStaticType(rhs); 10156 DartType staticRightType = getStaticType(rhs);
10093 if (!staticRightType.isAssignableTo(leftType)) { 10157 if (!staticRightType.isAssignableTo(leftType)) {
10094 String leftName = leftType.displayName; 10158 String leftName = leftType.displayName;
10095 String rightName = staticRightType.displayName; 10159 String rightName = staticRightType.displayName;
10096 if (leftName == rightName) { 10160 if (leftName == rightName) {
10097 leftName = getExtendedDisplayName(leftType); 10161 Element leftElement = leftType.element;
10098 rightName = getExtendedDisplayName(staticRightType); 10162 Element rightElement = staticRightType.element;
10163 if (leftElement != null && rightElement != null) {
10164 leftName = leftElement.extendedDisplayName;
10165 rightName = rightElement.extendedDisplayName;
10166 }
10099 } 10167 }
10100 _errorReporter.reportErrorForNode(StaticTypeWarningCode.INVALID_ASSIGNMENT , rhs, [rightName, leftName]); 10168 _errorReporter.reportErrorForNode(StaticTypeWarningCode.INVALID_ASSIGNMENT , rhs, [rightName, leftName]);
10101 return true; 10169 return true;
10102 } 10170 }
10103 return false; 10171 return false;
10104 } 10172 }
10105 10173
10106 /** 10174 /**
10107 * Given an assignment using a compound assignment operator, this verifies tha t the given 10175 * Given an assignment using a compound assignment operator, this verifies tha t the given
10108 * assignment is valid. 10176 * assignment is valid.
10109 * 10177 *
10110 * @param node the assignment expression being tested 10178 * @param node the assignment expression being tested
10179 * @param lhs the left hand side expression
10180 * @param rhs the right hand side expression
10111 * @return `true` if and only if an error code is generated on the passed node 10181 * @return `true` if and only if an error code is generated on the passed node
10112 * @see StaticTypeWarningCode#INVALID_ASSIGNMENT 10182 * @see StaticTypeWarningCode#INVALID_ASSIGNMENT
10113 */ 10183 */
10114 bool _checkForInvalidCompoundAssignment(AssignmentExpression node) { 10184 bool _checkForInvalidCompoundAssignment(AssignmentExpression node, Expression lhs, Expression rhs) {
10115 Expression lhs = node.leftHandSide;
10116 if (lhs == null) { 10185 if (lhs == null) {
10117 return false; 10186 return false;
10118 } 10187 }
10119 VariableElement leftElement = getVariableElement(lhs); 10188 VariableElement leftVariableElement = getVariableElement(lhs);
10120 DartType leftType = (leftElement == null) ? getStaticType(lhs) : leftElement .type; 10189 DartType leftType = (leftVariableElement == null) ? getStaticType(lhs) : lef tVariableElement.type;
10121 MethodElement invokedMethod = node.staticElement; 10190 MethodElement invokedMethod = node.staticElement;
10122 if (invokedMethod == null) { 10191 if (invokedMethod == null) {
10123 return false; 10192 return false;
10124 } 10193 }
10125 DartType rightType = invokedMethod.type.returnType; 10194 DartType rightType = invokedMethod.type.returnType;
10126 if (leftType == null || rightType == null) { 10195 if (leftType == null || rightType == null) {
10127 return false; 10196 return false;
10128 } 10197 }
10129 if (!rightType.isAssignableTo(leftType)) { 10198 if (!rightType.isAssignableTo(leftType)) {
10130 String leftName = leftType.displayName; 10199 String leftName = leftType.displayName;
10131 String rightName = rightType.displayName; 10200 String rightName = rightType.displayName;
10132 if (leftName == rightName) { 10201 if (leftName == rightName) {
10133 leftName = getExtendedDisplayName(leftType); 10202 Element leftElement = leftType.element;
10134 rightName = getExtendedDisplayName(rightType); 10203 Element rightElement = rightType.element;
10204 if (leftElement != null && rightElement != null) {
10205 leftName = leftElement.extendedDisplayName;
10206 rightName = rightElement.extendedDisplayName;
10207 }
10135 } 10208 }
10136 _errorReporter.reportErrorForNode(StaticTypeWarningCode.INVALID_ASSIGNMENT , node.rightHandSide, [rightName, leftName]); 10209 _errorReporter.reportErrorForNode(StaticTypeWarningCode.INVALID_ASSIGNMENT , rhs, [rightName, leftName]);
10137 return true; 10210 return true;
10138 } 10211 }
10139 return false; 10212 return false;
10140 } 10213 }
10141 10214
10142 /** 10215 /**
10143 * Check the given initializer to ensure that the field being initialized is a valid field. 10216 * Check the given initializer to ensure that the field being initialized is a valid field.
10144 * 10217 *
10145 * @param node the field initializer being checked 10218 * @param node the field initializer being checked
10219 * @param fieldName the field name from the [ConstructorFieldInitializer]
10220 * @param staticElement the static element from the name in the
10221 * [ConstructorFieldInitializer]
10146 */ 10222 */
10147 void _checkForInvalidField(ConstructorFieldInitializer node) { 10223 void _checkForInvalidField(ConstructorFieldInitializer node, SimpleIdentifier fieldName, Element staticElement) {
10148 SimpleIdentifier fieldName = node.fieldName;
10149 Element staticElement = fieldName.staticElement;
10150 if (staticElement is FieldElement) { 10224 if (staticElement is FieldElement) {
10151 FieldElement fieldElement = staticElement; 10225 FieldElement fieldElement = staticElement;
10152 if (fieldElement.isSynthetic) { 10226 if (fieldElement.isSynthetic) {
10153 _errorReporter.reportErrorForNode(CompileTimeErrorCode.INITIALIZER_FOR_N ON_EXISTANT_FIELD, node, [fieldName]); 10227 _errorReporter.reportErrorForNode(CompileTimeErrorCode.INITIALIZER_FOR_N ON_EXISTANT_FIELD, node, [fieldName]);
10154 } else if (fieldElement.isStatic) { 10228 } else if (fieldElement.isStatic) {
10155 _errorReporter.reportErrorForNode(CompileTimeErrorCode.INITIALIZER_FOR_S TATIC_FIELD, node, [fieldName]); 10229 _errorReporter.reportErrorForNode(CompileTimeErrorCode.INITIALIZER_FOR_S TATIC_FIELD, node, [fieldName]);
10156 } 10230 }
10157 } else { 10231 } else {
10158 _errorReporter.reportErrorForNode(CompileTimeErrorCode.INITIALIZER_FOR_NON _EXISTANT_FIELD, node, [fieldName]); 10232 _errorReporter.reportErrorForNode(CompileTimeErrorCode.INITIALIZER_FOR_NON _EXISTANT_FIELD, node, [fieldName]);
10159 return; 10233 return;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
10194 } 10268 }
10195 } 10269 }
10196 return foundError; 10270 return foundError;
10197 } 10271 }
10198 10272
10199 /** 10273 /**
10200 * This verifies that the elements given [ListLiteral] are subtypes of the spe cified element 10274 * This verifies that the elements given [ListLiteral] are subtypes of the spe cified element
10201 * type. 10275 * type.
10202 * 10276 *
10203 * @param node the list literal to evaluate 10277 * @param node the list literal to evaluate
10278 * @param typeArguments the type arguments, always non-`null`
10204 * @return `true` if and only if an error code is generated on the passed node 10279 * @return `true` if and only if an error code is generated on the passed node
10205 * @see CompileTimeErrorCode#LIST_ELEMENT_TYPE_NOT_ASSIGNABLE 10280 * @see CompileTimeErrorCode#LIST_ELEMENT_TYPE_NOT_ASSIGNABLE
10206 * @see StaticWarningCode#LIST_ELEMENT_TYPE_NOT_ASSIGNABLE 10281 * @see StaticWarningCode#LIST_ELEMENT_TYPE_NOT_ASSIGNABLE
10207 */ 10282 */
10208 bool _checkForListElementTypeNotAssignable(ListLiteral node) { 10283 bool _checkForListElementTypeNotAssignable(ListLiteral node, TypeArgumentList typeArguments) {
10209 // Prepare list element type. 10284 NodeList<TypeName> typeNames = typeArguments.arguments;
10210 TypeArgumentList typeArgumentList = node.typeArguments; 10285 if (typeNames.length < 1) {
10211 if (typeArgumentList == null) {
10212 return false; 10286 return false;
10213 } 10287 }
10214 NodeList<TypeName> typeArguments = typeArgumentList.arguments; 10288 DartType listElementType = typeNames[0].type;
10215 if (typeArguments.length < 1) {
10216 return false;
10217 }
10218 DartType listElementType = typeArguments[0].type;
10219 // Prepare problem to report. 10289 // Prepare problem to report.
10220 ErrorCode errorCode; 10290 ErrorCode errorCode;
10221 if (node.constKeyword != null) { 10291 if (node.constKeyword != null) {
10222 errorCode = CompileTimeErrorCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE; 10292 errorCode = CompileTimeErrorCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE;
10223 } else { 10293 } else {
10224 errorCode = StaticWarningCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE; 10294 errorCode = StaticWarningCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE;
10225 } 10295 }
10226 // Check every list element. 10296 // Check every list element.
10227 bool hasProblems = false; 10297 bool hasProblems = false;
10228 for (Expression element in node.elements) { 10298 for (Expression element in node.elements) {
10229 hasProblems = javaBooleanOr(hasProblems, _checkForArgumentTypeNotAssignabl eWithExpectedTypes(element, listElementType, errorCode)); 10299 hasProblems = javaBooleanOr(hasProblems, _checkForArgumentTypeNotAssignabl eWithExpectedTypes(element, listElementType, errorCode));
10230 } 10300 }
10231 return hasProblems; 10301 return hasProblems;
10232 } 10302 }
10233 10303
10234 /** 10304 /**
10235 * Check that the imported library does not define a loadLibrary function.
10236 *
10237 * @param node the import directive to evaluate
10238 * @param importElement the [ImportElement] retrieved from the node
10239 * @return `true` if and only if an error code is generated on the passed node
10240 * @see CompileTimeErrorCode#IMPORT_DEFERRED_LIBRARY_WITH_LOAD_FUNCTION
10241 */
10242 bool _checkForLoadLibraryFunction(ImportDirective node, ImportElement importEl ement) {
10243 LibraryElement importedLibrary = importElement.importedLibrary;
10244 if (importedLibrary == null) {
10245 return false;
10246 }
10247 if (importedLibrary.hasLoadLibraryFunction) {
10248 _errorReporter.reportErrorForNode(CompileTimeErrorCode.IMPORT_DEFERRED_LIB RARY_WITH_LOAD_FUNCTION, node, [importedLibrary.name]);
10249 return true;
10250 }
10251 return false;
10252 }
10253
10254 /**
10255 * This verifies that the key/value of entries of the given [MapLiteral] are s ubtypes of the 10305 * This verifies that the key/value of entries of the given [MapLiteral] are s ubtypes of the
10256 * key/value types specified in the type arguments. 10306 * key/value types specified in the type arguments.
10257 * 10307 *
10258 * @param node the map literal to evaluate 10308 * @param node the map literal to evaluate
10309 * @param typeArguments the type arguments, always non-`null`
10259 * @return `true` if and only if an error code is generated on the passed node 10310 * @return `true` if and only if an error code is generated on the passed node
10260 * @see CompileTimeErrorCode#MAP_KEY_TYPE_NOT_ASSIGNABLE 10311 * @see CompileTimeErrorCode#MAP_KEY_TYPE_NOT_ASSIGNABLE
10261 * @see CompileTimeErrorCode#MAP_VALUE_TYPE_NOT_ASSIGNABLE 10312 * @see CompileTimeErrorCode#MAP_VALUE_TYPE_NOT_ASSIGNABLE
10262 * @see StaticWarningCode#MAP_KEY_TYPE_NOT_ASSIGNABLE 10313 * @see StaticWarningCode#MAP_KEY_TYPE_NOT_ASSIGNABLE
10263 * @see StaticWarningCode#MAP_VALUE_TYPE_NOT_ASSIGNABLE 10314 * @see StaticWarningCode#MAP_VALUE_TYPE_NOT_ASSIGNABLE
10264 */ 10315 */
10265 bool _checkForMapTypeNotAssignable(MapLiteral node) { 10316 bool _checkForMapTypeNotAssignable(MapLiteral node, TypeArgumentList typeArgum ents) {
10266 // Prepare maps key/value types. 10317 // Prepare maps key/value types.
10267 TypeArgumentList typeArgumentList = node.typeArguments; 10318 NodeList<TypeName> typeNames = typeArguments.arguments;
10268 if (typeArgumentList == null) { 10319 if (typeNames.length < 2) {
10269 return false; 10320 return false;
10270 } 10321 }
10271 NodeList<TypeName> typeArguments = typeArgumentList.arguments; 10322 DartType keyType = typeNames[0].type;
10272 if (typeArguments.length < 2) { 10323 DartType valueType = typeNames[1].type;
10273 return false;
10274 }
10275 DartType keyType = typeArguments[0].type;
10276 DartType valueType = typeArguments[1].type;
10277 // Prepare problem to report. 10324 // Prepare problem to report.
10278 ErrorCode keyErrorCode; 10325 ErrorCode keyErrorCode;
10279 ErrorCode valueErrorCode; 10326 ErrorCode valueErrorCode;
10280 if (node.constKeyword != null) { 10327 if (node.constKeyword != null) {
10281 keyErrorCode = CompileTimeErrorCode.MAP_KEY_TYPE_NOT_ASSIGNABLE; 10328 keyErrorCode = CompileTimeErrorCode.MAP_KEY_TYPE_NOT_ASSIGNABLE;
10282 valueErrorCode = CompileTimeErrorCode.MAP_VALUE_TYPE_NOT_ASSIGNABLE; 10329 valueErrorCode = CompileTimeErrorCode.MAP_VALUE_TYPE_NOT_ASSIGNABLE;
10283 } else { 10330 } else {
10284 keyErrorCode = StaticWarningCode.MAP_KEY_TYPE_NOT_ASSIGNABLE; 10331 keyErrorCode = StaticWarningCode.MAP_KEY_TYPE_NOT_ASSIGNABLE;
10285 valueErrorCode = StaticWarningCode.MAP_VALUE_TYPE_NOT_ASSIGNABLE; 10332 valueErrorCode = StaticWarningCode.MAP_VALUE_TYPE_NOT_ASSIGNABLE;
10286 } 10333 }
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
10517 } 10564 }
10518 return false; 10565 return false;
10519 } 10566 }
10520 10567
10521 /** 10568 /**
10522 * This verifies that the passed 'new' instance creation expression invokes ex isting constructor. 10569 * This verifies that the passed 'new' instance creation expression invokes ex isting constructor.
10523 * 10570 *
10524 * This method assumes that the instance creation was tested to be 'new' befor e being called. 10571 * This method assumes that the instance creation was tested to be 'new' befor e being called.
10525 * 10572 *
10526 * @param node the instance creation expression to evaluate 10573 * @param node the instance creation expression to evaluate
10574 * @param constructorName the constructor name, always non-`null`
10575 * @param typeName the name of the type defining the constructor, always non-` null`
10527 * @return `true` if and only if an error code is generated on the passed node 10576 * @return `true` if and only if an error code is generated on the passed node
10528 * @see StaticWarningCode#NEW_WITH_UNDEFINED_CONSTRUCTOR 10577 * @see StaticWarningCode#NEW_WITH_UNDEFINED_CONSTRUCTOR
10529 */ 10578 */
10530 bool _checkForNewWithUndefinedConstructor(InstanceCreationExpression node) { 10579 bool _checkForNewWithUndefinedConstructor(InstanceCreationExpression node, Con structorName constructorName, TypeName typeName) {
10531 // OK if resolved 10580 // OK if resolved
10532 if (node.staticElement != null) { 10581 if (node.staticElement != null) {
10533 return false; 10582 return false;
10534 } 10583 }
10535 // prepare constructor name
10536 ConstructorName constructorName = node.constructorName;
10537 if (constructorName == null) {
10538 return false;
10539 }
10540 // prepare class name 10584 // prepare class name
10541 TypeName type = constructorName.type; 10585 Identifier className = typeName.name;
10542 if (type == null) {
10543 return false;
10544 }
10545 Identifier className = type.name;
10546 // report as named or default constructor absence 10586 // report as named or default constructor absence
10547 SimpleIdentifier name = constructorName.name; 10587 SimpleIdentifier name = constructorName.name;
10548 if (name != null) { 10588 if (name != null) {
10549 _errorReporter.reportErrorForNode(StaticWarningCode.NEW_WITH_UNDEFINED_CON STRUCTOR, name, [className, name]); 10589 _errorReporter.reportErrorForNode(StaticWarningCode.NEW_WITH_UNDEFINED_CON STRUCTOR, name, [className, name]);
10550 } else { 10590 } else {
10551 _errorReporter.reportErrorForNode(StaticWarningCode.NEW_WITH_UNDEFINED_CON STRUCTOR_DEFAULT, constructorName, [className]); 10591 _errorReporter.reportErrorForNode(StaticWarningCode.NEW_WITH_UNDEFINED_CON STRUCTOR_DEFAULT, constructorName, [className]);
10552 } 10592 }
10553 return true; 10593 return true;
10554 } 10594 }
10555 10595
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
10609 // 10649 //
10610 // Store in local sets the set of all method and accessor names 10650 // Store in local sets the set of all method and accessor names
10611 // 10651 //
10612 List<MethodElement> methods = _enclosingClass.methods; 10652 List<MethodElement> methods = _enclosingClass.methods;
10613 for (MethodElement method in methods) { 10653 for (MethodElement method in methods) {
10614 String methodName = method.name; 10654 String methodName = method.name;
10615 // If the enclosing class declares the method noSuchMethod(), then return. 10655 // If the enclosing class declares the method noSuchMethod(), then return.
10616 // From Spec: It is a static warning if a concrete class does not have an implementation for 10656 // From Spec: It is a static warning if a concrete class does not have an implementation for
10617 // a method in any of its superinterfaces unless it declares its own noSuc hMethod 10657 // a method in any of its superinterfaces unless it declares its own noSuc hMethod
10618 // method (7.10). 10658 // method (7.10).
10619 if (methodName == ElementResolver.NO_SUCH_METHOD_METHOD_NAME) { 10659 if (methodName == FunctionElement.NO_SUCH_METHOD_METHOD_NAME) {
10620 return false; 10660 return false;
10621 } 10661 }
10622 } 10662 }
10623 Set<ExecutableElement> missingOverrides = new Set<ExecutableElement>(); 10663 Set<ExecutableElement> missingOverrides = new Set<ExecutableElement>();
10624 // 10664 //
10625 // Loop through the set of all executable elements declared in the implicit interface. 10665 // Loop through the set of all executable elements declared in the implicit interface.
10626 // 10666 //
10627 MemberMap membersInheritedFromInterfaces = _inheritanceManager.getMapOfMembe rsInheritedFromInterfaces(_enclosingClass); 10667 MemberMap membersInheritedFromInterfaces = _inheritanceManager.getMapOfMembe rsInheritedFromInterfaces(_enclosingClass);
10628 MemberMap membersInheritedFromSuperclasses = _inheritanceManager.getMapOfMem bersInheritedFromClasses(_enclosingClass); 10668 MemberMap membersInheritedFromSuperclasses = _inheritanceManager.getMapOfMem bersInheritedFromClasses(_enclosingClass);
10629 for (int i = 0; i < membersInheritedFromInterfaces.size; i++) { 10669 for (int i = 0; i < membersInheritedFromInterfaces.size; i++) {
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
10910 // report problem 10950 // report problem
10911 _errorReporter.reportErrorForNode(CompileTimeErrorCode.PRIVATE_OPTIONAL_PARA METER, node, []); 10951 _errorReporter.reportErrorForNode(CompileTimeErrorCode.PRIVATE_OPTIONAL_PARA METER, node, []);
10912 return true; 10952 return true;
10913 } 10953 }
10914 10954
10915 /** 10955 /**
10916 * This checks if the passed constructor declaration is the redirecting genera tive constructor and 10956 * This checks if the passed constructor declaration is the redirecting genera tive constructor and
10917 * references itself directly or indirectly. 10957 * references itself directly or indirectly.
10918 * 10958 *
10919 * @param node the constructor declaration to evaluate 10959 * @param node the constructor declaration to evaluate
10960 * @param constructorElement the constructor element
10920 * @return `true` if and only if an error code is generated on the passed node 10961 * @return `true` if and only if an error code is generated on the passed node
10921 * @see CompileTimeErrorCode#RECURSIVE_CONSTRUCTOR_REDIRECT 10962 * @see CompileTimeErrorCode#RECURSIVE_CONSTRUCTOR_REDIRECT
10922 */ 10963 */
10923 bool _checkForRecursiveConstructorRedirect(ConstructorDeclaration node) { 10964 bool _checkForRecursiveConstructorRedirect(ConstructorDeclaration node, Constr uctorElement constructorElement) {
10924 // we check generative constructor here 10965 // we check generative constructor here
10925 if (node.factoryKeyword != null) { 10966 if (node.factoryKeyword != null) {
10926 return false; 10967 return false;
10927 } 10968 }
10928 // try to find redirecting constructor invocation and analyzer it for recurs ion 10969 // try to find redirecting constructor invocation and analyzer it for recurs ion
10929 for (ConstructorInitializer initializer in node.initializers) { 10970 for (ConstructorInitializer initializer in node.initializers) {
10930 if (initializer is RedirectingConstructorInvocation) { 10971 if (initializer is RedirectingConstructorInvocation) {
10931 // OK if no cycle 10972 // OK if no cycle
10932 ConstructorElement element = node.element; 10973 if (!_hasRedirectingFactoryConstructorCycle(constructorElement)) {
10933 if (!_hasRedirectingFactoryConstructorCycle(element)) {
10934 return false; 10974 return false;
10935 } 10975 }
10936 // report error 10976 // report error
10937 _errorReporter.reportErrorForNode(CompileTimeErrorCode.RECURSIVE_CONSTRU CTOR_REDIRECT, initializer, []); 10977 _errorReporter.reportErrorForNode(CompileTimeErrorCode.RECURSIVE_CONSTRU CTOR_REDIRECT, initializer, []);
10938 return true; 10978 return true;
10939 } 10979 }
10940 } 10980 }
10941 // OK, no redirecting constructor invocation 10981 // OK, no redirecting constructor invocation
10942 return false; 10982 return false;
10943 } 10983 }
10944 10984
10945 /** 10985 /**
10946 * This checks if the passed constructor declaration has redirected constructo r and references 10986 * This checks if the passed constructor declaration has redirected constructo r and references
10947 * itself directly or indirectly. 10987 * itself directly or indirectly.
10948 * 10988 *
10949 * @param node the constructor declaration to evaluate 10989 * @param node the constructor declaration to evaluate
10990 * @param constructorElement the constructor element
10950 * @return `true` if and only if an error code is generated on the passed node 10991 * @return `true` if and only if an error code is generated on the passed node
10951 * @see CompileTimeErrorCode#RECURSIVE_FACTORY_REDIRECT 10992 * @see CompileTimeErrorCode#RECURSIVE_FACTORY_REDIRECT
10952 */ 10993 */
10953 bool _checkForRecursiveFactoryRedirect(ConstructorDeclaration node) { 10994 bool _checkForRecursiveFactoryRedirect(ConstructorDeclaration node, Constructo rElement constructorElement) {
10954 // prepare redirected constructor 10995 // prepare redirected constructor
10955 ConstructorName redirectedConstructorNode = node.redirectedConstructor; 10996 ConstructorName redirectedConstructorNode = node.redirectedConstructor;
10956 if (redirectedConstructorNode == null) { 10997 if (redirectedConstructorNode == null) {
10957 return false; 10998 return false;
10958 } 10999 }
10959 // OK if no cycle 11000 // OK if no cycle
10960 ConstructorElement element = node.element; 11001 if (!_hasRedirectingFactoryConstructorCycle(constructorElement)) {
10961 if (!_hasRedirectingFactoryConstructorCycle(element)) {
10962 return false; 11002 return false;
10963 } 11003 }
10964 // report error 11004 // report error
10965 _errorReporter.reportErrorForNode(CompileTimeErrorCode.RECURSIVE_FACTORY_RED IRECT, redirectedConstructorNode, []); 11005 _errorReporter.reportErrorForNode(CompileTimeErrorCode.RECURSIVE_FACTORY_RED IRECT, redirectedConstructorNode, []);
10966 return true; 11006 return true;
10967 } 11007 }
10968 11008
10969 /** 11009 /**
10970 * This checks the class declaration is not a superinterface to itself. 11010 * This checks the class declaration is not a superinterface to itself.
10971 * 11011 *
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
11033 } 11073 }
11034 // done 11074 // done
11035 return errorReported; 11075 return errorReported;
11036 } 11076 }
11037 11077
11038 /** 11078 /**
11039 * This checks if the passed constructor declaration has redirected constructo r and references 11079 * This checks if the passed constructor declaration has redirected constructo r and references
11040 * itself directly or indirectly. 11080 * itself directly or indirectly.
11041 * 11081 *
11042 * @param node the constructor declaration to evaluate 11082 * @param node the constructor declaration to evaluate
11083 * @param constructorElement the constructor element
11043 * @return `true` if and only if an error code is generated on the passed node 11084 * @return `true` if and only if an error code is generated on the passed node
11044 * @see CompileTimeErrorCode#REDIRECT_TO_NON_CONST_CONSTRUCTOR 11085 * @see CompileTimeErrorCode#REDIRECT_TO_NON_CONST_CONSTRUCTOR
11045 */ 11086 */
11046 bool _checkForRedirectToNonConstConstructor(ConstructorDeclaration node) { 11087 bool _checkForRedirectToNonConstConstructor(ConstructorDeclaration node, Const ructorElement constructorElement) {
11047 // prepare redirected constructor 11088 // prepare redirected constructor
11048 ConstructorName redirectedConstructorNode = node.redirectedConstructor; 11089 ConstructorName redirectedConstructorNode = node.redirectedConstructor;
11049 if (redirectedConstructorNode == null) { 11090 if (redirectedConstructorNode == null) {
11050 return false; 11091 return false;
11051 } 11092 }
11052 // prepare element 11093 // prepare element
11053 ConstructorElement element = node.element; 11094 if (constructorElement == null) {
11054 if (element == null) {
11055 return false; 11095 return false;
11056 } 11096 }
11057 // OK, it is not 'const' 11097 // OK, it is not 'const'
11058 if (!element.isConst) { 11098 if (!constructorElement.isConst) {
11059 return false; 11099 return false;
11060 } 11100 }
11061 // prepare redirected constructor 11101 // prepare redirected constructor
11062 ConstructorElement redirectedConstructor = element.redirectedConstructor; 11102 ConstructorElement redirectedConstructor = constructorElement.redirectedCons tructor;
11063 if (redirectedConstructor == null) { 11103 if (redirectedConstructor == null) {
11064 return false; 11104 return false;
11065 } 11105 }
11066 // OK, it is also 'const' 11106 // OK, it is also 'const'
11067 if (redirectedConstructor.isConst) { 11107 if (redirectedConstructor.isConst) {
11068 return false; 11108 return false;
11069 } 11109 }
11070 // report error 11110 // report error
11071 _errorReporter.reportErrorForNode(CompileTimeErrorCode.REDIRECT_TO_NON_CONST _CONSTRUCTOR, redirectedConstructorNode, []); 11111 _errorReporter.reportErrorForNode(CompileTimeErrorCode.REDIRECT_TO_NON_CONST _CONSTRUCTOR, redirectedConstructorNode, []);
11072 return true; 11112 return true;
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
11285 // iterate over each bounded type parameter and corresponding argument 11325 // iterate over each bounded type parameter and corresponding argument
11286 NodeList<TypeName> typeNameArgList = node.typeArguments.arguments; 11326 NodeList<TypeName> typeNameArgList = node.typeArguments.arguments;
11287 List<DartType> typeArguments = (type as InterfaceType).typeArguments; 11327 List<DartType> typeArguments = (type as InterfaceType).typeArguments;
11288 int loopThroughIndex = Math.min(typeNameArgList.length, boundingElts.length) ; 11328 int loopThroughIndex = Math.min(typeNameArgList.length, boundingElts.length) ;
11289 bool foundError = false; 11329 bool foundError = false;
11290 for (int i = 0; i < loopThroughIndex; i++) { 11330 for (int i = 0; i < loopThroughIndex; i++) {
11291 TypeName argTypeName = typeNameArgList[i]; 11331 TypeName argTypeName = typeNameArgList[i];
11292 DartType argType = argTypeName.type; 11332 DartType argType = argTypeName.type;
11293 DartType boundType = boundingElts[i].bound; 11333 DartType boundType = boundingElts[i].bound;
11294 if (argType != null && boundType != null) { 11334 if (argType != null && boundType != null) {
11295 boundType = boundType.substitute2(typeArguments, typeParameters); 11335 if (typeArguments.length != 0 && typeArguments.length == typeParameters. length) {
11336 boundType = boundType.substitute2(typeArguments, typeParameters);
11337 }
11296 if (!argType.isSubtypeOf(boundType)) { 11338 if (!argType.isSubtypeOf(boundType)) {
11297 ErrorCode errorCode; 11339 ErrorCode errorCode;
11298 if (_isInConstInstanceCreation) { 11340 if (_isInConstInstanceCreation) {
11299 errorCode = CompileTimeErrorCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS; 11341 errorCode = CompileTimeErrorCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS;
11300 } else { 11342 } else {
11301 errorCode = StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS; 11343 errorCode = StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS;
11302 } 11344 }
11303 _errorReporter.reportErrorForNode(errorCode, argTypeName, [argType.dis playName, boundType.displayName]); 11345 _errorReporter.reportErrorForNode(errorCode, argTypeName, [argType.dis playName, boundType.displayName]);
11304 foundError = true; 11346 foundError = true;
11305 } 11347 }
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
11566 return false; 11608 return false;
11567 } 11609 }
11568 ClassElement classElement = node.element; 11610 ClassElement classElement = node.element;
11569 if (classElement == null) { 11611 if (classElement == null) {
11570 return false; 11612 return false;
11571 } 11613 }
11572 if (!classElement.type.isSubtypeOf(_typeProvider.functionType)) { 11614 if (!classElement.type.isSubtypeOf(_typeProvider.functionType)) {
11573 return false; 11615 return false;
11574 } 11616 }
11575 // If there is a noSuchMethod method, then don't report the warning, see dar tbug.com/16078 11617 // If there is a noSuchMethod method, then don't report the warning, see dar tbug.com/16078
11576 if (classElement.getMethod(ElementResolver.NO_SUCH_METHOD_METHOD_NAME) != nu ll) { 11618 if (classElement.getMethod(FunctionElement.NO_SUCH_METHOD_METHOD_NAME) != nu ll) {
11577 return false; 11619 return false;
11578 } 11620 }
11579 ExecutableElement callMethod = _inheritanceManager.lookupMember(classElement , "call"); 11621 ExecutableElement callMethod = _inheritanceManager.lookupMember(classElement , "call");
11580 if (callMethod == null || callMethod is! MethodElement || (callMethod as Met hodElement).isAbstract) { 11622 if (callMethod == null || callMethod is! MethodElement || (callMethod as Met hodElement).isAbstract) {
11581 _errorReporter.reportErrorForNode(StaticWarningCode.FUNCTION_WITHOUT_CALL, node.name, []); 11623 _errorReporter.reportErrorForNode(StaticWarningCode.FUNCTION_WITHOUT_CALL, node.name, []);
11582 return true; 11624 return true;
11583 } 11625 }
11584 return false; 11626 return false;
11585 } 11627 }
11586 11628
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
11747 // there is == that we don't like 11789 // there is == that we don't like
11748 return true; 11790 return true;
11749 } 11791 }
11750 11792
11751 bool _isFunctionType(DartType type) { 11793 bool _isFunctionType(DartType type) {
11752 if (type.isDynamic || type.isBottom) { 11794 if (type.isDynamic || type.isBottom) {
11753 return true; 11795 return true;
11754 } else if (type is FunctionType || type.isDartCoreFunction) { 11796 } else if (type is FunctionType || type.isDartCoreFunction) {
11755 return true; 11797 return true;
11756 } else if (type is InterfaceType) { 11798 } else if (type is InterfaceType) {
11757 MethodElement callMethod = type.lookUpMethod(ElementResolver.CALL_METHOD_N AME, _currentLibrary); 11799 MethodElement callMethod = type.lookUpMethod(FunctionElement.CALL_METHOD_N AME, _currentLibrary);
11758 return callMethod != null; 11800 return callMethod != null;
11759 } 11801 }
11760 return false; 11802 return false;
11761 } 11803 }
11762 11804
11763 /** 11805 /**
11764 * Return `true` iff the passed [ClassElement] has a method, getter or setter that 11806 * Return `true` iff the passed [ClassElement] has a method, getter or setter that
11765 * matches the name of the passed [ExecutableElement] in either the class itse lf, or one of 11807 * matches the name of the passed [ExecutableElement] in either the class itse lf, or one of
11766 * its' mixins that is concrete. 11808 * its' mixins that is concrete.
11767 * 11809 *
(...skipping 8087 matching lines...) Expand 10 before | Expand all | Expand 10 after
19855 * The Dart Language Specification, 12.5: <blockquote>The static type of a str ing literal is 19897 * The Dart Language Specification, 12.5: <blockquote>The static type of a str ing literal is
19856 * `String`.</blockquote> 19898 * `String`.</blockquote>
19857 */ 19899 */
19858 @override 19900 @override
19859 Object visitAdjacentStrings(AdjacentStrings node) { 19901 Object visitAdjacentStrings(AdjacentStrings node) {
19860 _recordStaticType(node, _typeProvider.stringType); 19902 _recordStaticType(node, _typeProvider.stringType);
19861 return null; 19903 return null;
19862 } 19904 }
19863 19905
19864 /** 19906 /**
19865 * The Dart Language Specification, 12.33: <blockquote>The static type of an a rgument definition
19866 * test is `bool`.</blockquote>
19867 */
19868 @override
19869 Object visitArgumentDefinitionTest(ArgumentDefinitionTest node) {
19870 _recordStaticType(node, _typeProvider.boolType);
19871 return null;
19872 }
19873
19874 /**
19875 * The Dart Language Specification, 12.32: <blockquote>... the cast expression <i>e as T</i> ... 19907 * The Dart Language Specification, 12.32: <blockquote>... the cast expression <i>e as T</i> ...
19876 * 19908 *
19877 * It is a static warning if <i>T</i> does not denote a type available in the current lexical 19909 * It is a static warning if <i>T</i> does not denote a type available in the current lexical
19878 * scope. 19910 * scope.
19879 * 19911 *
19880 * The static type of a cast expression <i>e as T</i> is <i>T</i>.</blockquote > 19912 * The static type of a cast expression <i>e as T</i> is <i>T</i>.</blockquote >
19881 */ 19913 */
19882 @override 19914 @override
19883 Object visitAsExpression(AsExpression node) { 19915 Object visitAsExpression(AsExpression node) {
19884 _recordStaticType(node, _getType(node.type)); 19916 _recordStaticType(node, _getType(node.type));
(...skipping 1070 matching lines...) Expand 10 before | Expand all | Expand 10 after
20955 // 20987 //
20956 // This is a function invocation expression disguised as something else. W e are invoking a 20988 // This is a function invocation expression disguised as something else. W e are invoking a
20957 // getter and then invoking the returned function. 20989 // getter and then invoking the returned function.
20958 // 20990 //
20959 FunctionType propertyType = element.type; 20991 FunctionType propertyType = element.type;
20960 if (propertyType != null) { 20992 if (propertyType != null) {
20961 DartType returnType = propertyType.returnType; 20993 DartType returnType = propertyType.returnType;
20962 if (returnType.isDartCoreFunction) { 20994 if (returnType.isDartCoreFunction) {
20963 return _dynamicType; 20995 return _dynamicType;
20964 } else if (returnType is InterfaceType) { 20996 } else if (returnType is InterfaceType) {
20965 MethodElement callMethod = returnType.lookUpMethod(ElementResolver.CAL L_METHOD_NAME, _resolver.definingLibrary); 20997 MethodElement callMethod = returnType.lookUpMethod(FunctionElement.CAL L_METHOD_NAME, _resolver.definingLibrary);
20966 if (callMethod != null) { 20998 if (callMethod != null) {
20967 return callMethod.type.returnType; 20999 return callMethod.type.returnType;
20968 } 21000 }
20969 } else if (returnType is FunctionType) { 21001 } else if (returnType is FunctionType) {
20970 DartType innerReturnType = returnType.returnType; 21002 DartType innerReturnType = returnType.returnType;
20971 if (innerReturnType != null) { 21003 if (innerReturnType != null) {
20972 return innerReturnType; 21004 return innerReturnType;
20973 } 21005 }
20974 } 21006 }
20975 if (returnType != null) { 21007 if (returnType != null) {
(...skipping 2445 matching lines...) Expand 10 before | Expand all | Expand 10 after
23421 parameterImpl.markPotentiallyMutatedInScope(); 23453 parameterImpl.markPotentiallyMutatedInScope();
23422 // If we are in some closure, check if it is not the same as where varia ble is declared. 23454 // If we are in some closure, check if it is not the same as where varia ble is declared.
23423 if (_enclosingFunction != null && (element.enclosingElement != _enclosin gFunction)) { 23455 if (_enclosingFunction != null && (element.enclosingElement != _enclosin gFunction)) {
23424 parameterImpl.markPotentiallyMutatedInClosure(); 23456 parameterImpl.markPotentiallyMutatedInClosure();
23425 } 23457 }
23426 } 23458 }
23427 } 23459 }
23428 return null; 23460 return null;
23429 } 23461 }
23430 } 23462 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/generated/parser.dart ('k') | pkg/analyzer/lib/src/generated/sdk_io.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698