| 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 /// Encapsulates how to invoke the analyzer resolver and overrides how it | 5 /// Encapsulates how to invoke the analyzer resolver and overrides how it |
| 6 /// computes types on expressions to use our restricted set of types. | 6 /// computes types on expressions to use our restricted set of types. |
| 7 library dev_compiler.src.checker.resolver; | 7 library dev_compiler.src.checker.resolver; |
| 8 | 8 |
| 9 import 'package:analyzer/analyzer.dart'; | 9 import 'package:analyzer/analyzer.dart'; |
| 10 import 'package:analyzer/src/generated/ast.dart'; | 10 import 'package:analyzer/src/generated/ast.dart'; |
| (...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 553 var element = node.element as LocalVariableElementImpl; | 553 var element = node.element as LocalVariableElementImpl; |
| 554 var exprType = expr.staticType; | 554 var exprType = expr.staticType; |
| 555 if (exprType is InterfaceType) { | 555 if (exprType is InterfaceType) { |
| 556 var iteratedType = _findIteratedType(exprType); | 556 var iteratedType = _findIteratedType(exprType); |
| 557 if (iteratedType != null) { | 557 if (iteratedType != null) { |
| 558 element.type = iteratedType; | 558 element.type = iteratedType; |
| 559 } | 559 } |
| 560 } | 560 } |
| 561 } | 561 } |
| 562 | 562 |
| 563 List<DartType> _sealedTypes = null; | |
| 564 | |
| 565 bool _isSealed(DartType t) { | 563 bool _isSealed(DartType t) { |
| 566 if (_sealedTypes == null) { | 564 return _typeProvider.nonSubtypableTypes.contains(t); |
| 567 // TODO(vsm): Use the analyzer's list - see dartbug.com/23125. | |
| 568 _sealedTypes = <DartType>[ | |
| 569 _typeProvider.nullType, | |
| 570 _typeProvider.numType, | |
| 571 _typeProvider.intType, | |
| 572 _typeProvider.doubleType, | |
| 573 _typeProvider.boolType, | |
| 574 _typeProvider.stringType | |
| 575 ]; | |
| 576 } | |
| 577 return _sealedTypes.contains(t); | |
| 578 } | 565 } |
| 579 | 566 |
| 580 @override // to propagate types to identifiers | 567 @override // to propagate types to identifiers |
| 581 visitMethodInvocation(MethodInvocation node) { | 568 visitMethodInvocation(MethodInvocation node) { |
| 582 // TODO(jmesserly): we rely on having a staticType propagated to the | 569 // TODO(jmesserly): we rely on having a staticType propagated to the |
| 583 // methodName identifier. This shouldn't be necessary for method calls, so | 570 // methodName identifier. This shouldn't be necessary for method calls, so |
| 584 // analyzer doesn't do it by default. Conceptually what we're doing here | 571 // analyzer doesn't do it by default. Conceptually what we're doing here |
| 585 // is asking for a tear off. We need this until we can fix #132, and rely | 572 // is asking for a tear off. We need this until we can fix #132, and rely |
| 586 // on `node.staticElement == null` instead of `rules.isDynamicCall(node)`. | 573 // on `node.staticElement == null` instead of `rules.isDynamicCall(node)`. |
| 587 visitSimpleIdentifier(node.methodName); | 574 visitSimpleIdentifier(node.methodName); |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 678 } | 665 } |
| 679 } | 666 } |
| 680 | 667 |
| 681 // Review note: no longer need to override visitFunctionExpression, this is | 668 // Review note: no longer need to override visitFunctionExpression, this is |
| 682 // handled by the analyzer internally. | 669 // handled by the analyzer internally. |
| 683 // TODO(vsm): in visitbinaryExpression: check computeStaticReturnType result? | 670 // TODO(vsm): in visitbinaryExpression: check computeStaticReturnType result? |
| 684 // TODO(vsm): in visitFunctionDeclaration: Should we ever use the expression | 671 // TODO(vsm): in visitFunctionDeclaration: Should we ever use the expression |
| 685 // type in a (...) => expr or just the written type? | 672 // type in a (...) => expr or just the written type? |
| 686 | 673 |
| 687 } | 674 } |
| OLD | NEW |