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

Unified Diff: pkg/analyzer/lib/src/dart/element/type.dart

Issue 2093523002: fix #25573, add option to disable implicit dynamic (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Merge remote-tracking branch 'origin/master' into no_implicit_dynamic Created 4 years, 6 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/analyzer/lib/src/context/context.dart ('k') | pkg/analyzer/lib/src/generated/engine.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/lib/src/dart/element/type.dart
diff --git a/pkg/analyzer/lib/src/dart/element/type.dart b/pkg/analyzer/lib/src/dart/element/type.dart
index 8d6aec0a5357e32d1dfde221bcc0d193a0b417d7..22a247ab3bfa0a509ded516f0a674157829c7ce6 100644
--- a/pkg/analyzer/lib/src/dart/element/type.dart
+++ b/pkg/analyzer/lib/src/dart/element/type.dart
@@ -927,6 +927,39 @@ class FunctionTypeImpl extends TypeImpl implements FunctionType {
}
/**
+ * Given a generic function type [g] and an instantiated function type [f],
+ * find a list of type arguments TArgs such that `g<TArgs> == f`,
+ * and return TArgs.
+ *
+ * This function must be called with type [f] that was instantiated from [g].
+ */
+ static Iterable<DartType> recoverTypeArguments(
+ FunctionType g, FunctionType f) {
+ // TODO(jmesserly): perhaps a better design here would be: instead of
+ // recording staticInvokeType on InvocationExpression, we could record the
+ // instantiated type arguments, that way we wouldn't need to recover them.
+ //
+ // For now though, this is a pretty quick operation.
+ assert(identical(g.element, f.element));
+ assert(g.typeFormals.isNotEmpty && f.typeFormals.isEmpty);
+ assert(g.typeFormals.length + g.typeArguments.length ==
+ f.typeArguments.length);
+
+ // Instantiation in Analyzer works like this:
+ // Given:
+ // {U/T} <S> T -> S
+ // Where {U/T} represents the typeArguments (U) and typeParameters (T) list,
+ // and <S> represents the typeFormals.
+ //
+ // Now instantiate([V]), and the result should be:
+ // {U/T, V/S} T -> S.
+ //
+ // Therefore, we can recover the typeArguments from our instantiated
+ // function.
+ return f.typeArguments.skip(g.typeArguments.length);
+ }
+
+ /**
* Compares two function types [t] and [s] to see if their corresponding
* parameter types match [parameterRelation] and their return types match
* [returnRelation].
« no previous file with comments | « pkg/analyzer/lib/src/context/context.dart ('k') | pkg/analyzer/lib/src/generated/engine.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698