google / google/reflectable.dart
LibraryMirror.declarations should include type aliases
- Dominant language
- Dart
- Stars
- 386
- Forks
- 67
- PR merge metrics
- No merged PRs in 30d
Description
Cf. [library_declarations_test.dart](https://github.com/dart-lang/test_reflectable/blob/master/test/library_declarations_test.dart).
Obtain a `LibraryMirror` for a library that contains some type alias declarations and inspect its `declarations`: There are no entries for the type aliases.
In a lot of ways, reflectable does not support reflection on function objects (because the underlying primitives that we would have to have in order to be able to support them do not exist). But it would certainly be possible to create some `TypedefMirror`s and allow them to return the `reflectedType`, such that we could get the name and compare for equality. However, even equality is currently blocked:
Cf. https://github.com/dart-lang/sdk/issues/32782: The specified equality for function types and type aliases denoting function types (which should use operator `==`, which should test for being "the same underlying type, i.e., looking up the denotation of a given type alias") has not yet, as of Feb 2019, been implemented by the common front end (nor by the vm, dart2js, etc; though I believe that dartdevc has it).
This means that we cannot compare some function types, because they would be expected to be obtained via type aliases in some cases, and to be declared "inline" (using syntax like `int Function()`) in other cases. So we can't provide a reasonable level of support for the type aliases before the basic equality test works. Hence 'blocked'.
Nevertheless, we could already implement the ability to look up the type aliases in the `declarations`, and we could let the implementation return the current reified type, even though it fails to have a correct operator `==`, and then "it would work" as long as the code that we're reflecting on makes the choice to declare any given function type (that we will reflect upon) using a type alias, and then using that type alias _everywhere_ that function type is used. This is slightly better than nothing (maybe ;-), and, notably: It will "just start working" when the equality issue has been fixed.
Contributor guide
Assessment
This issue has not been assessed yet.