| 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 // TODO(jmesserly): this was ported from package:dev_compiler, and needs to be | 7 // TODO(jmesserly): this was ported from package:dev_compiler, and needs to be |
| 8 // refactored to fit into analyzer. | 8 // refactored to fit into analyzer. |
| 9 library analyzer.src.task.strong.info; | 9 library analyzer.src.task.strong.info; |
| 10 | 10 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 String get message => 'Unsound implicit cast from {0} to {1}'; | 85 String get message => 'Unsound implicit cast from {0} to {1}'; |
| 86 | 86 |
| 87 /// Factory to create correct DownCast variant. | 87 /// Factory to create correct DownCast variant. |
| 88 static StaticInfo create(StrongTypeSystemImpl rules, Expression expression, | 88 static StaticInfo create(StrongTypeSystemImpl rules, Expression expression, |
| 89 DartType fromType, DartType toType) { | 89 DartType fromType, DartType toType) { |
| 90 // toT <:_R fromT => to <: fromT | 90 // toT <:_R fromT => to <: fromT |
| 91 // NB: classes with call methods are subtypes of function | 91 // NB: classes with call methods are subtypes of function |
| 92 // types, but the function type is not assignable to the class | 92 // types, but the function type is not assignable to the class |
| 93 assert(toType.isSubtypeOf(fromType) || fromType.isAssignableTo(toType)); | 93 assert(toType.isSubtypeOf(fromType) || fromType.isAssignableTo(toType)); |
| 94 | 94 |
| 95 // Handle null call specially. | |
| 96 if (expression is NullLiteral) { | |
| 97 // TODO(vsm): Create a NullCast for this once we revisit nonnullability. | |
| 98 return new DownCastImplicit(rules, expression, fromType, toType); | |
| 99 } | |
| 100 | |
| 101 // Inference "casts": | 95 // Inference "casts": |
| 102 if (expression is Literal || expression is FunctionExpression) { | 96 if (expression is Literal || expression is FunctionExpression) { |
| 103 // fromT should be an exact type - this will almost certainly fail at | 97 // fromT should be an exact type - this will almost certainly fail at |
| 104 // runtime. | 98 // runtime. |
| 105 return new StaticTypeError(rules, expression, toType); | 99 return new StaticTypeError(rules, expression, toType); |
| 106 } | 100 } |
| 107 | 101 |
| 108 if (expression is InstanceCreationExpression) { | 102 if (expression is InstanceCreationExpression) { |
| 109 ConstructorElement e = expression.staticElement; | 103 ConstructorElement e = expression.staticElement; |
| 110 if (e == null || !e.isFactory) { | 104 if (e == null || !e.isFactory) { |
| (...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 538 super(expression); | 532 super(expression); |
| 539 | 533 |
| 540 @override | 534 @override |
| 541 List<Object> get arguments => [node, baseType, expectedType]; | 535 List<Object> get arguments => [node, baseType, expectedType]; |
| 542 @override | 536 @override |
| 543 String get message => 'Type check failed: {0} ({1}) is not of type {2}'; | 537 String get message => 'Type check failed: {0} ({1}) is not of type {2}'; |
| 544 | 538 |
| 545 @override | 539 @override |
| 546 String get name => 'STRONG_MODE_STATIC_TYPE_ERROR'; | 540 String get name => 'STRONG_MODE_STATIC_TYPE_ERROR'; |
| 547 } | 541 } |
| OLD | NEW |