| Index: pkg/analyzer/lib/src/task/strong_mode.dart
|
| diff --git a/pkg/analyzer/lib/src/task/strong_mode.dart b/pkg/analyzer/lib/src/task/strong_mode.dart
|
| index 284a31ad55cc6386e4caa930421d87215029c06f..3f41ded34044c8d2462851258d10d34e1c8e32f2 100644
|
| --- a/pkg/analyzer/lib/src/task/strong_mode.dart
|
| +++ b/pkg/analyzer/lib/src/task/strong_mode.dart
|
| @@ -29,6 +29,12 @@ void setFieldType(VariableElement field, DartType newType) {
|
| }
|
| }
|
|
|
| +bool hasInstanceGetterReference(Expression expression) {
|
| + var visitor = new _InstanceGetterReferenceVisitor();
|
| + expression.accept(visitor);
|
| + return visitor.hasInstanceFieldOrGetterReference;
|
| +}
|
| +
|
| /**
|
| * Return the element for the single parameter of the given [setter], or `null`
|
| * if the executable element is not a setter or does not have a single
|
| @@ -363,9 +369,10 @@ class InstanceMemberInferrer {
|
| // analyze.
|
| //
|
| if (newType == null || newType.isDynamic) {
|
| - if (fieldElement.initializer != null &&
|
| + FunctionElement initializer = fieldElement.initializer;
|
| + if (initializer != null &&
|
| (fieldElement.isFinal || overriddenGetters.isEmpty)) {
|
| - newType = fieldElement.initializer.returnType;
|
| + newType = initializer.returnType;
|
| }
|
| }
|
| if (newType == null || newType.isBottom || newType.isDartCoreNull) {
|
| @@ -477,6 +484,8 @@ class VariableGatherer extends RecursiveAstVisitor {
|
| */
|
| final Set<VariableElement> results = new HashSet<VariableElement>();
|
|
|
| + bool hasInstanceFieldOrGetterReference = false;
|
| +
|
| /**
|
| * Initialize a newly created gatherer to gather all of the variables that
|
| * pass the given [filter] (or all variables if no filter is provided).
|
| @@ -494,9 +503,42 @@ class VariableGatherer extends RecursiveAstVisitor {
|
| }
|
|
|
| Element element = nonAccessor(node.staticElement);
|
| - if (element is VariableElement && (filter == null || filter(element))) {
|
| - results.add(element);
|
| +
|
| +// if (element == null) {
|
| +// AstNode parent = node.parent;
|
| +// if (parent is PropertyAccess && parent.propertyName == node ||
|
| +// parent is PrefixedIdentifier && parent.identifier == node) {
|
| +// hasInstanceFieldOrGetterReference = true;
|
| +// }
|
| +// } else
|
| + if (element is FieldElement && !element.isStatic ||
|
| + element is PropertyAccessorElement && !element.isStatic) {
|
| + hasInstanceFieldOrGetterReference = true;
|
| + }
|
| +
|
| + if (element is VariableElement) {
|
| + if (filter == null || filter(element)) {
|
| + results.add(element);
|
| + }
|
| + }
|
| + }
|
| + }
|
| +}
|
| +
|
| +class _InstanceGetterReferenceVisitor extends RecursiveAstVisitor {
|
| + bool hasInstanceFieldOrGetterReference = false;
|
| +
|
| + @override
|
| + void visitSimpleIdentifier(SimpleIdentifier node) {
|
| + Element element = node.staticElement;
|
| + if (element == null) {
|
| + AstNode parent = node.parent;
|
| + if (parent is PropertyAccess && parent.propertyName == node ||
|
| + parent is PrefixedIdentifier && parent.identifier == node) {
|
| + hasInstanceFieldOrGetterReference = true;
|
| }
|
| + } else if (element is PropertyAccessorElement && !element.isStatic) {
|
| + hasInstanceFieldOrGetterReference = true;
|
| }
|
| }
|
| }
|
|
|