dart-lang / dart-lang/language
Trying to get `this` type is incredibly unweildy. Ref: `Self` from Rust
- Dominant language
- TeX
- Stars
- 2.9k
- Forks
- 239
- Avg merge
- 2d 18h
- Merged PRs (30d)
- 14
Description
Sometimes, I want to get "this" type. This is often side-stepped by the use of `covarient` in;
for example; `didUpdateWidget(covarient ThisWidget oldWidget)`
Additionally, I find myself occasionally wanting to do something like:
```dart
abstract class Foo> {}
class Bar extends Foo {}
```
as a way to extract the "this" type, but it can get really messy really quickly.
One possible usecase is to have a copyWith interface as such:
```dart
interface class CopyWith {
Self copyWith();
}
class Foo {
Self copyWith() => Foo();
}
class Bar extends Foo { // Self changed, so Foo.copyWith is treated as abstract
Self copyWith() => Bar();
}
```
To add on, this could have strong synergy with static interfaces, as we could then _operate_ on `Self` such as doing:
```dart
static interface CreateDefault {
factory create();
}
base mixin CopyWith on CreateDefault {
Self copyWith() => Self.create();
}
```
Granted, copyWith is likely not the strongest example for this, but its 2:30 am and I don't have an example on hand, on account of being forced to give up :/
I want to see what ideas others have with regards to the usefulness of a `Self`-like "type"
Contributor guide
Research direction
Start by reviewing the issue's Dart examples and the Rust `Self` reference mentioned in the title. The issue does not name files, tests, or an entry point, and completion would require an agreed language design with concrete acceptance criteria.
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