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

Unified Diff: pkg/analyzer/lib/src/generated/resolver.dart

Issue 2260313002: Extend Future.then inference to subclasses (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 4 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 | « no previous file | pkg/analyzer/lib/src/generated/static_type_analyzer.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/lib/src/generated/resolver.dart
diff --git a/pkg/analyzer/lib/src/generated/resolver.dart b/pkg/analyzer/lib/src/generated/resolver.dart
index 98e7ca78cbaede97ce66dff3477fe77518309c88..07e6c70629dafe689bcf297a12f6d25cf5ee40b5 100644
--- a/pkg/analyzer/lib/src/generated/resolver.dart
+++ b/pkg/analyzer/lib/src/generated/resolver.dart
@@ -5758,15 +5758,25 @@ class ResolverVisitor extends ScopedVisitor {
}
/**
- * Returns true if this method is `Future.then`.
+ * Returns true if this method is `Future.then` or an override thereof.
*
* If so we will apply special typing rules in strong mode, to handle the
* implicit union of `S | Future<S>`
*/
bool isFutureThen(Element element) {
- return element is MethodElement &&
- element.name == 'then' &&
- element.enclosingElement.type.isDartAsyncFuture;
+ // If we are a method named then
+ if (element is MethodElement && element.name == 'then') {
+ // On Future, then we're good.
+ if (element.enclosingElement.type.isDartAsyncFuture) {
Jennifer Messerly 2016/08/19 19:36:46 could be worth a "DartType type = element.enclosin
Leaf 2016/08/19 19:47:00 Done.
+ return true;
+ }
+ // On a subtype of Future we're good.
+ if (typeSystem.isSubtypeOf(
+ element.enclosingElement.type, typeProvider.futureDynamicType)) {
+ return true;
+ }
+ }
+ return false;
}
/**
@@ -6725,6 +6735,12 @@ class ResolverVisitor extends ScopedVisitor {
@override
Object visitInstanceCreationExpression(InstanceCreationExpression node) {
TypeName classTypeName = node.constructorName.type;
+ // TODO(leafp): Currently, we may re-infer types here, since we
+ // sometimes resolve multiple times. We should really check that we
+ // have not already inferred something. However, the obvious ways to
+ // check this don't work, since we class may have been instantiated
+ // to bounds in an earlier phase, and we *do* want to do inference
+ // in that case.
if (classTypeName.typeArguments == null) {
// Given a union of context types ` T0 | T1 | ... | Tn`, find the first
// valid instantiation `new C<Ti>`, if it exists.
« no previous file with comments | « no previous file | pkg/analyzer/lib/src/generated/static_type_analyzer.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698