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

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

Issue 1367183004: analyzer strong mode: infer final field from initializer if super getters are dynamic (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: redo comment per Brian's suggestion Created 5 years, 2 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
« no previous file with comments | « no previous file | pkg/analyzer/test/src/task/strong_mode_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/src/generated/ast.dart'; 9 import 'package:analyzer/src/generated/ast.dart';
10 import 'package:analyzer/src/generated/element.dart'; 10 import 'package:analyzer/src/generated/element.dart';
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 if (overriddenGetters.isNotEmpty && _onlyGetters(overriddenGetters)) { 287 if (overriddenGetters.isNotEmpty && _onlyGetters(overriddenGetters)) {
288 newType = _computeReturnType(overriddenGetters); 288 newType = _computeReturnType(overriddenGetters);
289 List<ExecutableElement> overriddenSetters = inheritanceManager 289 List<ExecutableElement> overriddenSetters = inheritanceManager
290 .lookupOverrides( 290 .lookupOverrides(
291 fieldElement.enclosingElement, fieldElement.name + '='); 291 fieldElement.enclosingElement, fieldElement.name + '=');
292 if (!_isCompatible(newType, overriddenSetters)) { 292 if (!_isCompatible(newType, overriddenSetters)) {
293 newType = null; 293 newType = null;
294 } 294 }
295 } 295 }
296 // 296 //
297 // Then, if none was found, infer the type from the initialization 297 // If there is no overridden getter or if the overridden getter's type is
298 // expression. 298 // dynamic, then we can infer the type from the initialization expression
299 // without breaking subtype rules. We could potentially infer a consistent
300 // return type even if the overridden getter's type was not dynamic, but
301 // choose not to for simplicity. The field is required to be final to
302 // prevent choosing a type that is inconsistent with assignments we cannot
303 // analyze.
299 // 304 //
300 if (newType == null) { 305 if (newType == null || newType.isDynamic) {
301 if (fieldElement.initializer != null && 306 if (fieldElement.initializer != null &&
302 (fieldElement.isFinal || overriddenGetters.isEmpty)) { 307 (fieldElement.isFinal || overriddenGetters.isEmpty)) {
303 newType = fieldElement.initializer.returnType; 308 newType = fieldElement.initializer.returnType;
304 } 309 }
305 } 310 }
306 if (newType == null || newType.isBottom) { 311 if (newType == null || newType.isBottom) {
307 newType = typeProvider.dynamicType; 312 newType = typeProvider.dynamicType;
308 } 313 }
309 (fieldElement as FieldElementImpl).type = newType; 314 (fieldElement as FieldElementImpl).type = newType;
310 setReturnType(fieldElement.getter, newType); 315 setReturnType(fieldElement.getter, newType);
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
472 results.add(element); 477 results.add(element);
473 } 478 }
474 } 479 }
475 } 480 }
476 } 481 }
477 482
478 /** 483 /**
479 * A class of exception that is not used anywhere else. 484 * A class of exception that is not used anywhere else.
480 */ 485 */
481 class _CycleException implements Exception {} 486 class _CycleException implements Exception {}
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/test/src/task/strong_mode_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698