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

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: 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 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 // Then, if none was found, infer the type from the initialization
298 // expression. 298 // expression.
299 // 299 //
300 if (newType == null) { 300 // Also, if we're the field is final and overridden getter is dynamic,
301 // we can infer from the initialization without breaking subtyping rules
302 // (return type is covariant).
303 //
304 if (newType == null || newType.isDynamic) {
Jennifer Messerly 2015/09/25 21:41:55 this fix is intended to match: https://github.com/
Brian Wilkerson 2015/09/25 22:00:00 hasImplicitType only applies to variables, not typ
Jennifer Messerly 2015/09/25 22:22:11 What doesn't make sense about the comment? That's
Leaf 2015/09/25 22:36:32 The comment has a wording problem in the first lin
Jennifer Messerly 2015/09/25 22:48:23 ah good catch. How about this: Also infer from th
Brian Wilkerson 2015/09/26 00:36:29 Aside from the grammatical error, it seems to me t
Jennifer Messerly 2015/09/26 00:48:23 "if <condition>, do this" "also, if <other conditi
301 if (fieldElement.initializer != null && 305 if (fieldElement.initializer != null &&
302 (fieldElement.isFinal || overriddenGetters.isEmpty)) { 306 (fieldElement.isFinal || overriddenGetters.isEmpty)) {
303 newType = fieldElement.initializer.returnType; 307 newType = fieldElement.initializer.returnType;
304 } 308 }
305 } 309 }
306 if (newType == null || newType.isBottom) { 310 if (newType == null || newType.isBottom) {
307 newType = typeProvider.dynamicType; 311 newType = typeProvider.dynamicType;
308 } 312 }
309 (fieldElement as FieldElementImpl).type = newType; 313 (fieldElement as FieldElementImpl).type = newType;
310 setReturnType(fieldElement.getter, newType); 314 setReturnType(fieldElement.getter, newType);
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
472 results.add(element); 476 results.add(element);
473 } 477 }
474 } 478 }
475 } 479 }
476 } 480 }
477 481
478 /** 482 /**
479 * A class of exception that is not used anywhere else. 483 * A class of exception that is not used anywhere else.
480 */ 484 */
481 class _CycleException implements Exception {} 485 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