dart-lang / dart-lang/source_gen
`isAssignableFrom` does not work for mixins as stated by the docs
- Dominant language
- Dart
- Stars
- 494
- Forks
- 115
- Avg merge
- 12h 13m
- Merged PRs (30d)
- 3
Description
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](https://pub.dev/documentation/source_gen/latest/source_gen/TypeChecker/isAssignableFromType.html).**
So with this information I thought that `isAssignableFromType` would work as it is.
Implementation:
```dart
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.
Contributor guide
Research direction
Locate the isAssignableFromType and isAssignableFrom implementations shown in the issue, then trace how mixin elements and their supertypes are represented. Reproduce the documented mixin check and verify that the completed behavior treats the mixin as assignable in the same way described by the isSuperTypeOf documentation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- dart
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100