-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
We should consider adding a method isSubtypeOf in class Type to check if a type instance is a sub type of another instance #23764
Comments
We could provide this functionality in the class Type of the SDK. Instead of abstract class Type {} we could have abstract class Type { Other methods to inspect function types may be useful too: static Type VoidType(); To be complete, we would also need access to optional arguments, since they are considered in function type tests: All the above is already implemented in C++ in the VM and would just have to be exposed on the Dart side. This is an API change, obviously. |
I'm sympathetic to adding more functionality on Personally I'd want at least: class Type<T> {
bool isInstance(object) => object is T;
bool isSubtypeOf(Type other) => ...;
} I don't think the function inspection is a good idea - that's too close to reflection, and then you can just use mirrors. In general, passing around In short: If you use Adding anything to |
I don't think we should speculatively add functionality without first having a use case for it. I think a good first step would be to find all the 'dart:mirrors' usage in the Sky framework and get that functionality in through other means. Regarding passing Type objects around, we can only suggest as a recommended patterns but it is always up to the user as to how they use it. |
@larsbak had a suggestion for the Sky code in this particular case, in order to eliminate the need for mirrors here. |
I think this issue is stale - and it is not a VM issue but a language/core library one |
The widget code in Sky uses mirrors in the following scenario to query if the type of an object is a subtype of another target type.
Widget findAncestor(Type targetType) {
var ancestor = _parent;
while (ancestor != null && !reflectClass(ancestor.runtimeType).isSubtypeOf(reflectClass(targetType)))
ancestor = ancestor._parent;
return ancestor;
}
We would like to eliminate all uses of mirrors in Sky code as we will have issues with it when precompiling and tree shaking for the ios platform
@sgmitrovic @crelier
The text was updated successfully, but these errors were encountered: