| 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 500 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 511 var source = (node.root as CompilationUnit).element.source; | 511 var source = (node.root as CompilationUnit).element.source; |
| 512 return new AnalysisError(source, begin, length, toErrorCode(), arguments); | 512 return new AnalysisError(source, begin, length, toErrorCode(), arguments); |
| 513 } | 513 } |
| 514 | 514 |
| 515 // TODO(jmesserly): review the usage of error codes. We probably want our own, | 515 // TODO(jmesserly): review the usage of error codes. We probably want our own, |
| 516 // as well as some DDC specific [ErrorType]s. | 516 // as well as some DDC specific [ErrorType]s. |
| 517 ErrorCode toErrorCode(); | 517 ErrorCode toErrorCode(); |
| 518 | 518 |
| 519 static bool isKnownFunction(Expression expression) { | 519 static bool isKnownFunction(Expression expression) { |
| 520 Element element = null; | 520 Element element = null; |
| 521 if (expression is PropertyAccess) { | 521 if (expression is FunctionExpression) { |
| 522 return true; |
| 523 } else if (expression is PropertyAccess) { |
| 522 element = expression.propertyName.staticElement; | 524 element = expression.propertyName.staticElement; |
| 523 } else if (expression is Identifier) { | 525 } else if (expression is Identifier) { |
| 524 element = expression.staticElement; | 526 element = expression.staticElement; |
| 525 } | 527 } |
| 526 // First class functions and static methods, where we know the original | 528 // First class functions and static methods, where we know the original |
| 527 // declaration, will have an exact type, so we know a downcast will fail. | 529 // declaration, will have an exact type, so we know a downcast will fail. |
| 528 return element is FunctionElement || | 530 return element is FunctionElement || |
| 529 element is MethodElement && element.isStatic; | 531 element is MethodElement && element.isStatic; |
| 530 } | 532 } |
| 531 } | 533 } |
| 532 | 534 |
| 533 class StaticTypeError extends StaticError { | 535 class StaticTypeError extends StaticError { |
| 534 final DartType baseType; | 536 final DartType baseType; |
| 535 final DartType expectedType; | 537 final DartType expectedType; |
| 536 | 538 |
| 537 StaticTypeError(TypeSystem rules, Expression expression, this.expectedType) | 539 StaticTypeError(TypeSystem rules, Expression expression, this.expectedType) |
| 538 : baseType = expression.staticType ?? DynamicTypeImpl.instance, | 540 : baseType = expression.staticType ?? DynamicTypeImpl.instance, |
| 539 super(expression); | 541 super(expression); |
| 540 | 542 |
| 541 @override | 543 @override |
| 542 List<Object> get arguments => [node, baseType, expectedType]; | 544 List<Object> get arguments => [node, baseType, expectedType]; |
| 543 @override | 545 @override |
| 544 String get message => 'Type check failed: {0} ({1}) is not of type {2}'; | 546 String get message => 'Type check failed: {0} ({1}) is not of type {2}'; |
| 545 | 547 |
| 546 @override | 548 @override |
| 547 String get name => 'STRONG_MODE_STATIC_TYPE_ERROR'; | 549 String get name => 'STRONG_MODE_STATIC_TYPE_ERROR'; |
| 548 } | 550 } |
| OLD | NEW |