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

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

Issue 886833005: Fix await parsing. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Added comment Created 5 years, 10 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/compiler/lib/src/scanner/parser.dart ('k') | tests/compiler/dart2js/metadata_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 part of dart2js; 5 part of dart2js;
6 6
7 class TypeCheckerTask extends CompilerTask { 7 class TypeCheckerTask extends CompilerTask {
8 TypeCheckerTask(Compiler compiler) : super(compiler); 8 TypeCheckerTask(Compiler compiler) : super(compiler);
9 String get name => "Type checker"; 9 String get name => "Type checker";
10 10
(...skipping 1583 matching lines...) Expand 10 before | Expand all | Expand 10 after
1594 } 1594 }
1595 return const StatementType(); 1595 return const StatementType();
1596 } 1596 }
1597 1597
1598 DartType visitThrow(Throw node) { 1598 DartType visitThrow(Throw node) {
1599 // TODO(johnniwinther): Handle reachability. 1599 // TODO(johnniwinther): Handle reachability.
1600 analyze(node.expression); 1600 analyze(node.expression);
1601 return const DynamicType(); 1601 return const DynamicType();
1602 } 1602 }
1603 1603
1604 /// Flatten [type] by recursively removing enclosing `Future` annotations.
1605 ///
1606 /// For instance:
1607 /// flatten(T) = T
1608 /// flatten(Future<T>) = T
1609 /// flatten(Future<Future<T>>) = T
1610 ///
1611 /// This method is used in the static typing of await and type checking of
1612 /// return.
1613 DartType flatten(DartType type) {
1614 if (type is InterfaceType) {
1615 InterfaceType futureType = type.asInstanceOf(compiler.futureClass);
1616 if (futureType != null) {
1617 return flatten(futureType.typeArguments.first);
1618 }
1619 }
1620 return type;
1621 }
1622
1604 DartType visitAwait(Await node) { 1623 DartType visitAwait(Await node) {
1605 DartType expressionType = analyze(node.expression); 1624 DartType expressionType = analyze(node.expression);
1606 DartType resultType = expressionType; 1625 return flatten(expressionType);
1607 if (expressionType is InterfaceType) {
1608 InterfaceType futureType =
1609 expressionType.asInstanceOf(compiler.futureClass);
1610 if (futureType != null) {
1611 resultType = futureType.typeArguments.first;
1612 }
1613 }
1614 return resultType;
1615 } 1626 }
1616 1627
1617 DartType visitYield(Yield node) { 1628 DartType visitYield(Yield node) {
1618 DartType resultType = analyze(node.expression); 1629 DartType resultType = analyze(node.expression);
1619 if (!node.hasStar) { 1630 if (!node.hasStar) {
1620 if (currentAsyncMarker.isAsync) { 1631 if (currentAsyncMarker.isAsync) {
1621 resultType = 1632 resultType =
1622 compiler.streamClass.thisType.createInstantiation( 1633 compiler.streamClass.thisType.createInstantiation(
1623 <DartType>[resultType]); 1634 <DartType>[resultType]);
1624 } else { 1635 } else {
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
1828 1839
1829 visitTypedef(Typedef node) { 1840 visitTypedef(Typedef node) {
1830 // Do not typecheck [Typedef] nodes. 1841 // Do not typecheck [Typedef] nodes.
1831 } 1842 }
1832 1843
1833 visitNode(Node node) { 1844 visitNode(Node node) {
1834 compiler.internalError(node, 1845 compiler.internalError(node,
1835 'Unexpected node ${node.getObjectDescription()} in the type checker.'); 1846 'Unexpected node ${node.getObjectDescription()} in the type checker.');
1836 } 1847 }
1837 } 1848 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/scanner/parser.dart ('k') | tests/compiler/dart2js/metadata_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698