| 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 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 463 return (e as dynamic).type; | 463 return (e as dynamic).type; |
| 464 } | 464 } |
| 465 | 465 |
| 466 /// Returns `true` if the target expression is dynamic. | 466 /// Returns `true` if the target expression is dynamic. |
| 467 // TODO(jmesserly): remove this in favor of utils? Or a static method here? | 467 // TODO(jmesserly): remove this in favor of utils? Or a static method here? |
| 468 bool isDynamicTarget(Expression target) => utils.isDynamicTarget(target); | 468 bool isDynamicTarget(Expression target) => utils.isDynamicTarget(target); |
| 469 | 469 |
| 470 /// Returns `true` if the expression is a dynamic function call or method | 470 /// Returns `true` if the expression is a dynamic function call or method |
| 471 /// invocation. | 471 /// invocation. |
| 472 bool isDynamicCall(Expression call) { | 472 bool isDynamicCall(Expression call) { |
| 473 var t = getTypeAsCaller(call); | 473 var ft = getTypeAsCaller(call); |
| 474 // TODO(leafp): This will currently return true if t is Function | 474 // TODO(leafp): This will currently return true if t is Function |
| 475 // This is probably the most correct thing to do for now, since | 475 // This is probably the most correct thing to do for now, since |
| 476 // this code is also used by the back end. Maybe revisit at some | 476 // this code is also used by the back end. Maybe revisit at some |
| 477 // point? | 477 // point? |
| 478 if (t == null) return true; | 478 if (ft == null) return true; |
| 479 // Dynamic as the parameter type is treated as bottom. A function with | 479 // Dynamic as the parameter type is treated as bottom. A function with |
| 480 // a dynamic parameter type requires a dynamic call in general. | 480 // a dynamic parameter type requires a dynamic call in general. |
| 481 // However, as an optimization, if we have an original definition, we know | 481 // However, as an optimization, if we have an original definition, we know |
| 482 // dynamic is reified as Object - in this case a regular call is fine. | 482 // dynamic is reified as Object - in this case a regular call is fine. |
| 483 if (call is SimpleIdentifier) { | 483 if (call is SimpleIdentifier) { |
| 484 var element = call.staticElement; | 484 var element = call.staticElement; |
| 485 if (element is FunctionElement || element is MethodElement) { | 485 if (element is FunctionElement || element is MethodElement) { |
| 486 // An original declaration. | 486 // An original declaration. |
| 487 return false; | 487 return false; |
| 488 } | 488 } |
| 489 } | 489 } |
| 490 | 490 |
| 491 var ft = t as FunctionType; | |
| 492 return _anyParameterType(ft, (pt) => pt.isDynamic); | 491 return _anyParameterType(ft, (pt) => pt.isDynamic); |
| 493 } | 492 } |
| 494 } | 493 } |
| 495 | 494 |
| 496 class DownwardsInference { | 495 class DownwardsInference { |
| 497 final TypeRules rules; | 496 final TypeRules rules; |
| 498 | 497 |
| 499 DownwardsInference(this.rules); | 498 DownwardsInference(this.rules); |
| 500 | 499 |
| 501 /// Called for each list literal which gets inferred | 500 /// Called for each list literal which gets inferred |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 776 var entries = e.entries; | 775 var entries = e.entries; |
| 777 bool inferEntry(MapLiteralEntry entry) { | 776 bool inferEntry(MapLiteralEntry entry) { |
| 778 return _inferExpression(entry.key, kType, errors) && | 777 return _inferExpression(entry.key, kType, errors) && |
| 779 _inferExpression(entry.value, vType, errors); | 778 _inferExpression(entry.value, vType, errors); |
| 780 } | 779 } |
| 781 var b = entries.every(inferEntry); | 780 var b = entries.every(inferEntry); |
| 782 if (b) annotateMapLiteral(e, targs); | 781 if (b) annotateMapLiteral(e, targs); |
| 783 return b; | 782 return b; |
| 784 } | 783 } |
| 785 } | 784 } |
| OLD | NEW |