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

Side by Side Diff: pkg/analyzer/lib/src/summary/summary_sdk.dart

Issue 2667343005: Infer Null for return type of functions with empty returns. (Closed)
Patch Set: Address comments, fix 28630, ddc expectations Created 3 years, 10 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.summary.summary_sdk; 5 library analyzer.src.summary.summary_sdk;
6 6
7 import 'package:analyzer/dart/element/element.dart'; 7 import 'package:analyzer/dart/element/element.dart';
8 import 'package:analyzer/dart/element/type.dart'; 8 import 'package:analyzer/dart/element/type.dart';
9 import 'package:analyzer/file_system/file_system.dart' show ResourceProvider; 9 import 'package:analyzer/file_system/file_system.dart' show ResourceProvider;
10 import 'package:analyzer/src/context/context.dart'; 10 import 'package:analyzer/src/context/context.dart';
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 class SummaryTypeProvider extends TypeProviderBase { 116 class SummaryTypeProvider extends TypeProviderBase {
117 LibraryElement _coreLibrary; 117 LibraryElement _coreLibrary;
118 LibraryElement _asyncLibrary; 118 LibraryElement _asyncLibrary;
119 119
120 InterfaceType _boolType; 120 InterfaceType _boolType;
121 InterfaceType _deprecatedType; 121 InterfaceType _deprecatedType;
122 InterfaceType _doubleType; 122 InterfaceType _doubleType;
123 InterfaceType _functionType; 123 InterfaceType _functionType;
124 InterfaceType _futureDynamicType; 124 InterfaceType _futureDynamicType;
125 InterfaceType _futureNullType; 125 InterfaceType _futureNullType;
126 InterfaceType _futureOrNullType;
126 InterfaceType _futureOrType; 127 InterfaceType _futureOrType;
127 InterfaceType _futureType; 128 InterfaceType _futureType;
128 InterfaceType _intType; 129 InterfaceType _intType;
129 InterfaceType _iterableDynamicType; 130 InterfaceType _iterableDynamicType;
130 InterfaceType _iterableType; 131 InterfaceType _iterableType;
131 InterfaceType _listType; 132 InterfaceType _listType;
132 InterfaceType _mapType; 133 InterfaceType _mapType;
133 DartObjectImpl _nullObject; 134 DartObjectImpl _nullObject;
134 InterfaceType _nullType; 135 InterfaceType _nullType;
135 InterfaceType _numType; 136 InterfaceType _numType;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 } 184 }
184 185
185 @override 186 @override
186 InterfaceType get futureNullType { 187 InterfaceType get futureNullType {
187 assert(_asyncLibrary != null); 188 assert(_asyncLibrary != null);
188 _futureNullType ??= futureType.instantiate(<DartType>[nullType]); 189 _futureNullType ??= futureType.instantiate(<DartType>[nullType]);
189 return _futureNullType; 190 return _futureNullType;
190 } 191 }
191 192
192 @override 193 @override
194 InterfaceType get futureOrNullType {
195 assert(_asyncLibrary != null);
196 _futureOrNullType ??= futureOrType.instantiate(<DartType>[nullType]);
197 return _futureOrNullType;
198 }
199
200 @override
193 InterfaceType get futureOrType { 201 InterfaceType get futureOrType {
194 assert(_asyncLibrary != null); 202 assert(_asyncLibrary != null);
195 try { 203 try {
196 _futureOrType ??= _getType(_asyncLibrary, "FutureOr"); 204 _futureOrType ??= _getType(_asyncLibrary, "FutureOr");
197 } on StateError { 205 } on StateError {
198 // FutureOr<T> is still fairly new, so if we're analyzing an SDK that 206 // FutureOr<T> is still fairly new, so if we're analyzing an SDK that
199 // doesn't have it yet, create an element for it. 207 // doesn't have it yet, create an element for it.
200 _futureOrType = 208 _futureOrType =
201 TypeProviderImpl.createPlaceholderFutureOr(futureType, objectType); 209 TypeProviderImpl.createPlaceholderFutureOr(futureType, objectType);
202 } 210 }
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 * throw a [StateError] if there is no class with the given name. 350 * throw a [StateError] if there is no class with the given name.
343 */ 351 */
344 InterfaceType _getType(LibraryElement library, String name) { 352 InterfaceType _getType(LibraryElement library, String name) {
345 Element element = library.getType(name); 353 Element element = library.getType(name);
346 if (element == null) { 354 if (element == null) {
347 throw new StateError("No definition of type $name"); 355 throw new StateError("No definition of type $name");
348 } 356 }
349 return (element as ClassElement).type; 357 return (element as ClassElement).type;
350 } 358 }
351 } 359 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698