Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(614)

Unified Diff: pkg/analyzer/lib/src/generated/constant.dart

Issue 1124433007: Fix constant evaluation logic for String.length. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/analyzer/test/generated/all_the_rest_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/lib/src/generated/constant.dart
diff --git a/pkg/analyzer/lib/src/generated/constant.dart b/pkg/analyzer/lib/src/generated/constant.dart
index 6aafe29f04a2986e1380ede8cf5b77cc0326f051..1a26cb164300fb16e6cda97872837bc5ee6d7bbe 100644
--- a/pkg/analyzer/lib/src/generated/constant.dart
+++ b/pkg/analyzer/lib/src/generated/constant.dart
@@ -1314,19 +1314,6 @@ class ConstantVisitor extends UnifyingAstVisitor<DartObjectImpl> {
*/
void beforeGetEvaluationResult(AstNode node) {}
- /**
- * Return `true` if the given [element] represents the `length` getter in
- * class 'String'.
- */
- bool isStringLength(Element element) {
- if (element is PropertyAccessorElement) {
- if (element.isGetter && element.name == 'length') {
- return element.enclosingElement == _typeProvider.stringType.element;
- }
- }
- return false;
- }
-
@override
DartObjectImpl visitAdjacentStrings(AdjacentStrings node) {
DartObjectImpl result = null;
@@ -1600,17 +1587,16 @@ class ConstantVisitor extends UnifyingAstVisitor<DartObjectImpl> {
@override
DartObjectImpl visitPrefixedIdentifier(PrefixedIdentifier node) {
+ SimpleIdentifier prefixNode = node.prefix;
+ Element prefixElement = prefixNode.staticElement;
// String.length
- {
- Element element = node.staticElement;
- if (isStringLength(element)) {
- DartObjectImpl prefixResult = node.prefix.accept(this);
+ if (prefixElement is! PrefixElement && prefixElement is! ClassElement) {
+ DartObjectImpl prefixResult = node.prefix.accept(this);
+ if (_isStringLength(prefixResult, node.identifier)) {
return prefixResult.stringLength(_typeProvider);
}
}
// importPrefix.CONST
- SimpleIdentifier prefixNode = node.prefix;
- Element prefixElement = prefixNode.staticElement;
if (prefixElement is! PrefixElement) {
DartObjectImpl prefixResult = prefixNode.accept(this);
if (prefixResult == null) {
@@ -1647,12 +1633,13 @@ class ConstantVisitor extends UnifyingAstVisitor<DartObjectImpl> {
@override
DartObjectImpl visitPropertyAccess(PropertyAccess node) {
- Element element = node.propertyName.staticElement;
- if (isStringLength(element)) {
- DartObjectImpl prefixResult = node.realTarget.accept(this);
- return prefixResult.stringLength(_typeProvider);
+ if (node.target != null) {
+ DartObjectImpl prefixResult = node.target.accept(this);
+ if (_isStringLength(prefixResult, node.propertyName)) {
+ return prefixResult.stringLength(_typeProvider);
+ }
}
- return _getConstantValue(node, element);
+ return _getConstantValue(node, node.propertyName.staticElement);
}
@override
@@ -1743,6 +1730,18 @@ class ConstantVisitor extends UnifyingAstVisitor<DartObjectImpl> {
}
/**
+ * Return `true` if the given [targetResult] represents a string and the
+ * [identifier] is "length".
+ */
+ bool _isStringLength(
+ DartObjectImpl targetResult, SimpleIdentifier identifier) {
+ if (targetResult == null || targetResult.type != _typeProvider.stringType) {
+ return false;
+ }
+ return identifier.name == 'length';
+ }
+
+ /**
* Return the value of the given [expression], or a representation of 'null'
* if the expression cannot be evaluated.
*/
« no previous file with comments | « no previous file | pkg/analyzer/test/generated/all_the_rest_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698