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

Unified Diff: pkg/compiler/lib/src/dart_types.dart

Issue 1035443002: Implement new flatten specification. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Updated cf. comment. Created 5 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/compiler/lib/src/core_types.dart ('k') | pkg/compiler/lib/src/typechecker.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/compiler/lib/src/dart_types.dart
diff --git a/pkg/compiler/lib/src/dart_types.dart b/pkg/compiler/lib/src/dart_types.dart
index fd27d881abab676d98fabe45ad37567e05214ade..b9c90fe40bbab1bdb29fad25c9d181cac4972f4b 100644
--- a/pkg/compiler/lib/src/dart_types.dart
+++ b/pkg/compiler/lib/src/dart_types.dart
@@ -1222,6 +1222,37 @@ class Types implements DartTypes {
return new Types(compiler);
}
+ /// Flatten [type] by recursively removing enclosing `Future` annotations.
+ ///
+ /// Defined in the language specification as:
+ ///
+ /// 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.
+ ///
+ /// For instance:
+ /// flatten(T) = T
+ /// flatten(Future<T>) = T
+ /// flatten(Future<Future<T>>) = T
+ ///
+ /// This method is used in the static typing of await and type checking of
+ /// return.
+ DartType flatten(DartType type) {
Paul Berry 2015/03/25 15:22:25 There are two corner cases I ran into in the analy
+ if (type is InterfaceType) {
+ if (type.element == coreTypes.futureClass) {
+ // T = Future<S>
+ return flatten(type.typeArguments.first);
+ }
+ InterfaceType futureType = type.asInstanceOf(coreTypes.futureClass);
+ if (futureType != null) {
+ // T << Future<S>
+ return futureType.typeArguments.single;
+ }
+ }
+ return type;
+ }
+
/** Returns true if [t] is more specific than [s]. */
bool isMoreSpecific(DartType t, DartType s) {
return moreSpecificVisitor.isMoreSpecific(t, s);
« no previous file with comments | « pkg/compiler/lib/src/core_types.dart ('k') | pkg/compiler/lib/src/typechecker.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698