| 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 1697 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1708 } | 1708 } |
| 1709 | 1709 |
| 1710 DartType visitThrow(Throw node) { | 1710 DartType visitThrow(Throw node) { |
| 1711 // TODO(johnniwinther): Handle reachability. | 1711 // TODO(johnniwinther): Handle reachability. |
| 1712 analyze(node.expression); | 1712 analyze(node.expression); |
| 1713 return const DynamicType(); | 1713 return const DynamicType(); |
| 1714 } | 1714 } |
| 1715 | 1715 |
| 1716 DartType visitAwait(Await node) { | 1716 DartType visitAwait(Await node) { |
| 1717 DartType expressionType = analyze(node.expression); | 1717 DartType expressionType = analyze(node.expression); |
| 1718 return types.flatten(expressionType); | 1718 if (compiler.backend.supportsAsyncAwait) { |
| 1719 return types.flatten(expressionType); |
| 1720 } else { |
| 1721 return const DynamicType(); |
| 1722 } |
| 1719 } | 1723 } |
| 1720 | 1724 |
| 1721 DartType visitYield(Yield node) { | 1725 DartType visitYield(Yield node) { |
| 1722 DartType resultType = analyze(node.expression); | 1726 DartType resultType = analyze(node.expression); |
| 1723 if (!node.hasStar) { | 1727 if (!node.hasStar) { |
| 1724 if (currentAsyncMarker.isAsync) { | 1728 if (currentAsyncMarker.isAsync) { |
| 1725 resultType = coreTypes.streamType(resultType); | 1729 resultType = coreTypes.streamType(resultType); |
| 1726 } else { | 1730 } else { |
| 1727 resultType = coreTypes.iterableType(resultType); | 1731 resultType = coreTypes.iterableType(resultType); |
| 1728 } | 1732 } |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1831 if (declaredIdentifier != null) { | 1835 if (declaredIdentifier != null) { |
| 1832 return analyzeWithDefault(declaredIdentifier.type, const DynamicType()); | 1836 return analyzeWithDefault(declaredIdentifier.type, const DynamicType()); |
| 1833 } else { | 1837 } else { |
| 1834 return analyze(node.declaredIdentifier); | 1838 return analyze(node.declaredIdentifier); |
| 1835 } | 1839 } |
| 1836 } | 1840 } |
| 1837 | 1841 |
| 1838 visitAsyncForIn(AsyncForIn node) { | 1842 visitAsyncForIn(AsyncForIn node) { |
| 1839 DartType elementType = computeForInElementType(node); | 1843 DartType elementType = computeForInElementType(node); |
| 1840 DartType expressionType = analyze(node.expression); | 1844 DartType expressionType = analyze(node.expression); |
| 1841 DartType streamOfDynamic = coreTypes.streamType(); | 1845 if (compiler.backend.supportsAsyncAwait) { |
| 1842 if (!types.isAssignable(expressionType, streamOfDynamic)) { | 1846 DartType streamOfDynamic = coreTypes.streamType(); |
| 1843 reportMessage(node.expression, MessageKind.NOT_ASSIGNABLE, | 1847 if (!types.isAssignable(expressionType, streamOfDynamic)) { |
| 1844 {'fromType': expressionType, 'toType': streamOfDynamic}, | 1848 reportMessage(node.expression, MessageKind.NOT_ASSIGNABLE, |
| 1845 isHint: true); | 1849 {'fromType': expressionType, 'toType': streamOfDynamic}, |
| 1846 } else { | 1850 isHint: true); |
| 1847 InterfaceType interfaceType = | 1851 } else { |
| 1848 Types.computeInterfaceType(resolution, expressionType); | 1852 InterfaceType interfaceType = |
| 1849 if (interfaceType != null) { | 1853 Types.computeInterfaceType(resolution, expressionType); |
| 1850 InterfaceType streamType = | 1854 if (interfaceType != null) { |
| 1851 interfaceType.asInstanceOf(streamOfDynamic.element); | 1855 InterfaceType streamType = |
| 1852 if (streamType != null) { | 1856 interfaceType.asInstanceOf(streamOfDynamic.element); |
| 1853 DartType streamElementType = streamType.typeArguments.first; | 1857 if (streamType != null) { |
| 1854 if (!types.isAssignable(streamElementType, elementType)) { | 1858 DartType streamElementType = streamType.typeArguments.first; |
| 1855 reportMessage( | 1859 if (!types.isAssignable(streamElementType, elementType)) { |
| 1856 node.expression, | 1860 reportMessage( |
| 1857 MessageKind.FORIN_NOT_ASSIGNABLE, | 1861 node.expression, |
| 1858 { | 1862 MessageKind.FORIN_NOT_ASSIGNABLE, |
| 1859 'currentType': streamElementType, | 1863 { |
| 1860 'expressionType': expressionType, | 1864 'currentType': streamElementType, |
| 1861 'elementType': elementType | 1865 'expressionType': expressionType, |
| 1862 }, | 1866 'elementType': elementType |
| 1863 isHint: true); | 1867 }, |
| 1868 isHint: true); |
| 1869 } |
| 1864 } | 1870 } |
| 1865 } | 1871 } |
| 1866 } | 1872 } |
| 1867 } | 1873 } |
| 1868 analyze(node.body); | 1874 analyze(node.body); |
| 1869 return const StatementType(); | 1875 return const StatementType(); |
| 1870 } | 1876 } |
| 1871 | 1877 |
| 1872 visitSyncForIn(SyncForIn node) { | 1878 visitSyncForIn(SyncForIn node) { |
| 1873 DartType elementType = computeForInElementType(node); | 1879 DartType elementType = computeForInElementType(node); |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2010 | 2016 |
| 2011 visitTypedef(Typedef node) { | 2017 visitTypedef(Typedef node) { |
| 2012 // Do not typecheck [Typedef] nodes. | 2018 // Do not typecheck [Typedef] nodes. |
| 2013 } | 2019 } |
| 2014 | 2020 |
| 2015 visitNode(Node node) { | 2021 visitNode(Node node) { |
| 2016 reporter.internalError(node, | 2022 reporter.internalError(node, |
| 2017 'Unexpected node ${node.getObjectDescription()} in the type checker.'); | 2023 'Unexpected node ${node.getObjectDescription()} in the type checker.'); |
| 2018 } | 2024 } |
| 2019 } | 2025 } |
| OLD | NEW |