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

Side by Side Diff: pkg/analyzer/lib/src/generated/error_verifier.dart

Issue 897673003: Implement new return type checking rules in analyzer. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Reformat and sort class members. Created 5 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 | Annotate | Revision Log
« no previous file with comments | « pkg/analyzer/lib/src/generated/error.dart ('k') | pkg/analyzer/lib/src/generated/resolver.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) 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 engine.resolver.error_verifier; 5 library engine.resolver.error_verifier;
6 6
7 import "dart:math" as math; 7 import "dart:math" as math;
8 import 'dart:collection'; 8 import 'dart:collection';
9 9
10 import 'ast.dart'; 10 import 'ast.dart';
(...skipping 659 matching lines...) Expand 10 before | Expand all | Expand 10 after
670 } 670 }
671 _checkForNonVoidReturnTypeForSetter(returnType); 671 _checkForNonVoidReturnTypeForSetter(returnType);
672 } 672 }
673 } 673 }
674 if (node.isSetter) { 674 if (node.isSetter) {
675 _checkForInvalidModifierOnBody( 675 _checkForInvalidModifierOnBody(
676 node.functionExpression.body, 676 node.functionExpression.body,
677 CompileTimeErrorCode.INVALID_MODIFIER_ON_SETTER); 677 CompileTimeErrorCode.INVALID_MODIFIER_ON_SETTER);
678 } 678 }
679 _checkForTypeAnnotationDeferredClass(returnType); 679 _checkForTypeAnnotationDeferredClass(returnType);
680 _checkForIllegalReturnType(returnType);
680 return super.visitFunctionDeclaration(node); 681 return super.visitFunctionDeclaration(node);
681 } finally { 682 } finally {
682 _enclosingFunction = outerFunction; 683 _enclosingFunction = outerFunction;
683 } 684 }
684 } 685 }
685 686
686 @override 687 @override
687 Object visitFunctionExpression(FunctionExpression node) { 688 Object visitFunctionExpression(FunctionExpression node) {
688 // If this function expression is wrapped in a function declaration, don't 689 // If this function expression is wrapped in a function declaration, don't
689 // change the enclosingFunction field. 690 // change the enclosingFunction field.
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
855 _checkForNonVoidReturnTypeForSetter(returnTypeName); 856 _checkForNonVoidReturnTypeForSetter(returnTypeName);
856 _checkForConflictingStaticSetterAndInstanceMember(node); 857 _checkForConflictingStaticSetterAndInstanceMember(node);
857 } else if (node.isOperator) { 858 } else if (node.isOperator) {
858 _checkForOptionalParameterInOperator(node); 859 _checkForOptionalParameterInOperator(node);
859 _checkForWrongNumberOfParametersForOperator(node); 860 _checkForWrongNumberOfParametersForOperator(node);
860 _checkForNonVoidReturnTypeForOperator(node); 861 _checkForNonVoidReturnTypeForOperator(node);
861 } 862 }
862 _checkForConcreteClassWithAbstractMember(node); 863 _checkForConcreteClassWithAbstractMember(node);
863 _checkForAllInvalidOverrideErrorCodesForMethod(node); 864 _checkForAllInvalidOverrideErrorCodesForMethod(node);
864 _checkForTypeAnnotationDeferredClass(returnTypeName); 865 _checkForTypeAnnotationDeferredClass(returnTypeName);
866 _checkForIllegalReturnType(returnTypeName);
865 return super.visitMethodDeclaration(node); 867 return super.visitMethodDeclaration(node);
866 } finally { 868 } finally {
867 _enclosingFunction = previousFunction; 869 _enclosingFunction = previousFunction;
868 _isInStaticMethod = false; 870 _isInStaticMethod = false;
869 } 871 }
870 } 872 }
871 873
872 @override 874 @override
873 Object visitMethodInvocation(MethodInvocation node) { 875 Object visitMethodInvocation(MethodInvocation node) {
874 Expression target = node.realTarget; 876 Expression target = node.realTarget;
(...skipping 2599 matching lines...) Expand 10 before | Expand all | Expand 10 after
3474 for (ClassMember classMember in classMembers) { 3476 for (ClassMember classMember in classMembers) {
3475 if (classMember is FieldDeclaration && 3477 if (classMember is FieldDeclaration &&
3476 _checkForFinalNotInitialized(classMember.fields)) { 3478 _checkForFinalNotInitialized(classMember.fields)) {
3477 foundError = true; 3479 foundError = true;
3478 } 3480 }
3479 } 3481 }
3480 return foundError; 3482 return foundError;
3481 } 3483 }
3482 3484
3483 /** 3485 /**
3486 * If the current function is async, async*, or sync*, verify that its
3487 * declared return type is assignable to Future, Stream, or Iterable,
3488 * respectively. If not, report the error using [node].
3489 */
3490 void _checkForIllegalReturnType(TypeName node) {
3491 if (node == null) {
3492 // No declared return type, so the return type must be dynamic, which is
3493 // assignable to everything.
3494 return;
3495 }
3496 if (_enclosingFunction.isAsynchronous) {
3497 if (_enclosingFunction.isGenerator) {
3498 if (!_enclosingFunction.returnType.isAssignableTo(
3499 _typeProvider.streamDynamicType)) {
3500 _errorReporter.reportErrorForNode(
3501 StaticTypeWarningCode.ILLEGAL_ASYNC_GENERATOR_RETURN_TYPE,
3502 node);
3503 }
3504 } else {
3505 if (!_enclosingFunction.returnType.isAssignableTo(
3506 _typeProvider.futureDynamicType)) {
3507 _errorReporter.reportErrorForNode(
3508 StaticTypeWarningCode.ILLEGAL_ASYNC_RETURN_TYPE,
3509 node);
3510 }
3511 }
3512 } else if (_enclosingFunction.isGenerator) {
3513 if (!_enclosingFunction.returnType.isAssignableTo(
3514 _typeProvider.iterableDynamicType)) {
3515 _errorReporter.reportErrorForNode(
3516 StaticTypeWarningCode.ILLEGAL_SYNC_GENERATOR_RETURN_TYPE,
3517 node);
3518 }
3519 }
3520 }
3521
3522 /**
3484 * This verifies that the passed implements clause does not implement classes that are deferred. 3523 * This verifies that the passed implements clause does not implement classes that are deferred.
3485 * 3524 *
3486 * @param node the implements clause to test 3525 * @param node the implements clause to test
3487 * @return `true` if and only if an error code is generated on the passed node 3526 * @return `true` if and only if an error code is generated on the passed node
3488 * See [CompileTimeErrorCode.IMPLEMENTS_DEFERRED_CLASS]. 3527 * See [CompileTimeErrorCode.IMPLEMENTS_DEFERRED_CLASS].
3489 */ 3528 */
3490 bool _checkForImplementsDeferredClass(ImplementsClause node) { 3529 bool _checkForImplementsDeferredClass(ImplementsClause node) {
3491 if (node == null) { 3530 if (node == null) {
3492 return false; 3531 return false;
3493 } 3532 }
(...skipping 2778 matching lines...) Expand 10 before | Expand all | Expand 10 after
6272 toCheck.add(type.element); 6311 toCheck.add(type.element);
6273 // type arguments 6312 // type arguments
6274 if (type is InterfaceType) { 6313 if (type is InterfaceType) {
6275 InterfaceType interfaceType = type; 6314 InterfaceType interfaceType = type;
6276 for (DartType typeArgument in interfaceType.typeArguments) { 6315 for (DartType typeArgument in interfaceType.typeArguments) {
6277 _addTypeToCheck(typeArgument); 6316 _addTypeToCheck(typeArgument);
6278 } 6317 }
6279 } 6318 }
6280 } 6319 }
6281 } 6320 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/generated/error.dart ('k') | pkg/analyzer/lib/src/generated/resolver.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698