-
Notifications
You must be signed in to change notification settings - Fork 1.7k
ObjectMirror.invoke ignores typeArguments #33594
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
Comments
Is there anything else I can do about this? This bug means that anything that uses |
FWIW, you really won't want to use https://www.dartlang.org/guides/language/effective-dart/usage#avoid-using-cast (Still doesn't help you with mirrors, of course) |
Did you try |
Thanks for the tip - I was able to resolve it by using |
I'd like to work on this, if no one else is planning on looking into it soon. The solution I'm thinking of:
Does that sound like a reasonable plan? Or are there other aspects of dart:mirrors that should be updated for generics at the same time? |
When generic functions got implemented in the VM, mirrors were supposed to be removed. Therefore, mirrors were only modified to gracefully ignore type arguments on functions without crashing. But no work was done to support them fully. You can try to support generic functions in mirrors, but I think you will run into multiple issues. Mirrors would require a major revision for this to work properly. The author of mirrors, @rmacnak-google, can comment further. |
@crelier Thanks for the background. To clarify, when you say mirrors were supposed to be removed, is that still the plan? Or has that changed? |
Mirrors definitely survived much longer than expected. I am not clear about their future, though. @rmacnak-google may know. |
It would also be hugely helpful for reflectClass(StreamController).newGenericInstance(Symbol(""), [<expectedType>], []);
// should yield instance of StreamController<expectedType> |
@rmacnak-google thank you! |
At this point we have no plans for enhancing |
2.0.0-dev.64.1
I'm updating the package
json_god
to work with Dart 2; it's adart:mirrors
-based reflection solution. The actual functionality works, but for the fact that Dart 2's generics are reified, and so to work with typed collections, I need to somehow attach type information to objects.The solution I am attempting is to reflectively call
List.cast
with the necessary type argument; however, theObjectMirror.delegate
method forwards toObjectMirror.invoke
, which doesn't use the type arguments. Thus, the type arguments are ignored, and items likeList<String>
remainList<dynamic>
.My code:
The current output:
It's evident that that the type arguments are not actually being applied at all. I can't think of any possible workaround for this, unfortunately.
The text was updated successfully, but these errors were encountered: