-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Kernel inferences incorrect type for await expression. #31541
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
Comments
Change Fasta type inference and Kernel type checking to use the new definition for Future flattening, which is really unwrapping (peeling off one layer of Future or FutureOr). Use this for inferring types of `await` expressions and return types from `async` functions. Ensure that we are using the same notion of flattening for inference and checking. (Maybe it was a red flag that we weren't.) This fixes await_test so that it produces a runtime error rather than a compile time error - see #31541. A similar change will need to be made to the analyzer - see #31887. Change-Id: I7d936e9788969a48fdc216628eaa793389fb5e30 Reviewed-on: https://dart-review.googlesource.com/34504 Commit-Queue: Kevin Millikin <[email protected]> Reviewed-by: Kevin Millikin <[email protected]>
45b02f8 changed the compile-time error into a runtime error, and ff008ca fixed the runtime error. There is still a crash when testing DDC with kernel, however, so I'm just going to go ahead and reclassify this as a DDC bug. To repro, remove the line
Backtrace looks like this:
|
I can fix the crash. Question though for @lrhn and @leafpetersen, given this program: import 'dart:async';
FutureOr<T> future<T>(T value) async => value;
main() {
var f = future<int>(0);
print(f.runtimeType); // _Future
f as Future<int>; // fails casting _Future<dynamic> to Future<int>
} Is that behavior intended? That is what DDC (w/ Analyzer strong mode) is currently doing. When determining the type Seems like a soundness problem, because the value in Aside @stereotype441 -- it would be kinda nice if front_end/kernel made |
@jmesserly As of 45b02f8 you can get access to the |
tl;dr: Use For the above program, the returned value should be a I don't know if strong mode specified this explicitly, but as I see it, If the declared return type of an So, the declared return type -> returned future type mapping is:
No other types are valid return types for The first three cases have no hint to the actual type of the future, so it just picks a type that works for all values. Which actually means that we can just use |
thanks @lrhn, that sounds good to me! I will use that in DDC/K. |
Error message:
where
func
has typeFutureOr<T> Function<T>(T)
.This means that the static type of
await(func(0))
use to infer the type ofi
isFutureOr<int>
, notint
as it should be.(See language_2/await_test when it lands).
The text was updated successfully, but these errors were encountered: