| 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 // TODO(jmesserly): this was ported from package:dev_compiler, and needs to be | 5 // TODO(jmesserly): this was ported from package:dev_compiler, and needs to be |
| 6 // refactored to fit into analyzer. | 6 // refactored to fit into analyzer. |
| 7 library analyzer.src.task.strong.checker; | 7 library analyzer.src.task.strong.checker; |
| 8 | 8 |
| 9 import 'package:analyzer/analyzer.dart'; | 9 import 'package:analyzer/analyzer.dart'; |
| 10 import 'package:analyzer/dart/element/element.dart'; | 10 import 'package:analyzer/dart/element/element.dart'; |
| (...skipping 770 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 781 } | 781 } |
| 782 | 782 |
| 783 DartType _getStaticType(Expression expr) { | 783 DartType _getStaticType(Expression expr) { |
| 784 return expr.staticType ?? DynamicTypeImpl.instance; | 784 return expr.staticType ?? DynamicTypeImpl.instance; |
| 785 } | 785 } |
| 786 | 786 |
| 787 /// Given an expression, return its type assuming it is | 787 /// Given an expression, return its type assuming it is |
| 788 /// in the caller position of a call (that is, accounting | 788 /// in the caller position of a call (that is, accounting |
| 789 /// for the possibility of a call method). Returns null | 789 /// for the possibility of a call method). Returns null |
| 790 /// if expression is not statically callable. | 790 /// if expression is not statically callable. |
| 791 FunctionType _getTypeAsCaller(Expression applicand) { | 791 FunctionType _getTypeAsCaller(Expression node) { |
| 792 var t = applicand.staticType ?? DynamicTypeImpl.instance; | 792 DartType t = node.staticType; |
| 793 if (node is SimpleIdentifier) { |
| 794 Expression parent = node.parent; |
| 795 if (parent is MethodInvocation) { |
| 796 t = parent.staticInvokeType; |
| 797 } |
| 798 } |
| 793 if (t is InterfaceType) { | 799 if (t is InterfaceType) { |
| 794 return rules.getCallMethodType(t); | 800 return rules.getCallMethodType(t); |
| 795 } | 801 } |
| 796 if (t is FunctionType) return t; | 802 if (t is FunctionType) return t; |
| 797 return null; | 803 return null; |
| 798 } | 804 } |
| 799 | 805 |
| 800 /// Checks if we can perform downwards inference on [e] tp get type [t]. | 806 /// Checks if we can perform downwards inference on [e] tp get type [t]. |
| 801 /// If it is not possible, this will add a message to [errors]. | 807 /// If it is not possible, this will add a message to [errors]. |
| 802 bool _inferExpression(Expression e, DartType t, List<String> errors) { | 808 bool _inferExpression(Expression e, DartType t, List<String> errors) { |
| (...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1235 } while (!current.isObject && !visited.contains(current)); | 1241 } while (!current.isObject && !visited.contains(current)); |
| 1236 } | 1242 } |
| 1237 | 1243 |
| 1238 void _recordMessage(StaticInfo info) { | 1244 void _recordMessage(StaticInfo info) { |
| 1239 if (info == null) return; | 1245 if (info == null) return; |
| 1240 var error = info.toAnalysisError(); | 1246 var error = info.toAnalysisError(); |
| 1241 if (error.errorCode.errorSeverity == ErrorSeverity.ERROR) _failure = true; | 1247 if (error.errorCode.errorSeverity == ErrorSeverity.ERROR) _failure = true; |
| 1242 _reporter.onError(error); | 1248 _reporter.onError(error); |
| 1243 } | 1249 } |
| 1244 } | 1250 } |
| OLD | NEW |