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

Side by Side Diff: pkg/analyzer/lib/src/generated/error_verifier.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) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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.generated.error_verifier; 5 library analyzer.src.generated.error_verifier;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 import "dart:math" as math; 8 import "dart:math" as math;
9 9
10 import 'package:analyzer/dart/ast/ast.dart'; 10 import 'package:analyzer/dart/ast/ast.dart';
(...skipping 2288 matching lines...) Expand 10 before | Expand all | Expand 10 after
2299 } 2299 }
2300 if (expectedReturnType is InterfaceType && 2300 if (expectedReturnType is InterfaceType &&
2301 expectedReturnType.isDartAsyncFuture) { 2301 expectedReturnType.isDartAsyncFuture) {
2302 DartType futureArgument = expectedReturnType.typeArguments[0]; 2302 DartType futureArgument = expectedReturnType.typeArguments[0];
2303 if (futureArgument.isDynamic || 2303 if (futureArgument.isDynamic ||
2304 futureArgument.isDartCoreNull || 2304 futureArgument.isDartCoreNull ||
2305 futureArgument.isObject) { 2305 futureArgument.isObject) {
2306 return; 2306 return;
2307 } 2307 }
2308 } 2308 }
2309 } else if (expectedReturnType.isDynamic || expectedReturnType.isVoid) { 2309 } else if (expectedReturnType.isDynamic ||
2310 expectedReturnType.isVoid ||
2311 expectedReturnType.isDartCoreNull) {
2310 return; 2312 return;
2311 } 2313 }
2312 _hasReturnWithoutValue = true; 2314 _hasReturnWithoutValue = true;
2313 _errorReporter.reportErrorForNode( 2315 _errorReporter.reportErrorForNode(
2314 StaticWarningCode.RETURN_WITHOUT_VALUE, statement); 2316 StaticWarningCode.RETURN_WITHOUT_VALUE, statement);
2315 return; 2317 return;
2316 } else if (_inGenerator) { 2318 } else if (_inGenerator) {
2317 // RETURN_IN_GENERATOR 2319 // RETURN_IN_GENERATOR
2318 _errorReporter.reportErrorForNode( 2320 _errorReporter.reportErrorForNode(
2319 CompileTimeErrorCode.RETURN_IN_GENERATOR, 2321 CompileTimeErrorCode.RETURN_IN_GENERATOR,
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
2506 return actualStaticType != null && 2508 return actualStaticType != null &&
2507 _checkForAssignableExpressionAtType( 2509 _checkForAssignableExpressionAtType(
2508 expression, actualStaticType, expectedStaticType, errorCode); 2510 expression, actualStaticType, expectedStaticType, errorCode);
2509 } 2511 }
2510 2512
2511 bool _checkForAssignableExpressionAtType( 2513 bool _checkForAssignableExpressionAtType(
2512 Expression expression, 2514 Expression expression,
2513 DartType actualStaticType, 2515 DartType actualStaticType,
2514 DartType expectedStaticType, 2516 DartType expectedStaticType,
2515 ErrorCode errorCode) { 2517 ErrorCode errorCode) {
2516 // TODO(leafp): Move the Downcast functionality here.
2517 if (!_expressionIsAssignableAtType( 2518 if (!_expressionIsAssignableAtType(
2518 expression, actualStaticType, expectedStaticType)) { 2519 expression, actualStaticType, expectedStaticType)) {
2519 _errorReporter.reportTypeErrorForNode( 2520 _errorReporter.reportTypeErrorForNode(
2520 errorCode, expression, [actualStaticType, expectedStaticType]); 2521 errorCode, expression, [actualStaticType, expectedStaticType]);
2521 return false; 2522 return false;
2522 } 2523 }
2523 return true; 2524 return true;
2524 } 2525 }
2525 2526
2526 /** 2527 /**
(...skipping 3718 matching lines...) Expand 10 before | Expand all | Expand 10 after
6245 } 6246 }
6246 return staticReturnType; 6247 return staticReturnType;
6247 } 6248 }
6248 6249
6249 bool _expressionIsAssignableAtType(Expression expression, 6250 bool _expressionIsAssignableAtType(Expression expression,
6250 DartType actualStaticType, DartType expectedStaticType) { 6251 DartType actualStaticType, DartType expectedStaticType) {
6251 bool concrete = _options.strongMode && checker.hasStrictArrow(expression); 6252 bool concrete = _options.strongMode && checker.hasStrictArrow(expression);
6252 if (concrete && actualStaticType is FunctionType) { 6253 if (concrete && actualStaticType is FunctionType) {
6253 actualStaticType = 6254 actualStaticType =
6254 _typeSystem.functionTypeToConcreteType(actualStaticType); 6255 _typeSystem.functionTypeToConcreteType(actualStaticType);
6255 // TODO(leafp): Move the Downcast functionality here.
6256 } 6256 }
6257 return _typeSystem.isAssignableTo(actualStaticType, expectedStaticType); 6257 return _typeSystem.isAssignableTo(actualStaticType, expectedStaticType);
6258 } 6258 }
6259 6259
6260 MethodElement _findOverriddenMemberThatMustCallSuper(MethodDeclaration node) { 6260 MethodElement _findOverriddenMemberThatMustCallSuper(MethodDeclaration node) {
6261 ExecutableElement overriddenMember = _getOverriddenMember(node.element); 6261 ExecutableElement overriddenMember = _getOverriddenMember(node.element);
6262 List<ExecutableElement> seen = <ExecutableElement>[]; 6262 List<ExecutableElement> seen = <ExecutableElement>[];
6263 while ( 6263 while (
6264 overriddenMember is MethodElement && !seen.contains(overriddenMember)) { 6264 overriddenMember is MethodElement && !seen.contains(overriddenMember)) {
6265 for (ElementAnnotation annotation in overriddenMember.metadata) { 6265 for (ElementAnnotation annotation in overriddenMember.metadata) {
(...skipping 811 matching lines...) Expand 10 before | Expand all | Expand 10 after
7077 class _InvocationCollector extends RecursiveAstVisitor { 7077 class _InvocationCollector extends RecursiveAstVisitor {
7078 final List<String> superCalls = <String>[]; 7078 final List<String> superCalls = <String>[];
7079 7079
7080 @override 7080 @override
7081 visitMethodInvocation(MethodInvocation node) { 7081 visitMethodInvocation(MethodInvocation node) {
7082 if (node.target is SuperExpression) { 7082 if (node.target is SuperExpression) {
7083 superCalls.add(node.methodName.name); 7083 superCalls.add(node.methodName.name);
7084 } 7084 }
7085 } 7085 }
7086 } 7086 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/lib/src/generated/resolver.dart » ('j') | pkg/analyzer/lib/src/generated/resolver.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698