| OLD | NEW | 
|---|
| 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 642 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 653       _inGenerator = node.isGenerator; | 653       _inGenerator = node.isGenerator; | 
| 654       FunctionType functionType = _enclosingFunction?.type; | 654       FunctionType functionType = _enclosingFunction?.type; | 
| 655       DartType expectedReturnType = functionType == null | 655       DartType expectedReturnType = functionType == null | 
| 656           ? DynamicTypeImpl.instance | 656           ? DynamicTypeImpl.instance | 
| 657           : functionType.returnType; | 657           : functionType.returnType; | 
| 658       ExecutableElement function = _enclosingFunction; | 658       ExecutableElement function = _enclosingFunction; | 
| 659       bool isSetterWithImplicitReturn = function.hasImplicitReturnType && | 659       bool isSetterWithImplicitReturn = function.hasImplicitReturnType && | 
| 660           function is PropertyAccessorElement && | 660           function is PropertyAccessorElement && | 
| 661           function.isSetter; | 661           function.isSetter; | 
| 662       if (!isSetterWithImplicitReturn) { | 662       if (!isSetterWithImplicitReturn) { | 
| 663         _checkForReturnOfInvalidType(node.expression, expectedReturnType); | 663         _checkForReturnOfInvalidType(node.expression, expectedReturnType, | 
|  | 664             isArrowFunction: true); | 
| 664       } | 665       } | 
| 665       return super.visitExpressionFunctionBody(node); | 666       return super.visitExpressionFunctionBody(node); | 
| 666     } finally { | 667     } finally { | 
| 667       _inAsync = wasInAsync; | 668       _inAsync = wasInAsync; | 
| 668       _inGenerator = wasInGenerator; | 669       _inGenerator = wasInGenerator; | 
| 669     } | 670     } | 
| 670   } | 671   } | 
| 671 | 672 | 
| 672   @override | 673   @override | 
| 673   Object visitFieldDeclaration(FieldDeclaration node) { | 674   Object visitFieldDeclaration(FieldDeclaration node) { | 
| (...skipping 4917 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 5591   /** | 5592   /** | 
| 5592    * Check that a type mis-match between the type of the [returnExpression] and | 5593    * Check that a type mis-match between the type of the [returnExpression] and | 
| 5593    * the [expectedReturnType] by the enclosing method or function. | 5594    * the [expectedReturnType] by the enclosing method or function. | 
| 5594    * | 5595    * | 
| 5595    * This method is called both by [_checkForAllReturnStatementErrorCodes] | 5596    * This method is called both by [_checkForAllReturnStatementErrorCodes] | 
| 5596    * and [visitExpressionFunctionBody]. | 5597    * and [visitExpressionFunctionBody]. | 
| 5597    * | 5598    * | 
| 5598    * See [StaticTypeWarningCode.RETURN_OF_INVALID_TYPE]. | 5599    * See [StaticTypeWarningCode.RETURN_OF_INVALID_TYPE]. | 
| 5599    */ | 5600    */ | 
| 5600   void _checkForReturnOfInvalidType( | 5601   void _checkForReturnOfInvalidType( | 
| 5601       Expression returnExpression, DartType expectedReturnType) { | 5602       Expression returnExpression, DartType expectedReturnType, | 
|  | 5603       {bool isArrowFunction = false}) { | 
| 5602     if (_enclosingFunction == null) { | 5604     if (_enclosingFunction == null) { | 
| 5603       return; | 5605       return; | 
| 5604     } | 5606     } | 
| 5605     if (_inGenerator) { | 5607     if (_inGenerator) { | 
| 5606       // "return expression;" is disallowed in generators, but this is checked | 5608       // "return expression;" is disallowed in generators, but this is checked | 
| 5607       // elsewhere.  Bare "return" is always allowed in generators regardless | 5609       // elsewhere.  Bare "return" is always allowed in generators regardless | 
| 5608       // of the return type.  So no need to do any further checking. | 5610       // of the return type.  So no need to do any further checking. | 
| 5609       return; | 5611       return; | 
| 5610     } | 5612     } | 
| 5611     DartType staticReturnType = _computeReturnTypeForMethod(returnExpression); | 5613     DartType staticReturnType = _computeReturnTypeForMethod(returnExpression); | 
| 5612     if (expectedReturnType.isVoid) { | 5614     if (expectedReturnType.isVoid) { | 
|  | 5615       if (isArrowFunction) { | 
|  | 5616         // "void f(..) => e" admits all types for "e". | 
|  | 5617         return; | 
|  | 5618       } | 
| 5613       if (staticReturnType.isVoid || | 5619       if (staticReturnType.isVoid || | 
| 5614           staticReturnType.isDynamic || | 5620           staticReturnType.isDynamic || | 
| 5615           staticReturnType.isBottom || | 5621           staticReturnType.isBottom || | 
| 5616           staticReturnType.isDartCoreNull) { | 5622           staticReturnType.isDartCoreNull) { | 
| 5617         return; | 5623         return; | 
| 5618       } | 5624       } | 
| 5619       _errorReporter.reportTypeErrorForNode( | 5625       _errorReporter.reportTypeErrorForNode( | 
| 5620           StaticTypeWarningCode.RETURN_OF_INVALID_TYPE, returnExpression, [ | 5626           StaticTypeWarningCode.RETURN_OF_INVALID_TYPE, returnExpression, [ | 
| 5621         staticReturnType, | 5627         staticReturnType, | 
| 5622         expectedReturnType, | 5628         expectedReturnType, | 
| (...skipping 1507 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 7130 class _InvocationCollector extends RecursiveAstVisitor { | 7136 class _InvocationCollector extends RecursiveAstVisitor { | 
| 7131   final List<String> superCalls = <String>[]; | 7137   final List<String> superCalls = <String>[]; | 
| 7132 | 7138 | 
| 7133   @override | 7139   @override | 
| 7134   visitMethodInvocation(MethodInvocation node) { | 7140   visitMethodInvocation(MethodInvocation node) { | 
| 7135     if (node.target is SuperExpression) { | 7141     if (node.target is SuperExpression) { | 
| 7136       superCalls.add(node.methodName.name); | 7142       superCalls.add(node.methodName.name); | 
| 7137     } | 7143     } | 
| 7138   } | 7144   } | 
| 7139 } | 7145 } | 
| OLD | NEW | 
|---|