Skip to content

Commit ba01596

Browse files
emmanuel-pcommit-bot@chromium.org
authored andcommitted
Revert "Analyzer: Report on return types of Future.catchError function"
This reverts commit d5ee021. Reason for revert: Breaks google3: b/178222419 Original change's description: > Analyzer: Report on return types of Future.catchError function > > The type of the `onError` parameter of Future<T>.catchError is just Function, > but the function can either have signature `FutureOr<T> Function(dynamic)` or > `FutureOr<T> Function(dynamic, StackTrace)`. This change adds checks for return > statements in a function literal passed to `onError`, and the return type of a > function-typed expression passed to `onError`. > > We still need to check parameter types. > > #35825 > > Change-Id: I3a1d1c444e298c5816fcd1d4bc537f7b87fa3da1 > Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/176221 > Commit-Queue: Samuel Rawlins <[email protected]> > Reviewed-by: Konstantin Shcheglov <[email protected]> > Reviewed-by: Brian Wilkerson <[email protected]> [email protected],[email protected],[email protected] # Not skipping CQ checks because original CL landed > 1 day ago. Change-Id: I8ebbaac0a4b44293576809baa2dc2c3fdcf35379 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/180822 Commit-Queue: David Morgan <[email protected]> Reviewed-by: David Morgan <[email protected]>
1 parent 341213b commit ba01596

12 files changed

+9
-486
lines changed

