-
Notifications
You must be signed in to change notification settings - Fork 65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement TypeMirror#typeArguments in transformer #79
Comments
On unsupported features: At the bottom of the page https://github.com/dart-lang/reflectable/tree/master/reflectable there is a section about 'Known Limitations'. It does mention that type arguments (that is, actual arguments to a generic entity) are not supported except in trivial cases; the problem is that we don't have a primitive which will allow us to get access to that data without using anything from 'dart:mirrors' (in short, given a On the type variables (that is, formal type parameters declared on a generic entity): They should be supported (with a |
You wouldn't have the opportunity to use a workaround, would you? class TypeArgumentReifier1<X> {
Type get typeArguments => <Type>[X];
}
class TypeArgumentReifier2<X1, X2> {
Type get typeArguments => <Type>[X1, X2];
}
...
class MyClass<E, W> implements TypeArgumentsReifier2<E, W> {
...
} You would then be able to use |
Sorry, I meant The workaround looks legit, but in my case access to the type arguments is not important enough to justify such a workaround polluting the whole codebase. It would just be the most elegant and generic (pun intended) solution but I can find a different route for now. I did notice the mention in the list of known limitations but it wasn't (isn't) really clear to me what constitutes a 'trivial' case. Further, the known limitations talk of 'parts of the library' that have not been implemented so I expected it to fail before running the transformed code. My main here objection here is that it's not clear that this will fail until you try to run the transformed code but not e.g. in unittests. Having a workflow were you need to constantly test the transformed code to avoid such pitfalls is not optimal. |
The trivial cases are the ones that we implemented from the beginning (e.g., You may be able to use yet another workaround in the case of type annotations: We have implemented support for obtaining The cases that we can support are cases where a given type annotation receives only compile time constant types (that is, no type variables occur anywhere in the type annotation), and you only get the assert(myMethodMirror.hasReflectedReturnType);
assert(myMethodMirror.hasDynamicReflectedReturnType);
assert(myMethodMirror.dynamicReflectedReturnType == C);
if (myMethodMirror.reflectedReturnType == const TypeValue<C<D>>().type) {
// May rely on `myMethodMirror.returnType.typeArguments == <Type>[D]`.
...
} in order to detect that you have a case where the type argument is Obviously this is a very weak workaround, because you have to check that the base type is I'll mark this issue as 'wontfix' and close it, in order to make this situation visible. |
Porting over some code that needs access to generic type variables because
MirrorsUsed
is a strange beast when doing that, I find out at the very end of my endeavour (#77 and #78) thattypeArguments
is not implemented in the reflectable transformer. Oh the irony...Anyway, this would be super neat to have!
On a more general note, consider clearly documenting which features are not supported in the transformer and/or having an option on the capability specification (my Reflectable subclass) to throw when running in the Dart VM if you try to use an unimplemented feature.
The text was updated successfully, but these errors were encountered: