| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 /// Defines static information collected by the type checker and used later by | 5 /// Defines static information collected by the type checker and used later by |
| 6 /// emitters to generate code. | 6 /// emitters to generate code. |
| 7 library dev_compiler.src.info; | 7 library dev_compiler.src.info; |
| 8 | 8 |
| 9 import 'package:analyzer/src/generated/ast.dart'; | 9 import 'package:analyzer/src/generated/ast.dart'; |
| 10 import 'package:analyzer/src/generated/element.dart'; | 10 import 'package:analyzer/src/generated/element.dart'; |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 final fromT = cast.fromType; | 215 final fromT = cast.fromType; |
| 216 final toT = cast.toType; | 216 final toT = cast.toType; |
| 217 | 217 |
| 218 // toT <:_R fromT => to <: fromT | 218 // toT <:_R fromT => to <: fromT |
| 219 // NB: classes with call methods are subtypes of function | 219 // NB: classes with call methods are subtypes of function |
| 220 // types, but the function type is not assignable to the class | 220 // types, but the function type is not assignable to the class |
| 221 assert(toT.isSubtypeOf(fromT) || fromT.isAssignableTo(toT)); | 221 assert(toT.isSubtypeOf(fromT) || fromT.isAssignableTo(toT)); |
| 222 | 222 |
| 223 // Handle null call specially. | 223 // Handle null call specially. |
| 224 if (expression is NullLiteral) { | 224 if (expression is NullLiteral) { |
| 225 if (rules.isNonNullableType(toT)) { | 225 // TODO(vsm): Create a NullCast for this once we revisit nonnullability. |
| 226 reason = "null is invalid as a $toT"; | 226 return new DownCastImplicit(rules, expression, cast); |
| 227 return new StaticTypeError(rules, expression, toT, reason: reason); | |
| 228 } else { | |
| 229 // We should only get here if some coercion is required. | |
| 230 assert(rules.maybeNonNullableType(toT)); | |
| 231 // TODO(vsm): Create a NullCast for this once we revisit nonnullability. | |
| 232 return new DownCastImplicit(rules, expression, cast); | |
| 233 } | |
| 234 } | 227 } |
| 235 | 228 |
| 236 // Inference "casts": | 229 // Inference "casts": |
| 237 if (expression is Literal) { | 230 if (expression is Literal) { |
| 238 // fromT should be an exact type - this will almost certainly fail at | 231 // fromT should be an exact type - this will almost certainly fail at |
| 239 // runtime. | 232 // runtime. |
| 240 return new StaticTypeError(rules, expression, toT, reason: reason); | 233 return new StaticTypeError(rules, expression, toT, reason: reason); |
| 241 } | 234 } |
| 242 if (expression is FunctionExpression) { | 235 if (expression is FunctionExpression) { |
| 243 // fromT should be an exact type - this will almost certainly fail at | 236 // fromT should be an exact type - this will almost certainly fail at |
| (...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 573 /// Better to have `super` at the end, as required by the Dart style guide: | 566 /// Better to have `super` at the end, as required by the Dart style guide: |
| 574 /// <http://goo.gl/q1T4BB> | 567 /// <http://goo.gl/q1T4BB> |
| 575 /// | 568 /// |
| 576 /// For now this is the only pattern we support. | 569 /// For now this is the only pattern we support. |
| 577 class InvalidSuperInvocation extends StaticError { | 570 class InvalidSuperInvocation extends StaticError { |
| 578 InvalidSuperInvocation(SuperConstructorInvocation node) : super(node); | 571 InvalidSuperInvocation(SuperConstructorInvocation node) : super(node); |
| 579 | 572 |
| 580 @override String get message => "super call must be last in an initializer " | 573 @override String get message => "super call must be last in an initializer " |
| 581 "list (see http://goo.gl/q1T4BB): {0}"; | 574 "list (see http://goo.gl/q1T4BB): {0}"; |
| 582 } | 575 } |
| OLD | NEW |