Skip to content

Incorrect implicit downcast error in async functions with FutureOr #30638

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
leafpetersen opened this issue Sep 6, 2017 · 3 comments
Closed
Labels
language-strong-mode-polish legacy-area-analyzer Use area-devexp instead. P2 A bug or feature request we're likely to work on type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@leafpetersen
Copy link
Member

The following code, when analyzer with --strong --no-implicit-casts produces type errors on both function returns:

import 'dart:async';
typedef FutureOr<String> Stuff();
Stuff stuff = () async => stuff2();
Future<String> stuff3() async => stuff2();
Stuff stuff2;
[error] The return type 'Future<FutureOr<String>>' isn't a 'Future<String>', as defined by the method ''. (/Users/leafp/tmp/ddctest.dart, line 5, col 27)
[error] The return type 'Future<FutureOr<String>>' isn't a 'Future<String>', as defined by the method 'stuff3'. (/Users/leafp/tmp/ddctest.dart, line 7, col 34)

As far as I can tell, there should be no error here: there is no implicit downcast.

Oddly enough, DDC (correctly) does not insert a downcast, so this error must presumably be coming from somewhere other than the checker.

cc @natebosch @jmesserly @stereotype441

@jmesserly
Copy link

jmesserly commented Sep 6, 2017

It's StaticWarningCode.RETURN_OF_INVALID_TYPE from ErrorVerifier, most likely _checkForReturnOfInvalidType. I thought we'd disabled most of ErrorVerifier type checking in strong mode (because CodeChecker in checker.dart supersedes it), but I guess we missed some checks. It probably does not understand FutureOr<T>

@leafpetersen
Copy link
Member Author

leafpetersen commented Oct 5, 2017

Possibly related example from @nex3

import 'dart:async';

bool c = true;

Future<void> test() async {
  Future<int> a = new Future.value(3);
  Future<dynamic> b = new Future<dynamic>.value(3);
  if (c) {
    return a;
  } else {
    return b;
  }
}

Currently this produces an error on the first return but not the second.

@leafpetersen
Copy link
Member Author

Another example reported in #31398

import 'dart:async';

Future<int> fn(int interpolation) async {
  return runCallback(() => 1);
}

T runCallback<T>(T callback()) {
  return callback();
}

@bwilkerson bwilkerson added P2 A bug or feature request we're likely to work on type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) labels Jan 29, 2018
dart-bot pushed a commit that referenced this issue Jun 15, 2018
various kinds of functions.

Closes-bug: #31887
Closes-bug: #30638
Closes-bug: #32233
Closes-bug: #32881
Closes-bug: #31278
Change-Id: I4ebd7e71096d611e189b571ba5de2998dd11c98b
Reviewed-on: https://dart-review.googlesource.com/60300
Reviewed-by: Brian Wilkerson <[email protected]>
Commit-Queue: Leaf Petersen <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
language-strong-mode-polish legacy-area-analyzer Use area-devexp instead. P2 A bug or feature request we're likely to work on type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

3 participants