dart-lang / dart-lang/language

Support Abstract Type Members

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

Description

Scala, for one, offers the concept of [abstract type members](https://docs.scala-lang.org/tour/abstract-type-members.html), and it would be great to see this supported in Dart.
Abstract type members provide both ergonomic convenience (by not having to repeatedly specify type parameters) as well as a way to specify valid mappings or combinations of types and preventing invalid combinations. For example, when modeling generic entities with arbitrary id types, currently we need to do something like this:
```dart
abstract class Entity { ... }
abstract class EntityRepo> {
E getById(Id id) ...
}
```
With the capability of defining a type member though, this could be a bit simpler, as with the following pseudo-syntax:
```dart
abstract class Entity {
type Id
}
abstract class EntityRepo {
E getById(E.Id id) ...
}
```
Not only is this less verbose, it can prevent creating invalid combinations of, in this case, entity and id types.

Contributor guide

Open the contributing guide

Research direction

Start with the issue's abstract type member examples and the linked Scala documentation. Investigate how Dart could express type members, including their syntax, generic relationships, and prevention of invalid type combinations. Done would require an accepted language design and corresponding specification changes, but no implementation files or tests are identified here.

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.