pkg/analyzer/lib/error/error.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -559,8 +559,6 @@ const List<ErrorCode> errorCodeValues = [
559559
HintCode.PACKAGE_IMPORT_CONTAINS_DOT_DOT,
560560
HintCode.RECEIVER_OF_TYPE_NEVER,
561561
HintCode.RETURN_OF_DO_NOT_STORE,
562-
HintCode.RETURN_OF_INVALID_TYPE_FROM_CATCH_ERROR,
563-
HintCode.RETURN_TYPE_INVALID_FOR_CATCH_ERROR,
564562
HintCode.SDK_VERSION_AS_EXPRESSION_IN_CONST_CONTEXT,
565563
HintCode.SDK_VERSION_ASYNC_EXPORTED_FROM_CORE,
566564
HintCode.SDK_VERSION_BOOL_OPERATOR_IN_CONST_CONTEXT,

pkg/analyzer/lib/src/dart/error/hint_codes.dart

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1745,28 +1745,6 @@ class HintCode extends AnalyzerErrorCode {
17451745
"'{1}' is also annotated.",
17461746
correction: "Annotate '{1}' with 'doNotStore'.");
17471747

1748-
/**
1749-
* Parameters:
1750-
* 0: the return type as declared in the return statement
1751-
* 1: the expected return type as defined by the type of the Future
1752-
*/
1753-
static const HintCode RETURN_OF_INVALID_TYPE_FROM_CATCH_ERROR = HintCode(
1754-
'RETURN_OF_INVALID_TYPE',
1755-
"A value of type '{0}' can't be returned by the 'onError' handler because "
1756-
"it must be assignable to '{1}'.",
1757-
uniqueName: 'RETURN_OF_INVALID_TYPE_FROM_CATCH_ERROR',
1758-
);
1759-
1760-
/**
1761-
* Parameters:
1762-
* 0: the return type of the function
1763-
* 1: the expected return type as defined by the type of the Future
1764-
*/
1765-
static const HintCode RETURN_TYPE_INVALID_FOR_CATCH_ERROR = HintCode(
1766-
'RETURN_TYPE_INVALID_FOR_CATCH_ERROR',
1767-
"The return type '{0}' isn't assignable to '{1}', as required by "
1768-
"'Future.catchError'.");
1769-
17701748
/**
17711749
* No parameters.
17721750
*/

pkg/analyzer/lib/src/error/best_practices_verifier.dart

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import 'package:analyzer/src/dart/element/type_system.dart';
2323
import 'package:analyzer/src/dart/resolver/body_inference_context.dart';
2424
import 'package:analyzer/src/dart/resolver/exit_detector.dart';
2525
import 'package:analyzer/src/dart/resolver/scope.dart';
26-
import 'package:analyzer/src/error/catch_error_verifier.dart';
2726
import 'package:analyzer/src/error/codes.dart';
2827
import 'package:analyzer/src/error/deprecated_member_use_verifier.dart';
2928
import 'package:analyzer/src/error/must_call_super_verifier.dart';
@@ -73,8 +72,6 @@ class BestPracticesVerifier extends RecursiveAstVisitor<void> {
7372

7473
final MustCallSuperVerifier _mustCallSuperVerifier;
7574

76-
final CatchErrorVerifier _catchErrorVerifier;
77-
7875
/// The [WorkspacePackage] in which [_currentLibrary] is declared.
7976
final WorkspacePackage _workspacePackage;
8077

@@ -112,8 +109,6 @@ class BestPracticesVerifier extends RecursiveAstVisitor<void> {
112109
_deprecatedVerifier =
113110
DeprecatedMemberUseVerifier(workspacePackage, _errorReporter),
114111
_mustCallSuperVerifier = MustCallSuperVerifier(_errorReporter),
115-
_catchErrorVerifier =
116-
CatchErrorVerifier(_errorReporter, typeProvider, typeSystem),
117112
_workspacePackage = workspacePackage {
118113
_deprecatedVerifier.pushInDeprecatedValue(_currentLibrary.hasDeprecated);
119114
_inDoNotStoreMember = _currentLibrary.hasDoNotStore;
@@ -593,7 +588,6 @@ class BestPracticesVerifier extends RecursiveAstVisitor<void> {
593588
void visitMethodInvocation(MethodInvocation node) {
594589
_deprecatedVerifier.methodInvocation(node);
595590
_checkForNullAwareHints(node, node.operator);
596-
_catchErrorVerifier.verifyMethodInvocation(node);
597591
super.visitMethodInvocation(node);
598592
}
599593

pkg/analyzer/lib/src/error/catch_error_verifier.dart

Lines changed: 0 additions & 107 deletions
This file was deleted.

pkg/analyzer/lib/src/error/return_type_verifier.dart

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -155,13 +155,7 @@ class ReturnTypeVerifier {
155155
var S = expression.staticType;
156156

157157
void reportTypeError() {
158-
if (enclosingExecutable.catchErrorOnErrorReturnType != null) {
159-
_errorReporter.reportErrorForNode(
160-
HintCode.RETURN_OF_INVALID_TYPE_FROM_CATCH_ERROR,
161-
expression,
162-
[S, T],
163-
);
164-
} else if (enclosingExecutable.isClosure) {
158+
if (enclosingExecutable.isClosure) {
165159
_errorReporter.reportErrorForNode(
166160
CompileTimeErrorCode.RETURN_OF_INVALID_TYPE_FROM_CLOSURE,
167161
expression,
@@ -262,13 +256,7 @@ class ReturnTypeVerifier {
262256
var S = expression.staticType;
263257

264258
void reportTypeError() {
265-
if (enclosingExecutable.catchErrorOnErrorReturnType != null) {
266-
_errorReporter.reportErrorForNode(
267-
HintCode.RETURN_OF_INVALID_TYPE_FROM_CATCH_ERROR,
268-
expression,
269-
[S, T],
270-
);
271-
} else if (enclosingExecutable.isClosure) {
259+
if (enclosingExecutable.isClosure) {
272260
_errorReporter.reportErrorForNode(
273261
CompileTimeErrorCode.RETURN_OF_INVALID_TYPE_FROM_CLOSURE,
274262
expression,

pkg/analyzer/lib/src/generated/error_verifier.dart

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,6 @@ class EnclosingExecutableContext {
5353
final bool inFactoryConstructor;
5454
final bool inStaticMethod;
5555

56-
/// If this [EnclosingExecutableContext] is the first argument in a method
57-
/// invocation of [Future.catchError], returns the return type expected for
58-
/// `Future<T>.catchError`'s `onError` parameter, which is `FutureOr<T>`,
59-
/// otherwise `null`.
60-
final InterfaceType catchErrorOnErrorReturnType;
61-
6256
/// The return statements that have a value.
6357
final List<ReturnStatement> _returnsWith = [];
6458

@@ -69,10 +63,8 @@ class EnclosingExecutableContext {
6963
/// for the kind of the function body, e.g. not `Future` for `async`.
7064
bool hasLegalReturnType = true;
7165

72-
EnclosingExecutableContext(this.element,
73-
{bool isAsynchronous, this.catchErrorOnErrorReturnType})
74-
: isAsynchronous =
75-
isAsynchronous ?? (element != null && element.isAsynchronous),
66+
EnclosingExecutableContext(this.element)
67+
: isAsynchronous = element != null && element.isAsynchronous,
7668
isConstConstructor = element is ConstructorElement && element.isConst,
7769
isGenerativeConstructor =
7870
element is ConstructorElement && !element.isFactory,
@@ -112,7 +104,7 @@ class EnclosingExecutableContext {
112104

113105
bool get isSynchronous => !isAsynchronous;
114106

115-
DartType get returnType => catchErrorOnErrorReturnType ?? element.returnType;
107+
DartType get returnType => element.returnType;
116108

117109
static bool _inFactoryConstructor(ExecutableElement element) {
118110
if (element is ConstructorElement) {
@@ -754,12 +746,13 @@ class ErrorVerifier extends RecursiveAstVisitor<void> {
754746
@override
755747
void visitFunctionExpression(FunctionExpression node) {
756748
_isInLateLocalVariable.add(false);
757-
if (node.parent is FunctionDeclaration) {
758-
super.visitFunctionExpression(node);
759-
} else {
749+
750+
if (node.parent is! FunctionDeclaration) {
760751
_withEnclosingExecutable(node.declaredElement, () {
761752
super.visitFunctionExpression(node);
762753
});
754+
} else {
755+
super.visitFunctionExpression(node);
763756
}
764757

765758
_isInLateLocalVariable.removeLast();

pkg/analyzer/lib/src/test_utilities/mock_sdk.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ abstract class Future<T> {
4343
throw 0;
4444
}
4545
46-
Future<T> catchError(Function onError, {bool test(Object error)});
47-
4846
Future<R> then<R>(FutureOr<R> onValue(T value));
4947
5048
Future<T> whenComplete(action());

0 commit comments

Comments
 (0)