| 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 library dev_compiler.src.checker.rules; | 5 library dev_compiler.src.checker.rules; |
| 6 | 6 |
| 7 import 'package:analyzer/src/generated/ast.dart'; | 7 import 'package:analyzer/src/generated/ast.dart'; |
| 8 import 'package:analyzer/src/generated/element.dart'; | 8 import 'package:analyzer/src/generated/element.dart'; |
| 9 import 'package:analyzer/src/generated/resolver.dart'; | 9 import 'package:analyzer/src/generated/resolver.dart'; |
| 10 | 10 |
| (...skipping 515 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 526 final Coercion c = _coerceTo(fromT, toT, options.wrapClosures); | 526 final Coercion c = _coerceTo(fromT, toT, options.wrapClosures); |
| 527 if (c is Identity) return null; | 527 if (c is Identity) return null; |
| 528 if (c is CoercionError) return new StaticTypeError(this, expr, toT); | 528 if (c is CoercionError) return new StaticTypeError(this, expr, toT); |
| 529 var reason = null; | 529 var reason = null; |
| 530 if (options.inferDownwards) { | 530 if (options.inferDownwards) { |
| 531 var errors = <String>[]; | 531 var errors = <String>[]; |
| 532 var ok = inferrer.inferExpression(expr, toT, errors); | 532 var ok = inferrer.inferExpression(expr, toT, errors); |
| 533 if (ok) return InferredType.create(this, expr, toT); | 533 if (ok) return InferredType.create(this, expr, toT); |
| 534 reason = (errors.isNotEmpty) ? errors.first : null; | 534 reason = (errors.isNotEmpty) ? errors.first : null; |
| 535 } | 535 } |
| 536 if (constContext && !options.allowConstCasts) { | |
| 537 reason = (reason == null) ? "Cast not allowed in const context" : reason; | |
| 538 return new StaticTypeError(this, expr, toT, reason: reason); | |
| 539 } | |
| 540 if (c is Cast) return DownCast.create(this, expr, c, reason: reason); | 536 if (c is Cast) return DownCast.create(this, expr, c, reason: reason); |
| 541 if (c is Wrapper) return ClosureWrap.create(this, expr, c, toT); | 537 if (c is Wrapper) return ClosureWrap.create(this, expr, c, toT); |
| 542 assert(false); | 538 assert(false); |
| 543 return null; | 539 return null; |
| 544 } | 540 } |
| 545 | 541 |
| 546 DartType elementType(Element e) { | 542 DartType elementType(Element e) { |
| 547 return (e as dynamic).type; | 543 return (e as dynamic).type; |
| 548 } | 544 } |
| 549 | 545 |
| (...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 864 var entries = e.entries; | 860 var entries = e.entries; |
| 865 bool inferEntry(MapLiteralEntry entry) { | 861 bool inferEntry(MapLiteralEntry entry) { |
| 866 return _inferExpression(entry.key, kType, errors) && | 862 return _inferExpression(entry.key, kType, errors) && |
| 867 _inferExpression(entry.value, vType, errors); | 863 _inferExpression(entry.value, vType, errors); |
| 868 } | 864 } |
| 869 var b = entries.every(inferEntry); | 865 var b = entries.every(inferEntry); |
| 870 if (b) annotateMapLiteral(e, targs); | 866 if (b) annotateMapLiteral(e, targs); |
| 871 return b; | 867 return b; |
| 872 } | 868 } |
| 873 } | 869 } |
| OLD | NEW |