Skip to content
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

Incorrect implicit downcast error in async functions with FutureOr #30638

Closed
leafpetersen opened this issue Sep 6, 2017 · 3 comments
Closed

Incorrect implicit downcast error in async functions with FutureOr #30638

leafpetersen opened this issue Sep 6, 2017 · 3 comments

Comments

@leafpetersen
Copy link
Member

@leafpetersen leafpetersen commented Sep 6, 2017

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

This comment has been minimized.

Copy link
Contributor

@jmesserly 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

This comment has been minimized.

Copy link
Member Author

@leafpetersen 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

This comment has been minimized.

Copy link
Member Author

@leafpetersen leafpetersen commented Nov 17, 2017

Another example reported in #31398

import 'dart:async';

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

T runCallback<T>(T callback()) {
  return callback();
}
@leafpetersen leafpetersen added this to 2.0 Language in 2.0 language Mar 2, 2018
@leafpetersen leafpetersen moved this from Language implementation to Implementation: analyzer in 2.0 language Mar 3, 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 <brianwilkerson@google.com>
Commit-Queue: Leaf Petersen <leafp@google.com>
2.0 language automation moved this from Implementation: analyzer to Done Jun 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
2.0 language
  
Done
3 participants
You can’t perform that action at this time.