Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(250)

Unified Diff: pkg/dev_compiler/tool/input_sdk/private/ddc_runtime/generators.dart

Issue 2769883002: Fix async iterator runtime type errors (Closed)
Patch Set: Only type the last future Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/dev_compiler/lib/sdk/ddc_sdk.sum ('k') | pkg/dev_compiler/tool/sdk_expected_errors.txt » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/dev_compiler/tool/input_sdk/private/ddc_runtime/generators.dart
diff --git a/pkg/dev_compiler/tool/input_sdk/private/ddc_runtime/generators.dart b/pkg/dev_compiler/tool/input_sdk/private/ddc_runtime/generators.dart
index b90e2ccc3b8ca0884c8df91d168d968c51464487..2d6dbb9156673e6b413e796bbad74b4d1d59574c 100644
--- a/pkg/dev_compiler/tool/input_sdk/private/ddc_runtime/generators.dart
+++ b/pkg/dev_compiler/tool/input_sdk/private/ddc_runtime/generators.dart
@@ -42,18 +42,28 @@ async_(gen, T, @rest args) => JS(
return next(iter.throw(err));
}
function next(ret) {
- if (ret.done) return ret.value;
- // Checks if the awaited value is a Future.
let future = ret.value;
- if (!$instanceOf(future, ${getGenericClass(Future)})) {
+ if (ret.done) {
+ return ret.value;
+ }
+ // Checks if the awaited value is a Future.
+ if (!$instanceOf(future, $Future)) {
future = $Future.value(future);
}
// Chain the Future so `await` receives the Future's value.
return future.then($dynamic)(onValue, {onError: onError});
}
- return ${getGenericClass(Future)}($T).microtask(function() {
+ let FutureT = ${getGenericClass(Future)(T)};
+ return FutureT.microtask(function() {
iter = $gen.apply(null, $args)[Symbol.iterator]();
- return onValue();
+ var result = onValue();
+ if ($strongInstanceOf(result, FutureT) == null) {
+ // Chain the Future<dynamic> to a Future<T> to produce the correct
+ // final type.
+ return result.then($T)((x) => x, {onError: onError});
+ } else {
+ return result;
+ }
});
})()''');
« no previous file with comments | « pkg/dev_compiler/lib/sdk/ddc_sdk.sum ('k') | pkg/dev_compiler/tool/sdk_expected_errors.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698