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

Side by Side Diff: pkg/compiler/lib/src/typechecker.dart

Issue 1338803002: Type check await for. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | tests/compiler/dart2js/type_checker_test.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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library dart2js.typechecker; 5 library dart2js.typechecker;
6 6
7 import 'common/names.dart' show 7 import 'common/names.dart' show
8 Identifiers; 8 Identifiers;
9 import 'common/tasks.dart' show 9 import 'common/tasks.dart' show
10 CompilerTask; 10 CompilerTask;
(...skipping 1774 matching lines...) Expand 10 before | Expand all | Expand 10 after
1785 } 1785 }
1786 1786
1787 visitBreakStatement(BreakStatement node) { 1787 visitBreakStatement(BreakStatement node) {
1788 return const StatementType(); 1788 return const StatementType();
1789 } 1789 }
1790 1790
1791 visitContinueStatement(ContinueStatement node) { 1791 visitContinueStatement(ContinueStatement node) {
1792 return const StatementType(); 1792 return const StatementType();
1793 } 1793 }
1794 1794
1795 DartType computeForInElementType(ForIn node) {
1796 VariableDefinitions declaredIdentifier =
1797 node.declaredIdentifier.asVariableDefinitions();
1798 if (declaredIdentifier != null) {
1799 return
1800 analyzeWithDefault(declaredIdentifier.type, const DynamicType());
1801 } else {
1802 return analyze(node.declaredIdentifier);
1803 }
1804 }
1805
1795 visitAsyncForIn(AsyncForIn node) { 1806 visitAsyncForIn(AsyncForIn node) {
1796 analyze(node.expression); 1807 DartType elementType = computeForInElementType(node);
1808 DartType expressionType = analyze(node.expression);
1809 // TODO(johnniwinther): Move this to _CompilerCoreTypes.
1810 compiler.streamClass.ensureResolved(compiler);
1811 DartType streamOfDynamic = coreTypes.streamType();
1812 if (!types.isAssignable(expressionType, streamOfDynamic)) {
1813 reportMessage(node.expression,
1814 MessageKind.NOT_ASSIGNABLE,
1815 {'fromType': expressionType, 'toType': streamOfDynamic},
1816 isHint: true);
1817 } else {
1818 InterfaceType interfaceType =
1819 Types.computeInterfaceType(compiler, expressionType);
1820 if (interfaceType != null) {
1821 InterfaceType streamType =
1822 interfaceType.asInstanceOf(compiler.streamClass);
1823 if (streamType != null) {
1824 DartType streamElementType = streamType.typeArguments.first;
1825 if (!types.isAssignable(streamElementType, elementType)) {
1826 reportMessage(node.expression,
1827 MessageKind.FORIN_NOT_ASSIGNABLE,
1828 {'currentType': streamElementType,
1829 'expressionType': expressionType,
1830 'elementType': elementType},
1831 isHint: true);
1832 }
1833 }
1834 }
1835 }
1797 analyze(node.body); 1836 analyze(node.body);
1798 return const StatementType(); 1837 return const StatementType();
1799 } 1838 }
1800 1839
1801 visitSyncForIn(SyncForIn node) { 1840 visitSyncForIn(SyncForIn node) {
1802 DartType elementType; 1841 DartType elementType = computeForInElementType(node);
1803 VariableDefinitions declaredIdentifier =
1804 node.declaredIdentifier.asVariableDefinitions();
1805 if (declaredIdentifier != null) {
1806 elementType =
1807 analyzeWithDefault(declaredIdentifier.type, const DynamicType());
1808 } else {
1809 elementType = analyze(node.declaredIdentifier);
1810 }
1811 DartType expressionType = analyze(node.expression); 1842 DartType expressionType = analyze(node.expression);
1812 DartType iteratorType = lookupMemberType(node.expression, 1843 DartType iteratorType = lookupMemberType(node.expression,
1813 expressionType, Identifiers.iterator, MemberKind.GETTER); 1844 expressionType, Identifiers.iterator, MemberKind.GETTER);
1814 DartType currentType = lookupMemberType(node.expression, 1845 DartType currentType = lookupMemberType(node.expression,
1815 iteratorType, Identifiers.current, MemberKind.GETTER, 1846 iteratorType, Identifiers.current, MemberKind.GETTER,
1816 isHint: true); 1847 isHint: true);
1817 if (!types.isAssignable(currentType, elementType)) { 1848 if (!types.isAssignable(currentType, elementType)) {
1818 reportMessage(node.expression, 1849 reportMessage(node.expression,
1819 MessageKind.FORIN_NOT_ASSIGNABLE, 1850 MessageKind.FORIN_NOT_ASSIGNABLE,
1820 {'currentType': currentType, 1851 {'currentType': currentType,
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
1943 1974
1944 visitTypedef(Typedef node) { 1975 visitTypedef(Typedef node) {
1945 // Do not typecheck [Typedef] nodes. 1976 // Do not typecheck [Typedef] nodes.
1946 } 1977 }
1947 1978
1948 visitNode(Node node) { 1979 visitNode(Node node) {
1949 compiler.internalError(node, 1980 compiler.internalError(node,
1950 'Unexpected node ${node.getObjectDescription()} in the type checker.'); 1981 'Unexpected node ${node.getObjectDescription()} in the type checker.');
1951 } 1982 }
1952 } 1983 }
OLDNEW
« no previous file with comments | « no previous file | tests/compiler/dart2js/type_checker_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698