dart-lang / dart-lang/language

Confusion with extension types and `implements`

Open
#3,463 6 comments 0 reactions 0 assignees View on GitHub
request
Dominant language
TeX
Stars
2.9k
Forks
239
Avg merge
2d 18h
Merged PRs (30d)
14

Description

First, I apologize in advance in case I misunderstand the meaning of `implements` in extension types. However, I find that it is confusing, considering how `implements` work in classes. This is mainly due to the fact that in classes, `implements` means that a class must follow a specified interface or "shape" of an object. However, in extension types, `implements` (I think) means "to expose" the interface of the underlying object. For example:

```dart
extension type const ImmutableList(T _) implements Iterable {
T operator[](int index) => _[index];
int get length => _.length; /// This is not necessary because of the implements clause.
}
```

So what's the idea with implements? Is it supposed to expose the underlying API of the object? Is it supposed to ensure that the object obeys its superinterface by exposing needed elements?

Contributor guide

Open the contributing guide

Research direction

Start with the extension type example in the issue and compare its use of `implements` with the class meaning described there. Determine and document whether the clause exposes the underlying API, enforces a superinterface, or serves another purpose; done means the semantics and distinction are clearly resolved.

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
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.