dart-lang / dart-lang/language
[extension-types, views] Allow variable show
- Dominant language
- TeX
- Stars
- 2.9k
- Forks
- 239
- Avg merge
- 2d 18h
- Merged PRs (30d)
- 14
Description
Cf. the [extension types](https://github.com/dart-lang/language/blob/master/working/1426-extension-types/feature-specification.md) proposal and the semantically very similar [views](https://github.com/dart-lang/language/pull/1617) proposal.
The `show` clause in an extension type or view `Foo` enables invocations of members of the underlying on-type. For instance:
```dart
view Foo on int show num { // or `extension type Foo ...`: same thing.
void bar() {}
}
void main() {
Foo foo = 30;
foo.floor(); // OK, member of on-type which is included by `show`.
foo.isEven; // Error, not included.
foo.bar(); // OK, declared in the view.
}
```
We may wish to compute the members included by the `show` clause based on the on-type, and this might actually be tractable in spite of the fact that it seems to be similar to "`class C implements X ...`":
```dart
view Foo on X show X hide substring {
String substring() => "Substring!";
}
void main() {
Foo i = 10;
i.isEven; // OK, member of the on-type, and shown.
Foo s = 'String!';
print(s.substring()); // OK, prints 'Substring!'.
}
```
This feature makes it possible to bundle a set of view members with any type (when `X` has no bound) or with any of the set of subtypes of a given type `T` (with `Foo ...`), and it allows us to preserve the full interface of the on-type.
It is indeed a quirky feature, but it might be quite useful.
@lrhn, @leafpetersen, @natebosch, @stereotype441, @jakemac53, @munificent, WDYT?
Contributor guide
Research direction
Start by reading the linked extension-types feature specification and the views proposal pull request 1617, then compare them with the examples in this issue. The work is complete when the language design for variable show is decided and its specification and validation requirements are documented.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- dart
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100