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

Unified Diff: pkg/front_end/lib/src/fasta/type_inference/type_schema_environment.dart

Issue 2895063003: Flatten futures when inferring the type of an async function expression. (Closed)
Patch Set: Don't recurse on future-derived types Created 3 years, 7 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
Index: pkg/front_end/lib/src/fasta/type_inference/type_schema_environment.dart
diff --git a/pkg/front_end/lib/src/fasta/type_inference/type_schema_environment.dart b/pkg/front_end/lib/src/fasta/type_inference/type_schema_environment.dart
index 202293e7b048997012a4c603921dacce00e2008d..e0d802d84a923d4f82a165e824e3c07bcda985d1 100644
--- a/pkg/front_end/lib/src/fasta/type_inference/type_schema_environment.dart
+++ b/pkg/front_end/lib/src/fasta/type_inference/type_schema_environment.dart
@@ -49,6 +49,28 @@ class TypeSchemaEnvironment extends TypeEnvironment {
constraint.upper = getGreatestLowerBound(constraint.upper, upper);
}
+ /// Implements the function "flatten" defined in the spec, where T is [type]:
+ ///
+ /// If T = Future<S> then flatten(T) = flatten(S).
+ ///
+ /// Otherwise if T <: Future then let S be a type such that T << Future<S>
+ /// and for all R, if T << Future<R> then S << R. Then flatten(T) = S.
+ ///
+ /// In any other circumstance, flatten(T) = T.
+ DartType flattenFutures(DartType type) {
+ if (type is InterfaceType) {
+ if (identical(type.classNode, coreTypes.futureClass)) {
+ return flattenFutures(type.typeArguments[0]);
+ }
+ InterfaceType futureBase =
+ hierarchy.getTypeAsInstanceOf(type, coreTypes.futureClass);
+ if (futureBase != null) {
+ return futureBase.typeArguments[0];
+ }
+ }
+ return type;
+ }
+
/// Computes the greatest lower bound of [type1] and [type2].
DartType getGreatestLowerBound(DartType type1, DartType type2) {
// The greatest lower bound relation is reflexive. Note that we don't test
« no previous file with comments | « pkg/front_end/lib/src/fasta/type_inference/type_inferrer.dart ('k') | pkg/front_end/test/fasta/strong.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698