Skip to content
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

isAssignableFrom does not work for mixins as stated by the docs #629

Open
rubenferreira97 opened this issue Nov 21, 2022 · 0 comments
Open

Comments

@rubenferreira97
Copy link

Trying to check if a mixin element type represents a super type I found the following statement documented on isSuperTypeOf():

Returns true if representing a super type of staticType.

This only takes into account the extends hierarchy. If you wish to check mixins and interfaces, use isAssignableFromType.

So with this information I thought that isAssignableFromType would work as it is.

Implementation:

bool isAssignableFromType(DartType staticType) =>
    isAssignableFrom(staticType.element2!);

bool isAssignableFrom(Element element) =>
    isExactly(element) ||
    (element is ClassElement && element.allSupertypes.any(isExactlyType));

However, given that a mixin type is a MixinElement and not a ClassElement, the previous condition fails since element is ClassElement is false.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant