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

Side by Side Diff: pkg/analyzer/lib/src/task/strong_mode.dart

Issue 2777733002: Update final fields inference according to the clarified specification. (Closed)
Patch Set: Created 3 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 unified diff | Download patch
OLDNEW
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 library analyzer.src.task.strong_mode; 5 library analyzer.src.task.strong_mode;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 8
9 import 'package:analyzer/dart/ast/ast.dart'; 9 import 'package:analyzer/dart/ast/ast.dart';
10 import 'package:analyzer/dart/ast/visitor.dart'; 10 import 'package:analyzer/dart/ast/visitor.dart';
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 107
108 /** 108 /**
109 * Return `true` if the list of [elements] contains only methods. 109 * Return `true` if the list of [elements] contains only methods.
110 */ 110 */
111 bool _allSameElementKind( 111 bool _allSameElementKind(
112 ExecutableElement element, List<ExecutableElement> elements) { 112 ExecutableElement element, List<ExecutableElement> elements) {
113 return elements.every((e) => e.kind == element.kind); 113 return elements.every((e) => e.kind == element.kind);
114 } 114 }
115 115
116 /** 116 /**
117 * Compute the inferred type for the given property accessor [element]. The 117 * Compute the inferred type for the given property [accessor]. The returned
118 * returned value is never `null`, but might be an error, and/or have the 118 * value is never `null`, but might be an error, and/or have the `null` type.
119 * `null` type.
120 */ 119 */
121 _FieldOverrideInferenceResult _computeFieldOverrideType( 120 _FieldOverrideInferenceResult _computeFieldOverrideType(
122 ExecutableElement element) { 121 PropertyAccessorElement accessor) {
123 String name = element.displayName; 122 String name = accessor.displayName;
124 123
125 var overriddenElements = <ExecutableElement>[]; 124 var overriddenElements = <ExecutableElement>[];
126 overriddenElements.addAll( 125 overriddenElements.addAll(
127 inheritanceManager.lookupOverrides(element.enclosingElement, name)); 126 inheritanceManager.lookupOverrides(accessor.enclosingElement, name));
128 overriddenElements.addAll( 127 if (overriddenElements.isEmpty || !accessor.variable.isFinal) {
129 inheritanceManager.lookupOverrides(element.enclosingElement, '$name=')); 128 List<ExecutableElement> overriddenSetters = inheritanceManager
129 .lookupOverrides(accessor.enclosingElement, '$name=');
130 overriddenElements.addAll(overriddenSetters);
131 }
130 132
131 bool isCovariant = false; 133 bool isCovariant = false;
132 DartType impliedType; 134 DartType impliedType;
133 for (ExecutableElement overriddenElement in overriddenElements) { 135 for (ExecutableElement overriddenElement in overriddenElements) {
134 FunctionType overriddenType = 136 FunctionType overriddenType =
135 _toOverriddenFunctionType(element, overriddenElement); 137 _toOverriddenFunctionType(accessor, overriddenElement);
136 if (overriddenType == null) { 138 if (overriddenType == null) {
137 return new _FieldOverrideInferenceResult(false, null, true); 139 return new _FieldOverrideInferenceResult(false, null, true);
138 } 140 }
139 141
140 DartType type; 142 DartType type;
141 if (overriddenElement.kind == ElementKind.GETTER) { 143 if (overriddenElement.kind == ElementKind.GETTER) {
142 type = overriddenType.returnType; 144 type = overriddenType.returnType;
143 } else if (overriddenElement.kind == ElementKind.SETTER) { 145 } else if (overriddenElement.kind == ElementKind.SETTER) {
144 if (overriddenType.parameters.length == 1) { 146 if (overriddenType.parameters.length == 1) {
145 ParameterElement parameter = overriddenType.parameters[0]; 147 ParameterElement parameter = overriddenType.parameters[0];
(...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after
610 AstNode parent = node.parent; 612 AstNode parent = node.parent;
611 if (parent is PropertyAccess && parent.propertyName == node || 613 if (parent is PropertyAccess && parent.propertyName == node ||
612 parent is PrefixedIdentifier && parent.identifier == node) { 614 parent is PrefixedIdentifier && parent.identifier == node) {
613 isValid = false; 615 isValid = false;
614 } 616 }
615 } else if (element is PropertyAccessorElement && !element.isStatic) { 617 } else if (element is PropertyAccessorElement && !element.isStatic) {
616 isValid = false; 618 isValid = false;
617 } 619 }
618 } 620 }
619 } 621 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/summary/link.dart ('k') | pkg/analyzer/test/src/summary/top_level_inference_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698