Last active
October 27, 2017 22:39
-
-
Save leonsenft/bd617ab891fca3f3f2815b0c85e7bfa1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DartType resolveGenerics(DartType type) { | |
if (type is TypeParameterType) { | |
return type.resolveToBound(dynamicType); // T --> dynamic. | |
} else if (type is ParameterizedType) { | |
// [T, ...] --> [dynamic, ...] | |
final resolvedTypeArguments = | |
type.typeArguments.map(resolveTypeParameters).toList(); | |
// Fails on nested unbounded type arguments. | |
// * List<T>.instantiate([dynamic]) --> List<dynamic> | |
// * List<Foo<T>>.instantiate([Foo<dynamic>]) --> List<Foo<T>> | |
return type.instantiate(typeArguments); | |
} | |
return type; // Nothing to resolve. | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment