OLD | NEW |
---|---|
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 Identifiers; | 7 import 'common/names.dart' show Identifiers; |
8 import 'common/resolution.dart' show Resolution; | 8 import 'common/resolution.dart' show Resolution; |
9 import 'common/tasks.dart' show CompilerTask; | 9 import 'common/tasks.dart' show CompilerTask; |
10 import 'common.dart'; | 10 import 'common.dart'; |
(...skipping 1724 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1735 } | 1735 } |
1736 | 1736 |
1737 DartType visitThrow(Throw node) { | 1737 DartType visitThrow(Throw node) { |
1738 // TODO(johnniwinther): Handle reachability. | 1738 // TODO(johnniwinther): Handle reachability. |
1739 analyze(node.expression); | 1739 analyze(node.expression); |
1740 return const DynamicType(); | 1740 return const DynamicType(); |
1741 } | 1741 } |
1742 | 1742 |
1743 DartType visitAwait(Await node) { | 1743 DartType visitAwait(Await node) { |
1744 DartType expressionType = analyze(node.expression); | 1744 DartType expressionType = analyze(node.expression); |
1745 if (compiler.backend.supportsAsyncAwait) { | 1745 return types.flatten(expressionType); |
Johnni Winther
2016/07/08 08:05:39
Ditto.
Harry Terkelsen
2016/07/18 17:35:58
Done.
| |
1746 return types.flatten(expressionType); | |
1747 } else { | |
1748 return const DynamicType(); | |
1749 } | |
1750 } | 1746 } |
1751 | 1747 |
1752 DartType visitYield(Yield node) { | 1748 DartType visitYield(Yield node) { |
1753 DartType resultType = analyze(node.expression); | 1749 DartType resultType = analyze(node.expression); |
1754 if (!node.hasStar) { | 1750 if (!node.hasStar) { |
1755 if (currentAsyncMarker.isAsync) { | 1751 if (currentAsyncMarker.isAsync) { |
1756 resultType = coreTypes.streamType(resultType); | 1752 resultType = coreTypes.streamType(resultType); |
1757 } else { | 1753 } else { |
1758 resultType = coreTypes.iterableType(resultType); | 1754 resultType = coreTypes.iterableType(resultType); |
1759 } | 1755 } |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1862 if (declaredIdentifier != null) { | 1858 if (declaredIdentifier != null) { |
1863 return analyzeWithDefault(declaredIdentifier.type, const DynamicType()); | 1859 return analyzeWithDefault(declaredIdentifier.type, const DynamicType()); |
1864 } else { | 1860 } else { |
1865 return analyze(node.declaredIdentifier); | 1861 return analyze(node.declaredIdentifier); |
1866 } | 1862 } |
1867 } | 1863 } |
1868 | 1864 |
1869 visitAsyncForIn(AsyncForIn node) { | 1865 visitAsyncForIn(AsyncForIn node) { |
1870 DartType elementType = computeForInElementType(node); | 1866 DartType elementType = computeForInElementType(node); |
1871 DartType expressionType = analyze(node.expression); | 1867 DartType expressionType = analyze(node.expression); |
1872 if (compiler.backend.supportsAsyncAwait) { | 1868 DartType streamOfDynamic = coreTypes.streamType(); |
Johnni Winther
2016/07/08 08:05:39
Ditto.
Harry Terkelsen
2016/07/18 17:35:58
Done.
| |
1873 DartType streamOfDynamic = coreTypes.streamType(); | 1869 if (!types.isAssignable(expressionType, streamOfDynamic)) { |
1874 if (!types.isAssignable(expressionType, streamOfDynamic)) { | 1870 reportMessage(node.expression, MessageKind.NOT_ASSIGNABLE, |
1875 reportMessage(node.expression, MessageKind.NOT_ASSIGNABLE, | 1871 {'fromType': expressionType, 'toType': streamOfDynamic}, |
1876 {'fromType': expressionType, 'toType': streamOfDynamic}, | 1872 isHint: true); |
1877 isHint: true); | 1873 } else { |
1878 } else { | 1874 InterfaceType interfaceType = |
1879 InterfaceType interfaceType = | 1875 Types.computeInterfaceType(resolution, expressionType); |
1880 Types.computeInterfaceType(resolution, expressionType); | 1876 if (interfaceType != null) { |
1881 if (interfaceType != null) { | 1877 InterfaceType streamType = |
1882 InterfaceType streamType = | 1878 interfaceType.asInstanceOf(streamOfDynamic.element); |
1883 interfaceType.asInstanceOf(streamOfDynamic.element); | 1879 if (streamType != null) { |
1884 if (streamType != null) { | 1880 DartType streamElementType = streamType.typeArguments.first; |
1885 DartType streamElementType = streamType.typeArguments.first; | 1881 if (!types.isAssignable(streamElementType, elementType)) { |
1886 if (!types.isAssignable(streamElementType, elementType)) { | 1882 reportMessage( |
1887 reportMessage( | 1883 node.expression, |
1888 node.expression, | 1884 MessageKind.FORIN_NOT_ASSIGNABLE, |
1889 MessageKind.FORIN_NOT_ASSIGNABLE, | 1885 { |
1890 { | 1886 'currentType': streamElementType, |
1891 'currentType': streamElementType, | 1887 'expressionType': expressionType, |
1892 'expressionType': expressionType, | 1888 'elementType': elementType |
1893 'elementType': elementType | 1889 }, |
1894 }, | 1890 isHint: true); |
1895 isHint: true); | |
1896 } | |
1897 } | 1891 } |
1898 } | 1892 } |
1899 } | 1893 } |
1900 } | 1894 } |
1901 analyze(node.body); | 1895 analyze(node.body); |
1902 return const StatementType(); | 1896 return const StatementType(); |
1903 } | 1897 } |
1904 | 1898 |
1905 visitSyncForIn(SyncForIn node) { | 1899 visitSyncForIn(SyncForIn node) { |
1906 DartType elementType = computeForInElementType(node); | 1900 DartType elementType = computeForInElementType(node); |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2045 | 2039 |
2046 visitTypedef(Typedef node) { | 2040 visitTypedef(Typedef node) { |
2047 // Do not typecheck [Typedef] nodes. | 2041 // Do not typecheck [Typedef] nodes. |
2048 } | 2042 } |
2049 | 2043 |
2050 visitNode(Node node) { | 2044 visitNode(Node node) { |
2051 reporter.internalError(node, | 2045 reporter.internalError(node, |
2052 'Unexpected node ${node.getObjectDescription()} in the type checker.'); | 2046 'Unexpected node ${node.getObjectDescription()} in the type checker.'); |
2053 } | 2047 } |
2054 } | 2048 } |
OLD | NEW |