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

Side by Side Diff: lib/ast.dart

Issue 2465263002: Always store the type of a conditional expression on the node. (Closed)
Patch Set: Update test expectation Created 4 years, 1 month 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 | « lib/analyzer/ast_from_analyzer.dart ('k') | lib/frontend/accessors.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) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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 /// ----------------------------------------------------------------------- 5 /// -----------------------------------------------------------------------
6 /// ERROR HANDLING 6 /// ERROR HANDLING
7 /// ----------------------------------------------------------------------- 7 /// -----------------------------------------------------------------------
8 /// 8 ///
9 /// As a rule of thumb, errors that can be detected statically are handled by 9 /// As a rule of thumb, errors that can be detected statically are handled by
10 /// the frontend, typically by translating the erroneous code into a 'throw' or 10 /// the frontend, typically by translating the erroneous code into a 'throw' or
(...skipping 1960 matching lines...) Expand 10 before | Expand all | Expand 10 after
1971 } 1971 }
1972 } 1972 }
1973 } 1973 }
1974 1974
1975 /// Expression of form `x ? y : z`. 1975 /// Expression of form `x ? y : z`.
1976 class ConditionalExpression extends Expression { 1976 class ConditionalExpression extends Expression {
1977 Expression condition; 1977 Expression condition;
1978 Expression then; 1978 Expression then;
1979 Expression otherwise; 1979 Expression otherwise;
1980 1980
1981 /// The static type of the expression, or `null` if the type should be derived 1981 /// The static type of the expression. Should not be `null`.
1982 /// from [then] and [otherwise] using a very simple upper bound computation.
1983 ///
1984 /// If one of the arms is a null literal, the static type of the other
1985 /// arm will be used.
1986 DartType staticType; 1982 DartType staticType;
1987 1983
1988 ConditionalExpression(this.condition, this.then, this.otherwise, 1984 ConditionalExpression(this.condition, this.then, this.otherwise,
1989 [this.staticType]) { 1985 this.staticType) {
1990 condition?.parent = this; 1986 condition?.parent = this;
1991 then?.parent = this; 1987 then?.parent = this;
1992 otherwise?.parent = this; 1988 otherwise?.parent = this;
1993 } 1989 }
1994 1990
1995 DartType getStaticType(TypeEnvironment types) { 1991 DartType getStaticType(TypeEnvironment types) => staticType;
1996 if (staticType != null) return staticType;
1997 var left = then.getStaticType(types);
1998 var right = otherwise.getStaticType(types);
1999 if (left is BottomType) return right;
2000 if (right is BottomType) return left;
2001 return const DynamicType();
2002 }
2003 1992
2004 accept(ExpressionVisitor v) => v.visitConditionalExpression(this); 1993 accept(ExpressionVisitor v) => v.visitConditionalExpression(this);
2005 1994
2006 visitChildren(Visitor v) { 1995 visitChildren(Visitor v) {
2007 condition?.accept(v); 1996 condition?.accept(v);
2008 then?.accept(v); 1997 then?.accept(v);
2009 otherwise?.accept(v); 1998 otherwise?.accept(v);
2010 staticType?.accept(v); 1999 staticType?.accept(v);
2011 } 2000 }
2012 2001
(...skipping 1599 matching lines...) Expand 10 before | Expand all | Expand 10 after
3612 3601
3613 @override 3602 @override
3614 defaultTreeNode(TreeNode node) { 3603 defaultTreeNode(TreeNode node) {
3615 if (node == child) { 3604 if (node == child) {
3616 return replacement; 3605 return replacement;
3617 } else { 3606 } else {
3618 return node; 3607 return node;
3619 } 3608 }
3620 } 3609 }
3621 } 3610 }
OLDNEW
« no previous file with comments | « lib/analyzer/ast_from_analyzer.dart ('k') | lib/frontend/accessors.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698