Skip to content

Dartanalyzer should report an error when catchError returns a different type #35545

Closed
@tomyeh

Description

@tomyeh

Dartanalyzer doesn't detect any error/warning for the following code. However, there will be a run-time error: type 'String' is not a subtype of type 'FutureOr<List>'

It is hard to pick up this kind of errors by eyes.

IMO, it is better to allow Future.catchError() to return another type like Future.then<R>() does. But, it is OK as long as dartanlyser can pick up the errors for us.

import "dart:async";

void main() {
  foo()
  .catchError((ex) {
  	return "error";
  });
}
Future<List> foo() async {
  throw "error";
}

Dart SDK: 2.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2A bug or feature request we're likely to work onlegacy-area-analyzerUse area-devexp instead.type-enhancementA request for a change that isn't a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions